diff --git a/generators/base/index.js b/generators/base/index.js index 17e29ce..78e749d 100644 --- a/generators/base/index.js +++ b/generators/base/index.js @@ -26,8 +26,15 @@ module.exports = class extends Generator { message: "Do you want i18n support?", default: true, }, + { + type: "confirm", + name: "fastlane", + message: "Do you want add Fastlane to this project?", + default: true, + }, ]).then((answers) => { this.i18nSupport = answers.i18nSupport; + this.fastlane = answers.fastlane; this.usingReactQuery = answers.httpLayer === "react-query"; this.usingReduxSaga = answers.httpLayer === "redux-saga"; }); @@ -246,6 +253,19 @@ module.exports = class extends Generator { this.destinationPath("__mocks__") ); + // Add fastlane folder + if (this.fastlane) { + this.fs.copy( + this.templatePath("fastlane"), + this.destinationPath("fastlane") + ); + + this.fs.copy( + this.templatePath("fastlane/.env.example"), + this.destinationPath("fastlane/.env.example") + ); + } + this.fs.copyTpl( this.templatePath("README.md"), this.destinationPath("README.md"), @@ -270,6 +290,12 @@ module.exports = class extends Generator { "prettier --config .prettierrc.js --write 'App/**/*.{ts,tsx,js}'", lint: "eslint --fix './App/**/*.{ts,tsx,js}'", bump: "./bin/bump-ios.sh", + "version:bump": + "npm version patch && cd fastlane && bundle exec fastlane version_bump", + "github:release": + "cd fastlane && bundle exec fastlane github_release", + "firebase:release": + "cd fastlane && bundle exec fastlane firebase_release", test: "jest --verbose", coverage: "jest --coverage", "test:watch": "npm test -- --watch", @@ -383,6 +409,13 @@ module.exports = class extends Generator { } ); + if (this.fastlane) { + this.log("Checking if Fastlane is installed on your machine..."); + this.spawnCommandSync("sh", [`${this.templatePath("bin")}/fastlane.sh`], { + cwd: this.destinationPath(), + }); + } + this.log("Setup complete!"); this.log("Please refer to the post-install notes"); this.log( diff --git a/generators/base/templates/bin/fastlane.sh b/generators/base/templates/bin/fastlane.sh new file mode 100644 index 0000000..f17f6e0 --- /dev/null +++ b/generators/base/templates/bin/fastlane.sh @@ -0,0 +1,16 @@ +# check if fastlane is installed +isInstalled() { +if hash fastlane 2>/dev/null; then + echo "Fastlane already installed!" +else + echo "How do you want to install Fastlane?" +select yn in "RubyGems" "Homebrew"; do + case $yn in + RubyGems ) echo "Installing Fastlane via RubyGems (you maybe asked for a password)... "; sudo gem install fastlane -NV ; break;; + Homebrew ) echo "Installing Fastlane via Homebrew..."; brew install fastlane ; break;; + esac + done +fi +}; + +isInstalled; \ No newline at end of file diff --git a/generators/base/templates/fastlane/.env.example b/generators/base/templates/fastlane/.env.example new file mode 100644 index 0000000..8a5cd9f --- /dev/null +++ b/generators/base/templates/fastlane/.env.example @@ -0,0 +1,12 @@ +# Version Bump +GITHUB_TOKEN= +REPO_NAME= + +# Github Release +CODESIGNING_IDENTITY= + +# Firebase Release +IOS_APP_ID= +ANDROID_APP_ID= +SLACK_URL= +TESTERS= \ No newline at end of file diff --git a/generators/base/templates/fastlane/Appfile b/generators/base/templates/fastlane/Appfile new file mode 100644 index 0000000..06b6203 --- /dev/null +++ b/generators/base/templates/fastlane/Appfile @@ -0,0 +1,11 @@ +#IOS config +# app_identifier "com.app.identifier" # The bundle identifier of your app +# apple_id "apple@id.co.uk"# Your Apple email address +# team_name "TEAM NAME"# Team name for your itunes connect account +# team_id "TEAMID" # Team ID for your itunes connect account - found at https://developer.apple.com/account/#/membership/S7R8RC82YA +# itc_team_name "TEAM NAME"# Team name for your itunes connect account +# itc_team_id "TEAM ID"# Team ID for your itunes connect account + +# Android config +# json_key_file "./path-to-json-key.json"# JSON key generated for the android play store account instructions for creating at: https://docs.fastlane.tools/getting-started/android/setup/#collect-your-google-credentials +# package_name "com.android.package.id" # Application id for the android app found in build.gradle fil# \ No newline at end of file diff --git a/generators/base/templates/fastlane/Fastfile b/generators/base/templates/fastlane/Fastfile new file mode 100644 index 0000000..16e7b1c --- /dev/null +++ b/generators/base/templates/fastlane/Fastfile @@ -0,0 +1,153 @@ +# Customise this file, documentation can be found here: +# https://github.com/fastlane/fastlane/tree/master/fastlane/docs +# All available actions: https://docs.fastlane.tools/actions +# can also be listed using the `fastlane actions` command + +# Change the syntax highlighting to Ruby +# All lines starting with a # are ignored when running `fastlane` + +# If you want to automatically update fastlane if a new version is available: +# update_fastlane + +# This is the minimum version number required. +# Update this, if you use features of a newer version +fastlane_version "2.28.3" + +# Check that there is nothing to commit and pull the latest repo. +before_all do + ensure_git_branch + ensure_git_status_clean + git_pull +end + +package = load_json(json_path: "./package.json") +appname = package["name"] +version = package["version"] + +#################### +### TEST LANE ### +#################### +lane :test_setup do + puts('FASTLANE CORRECTLY SETUP 🔥') +end + +#################### +### VERSION BUMP ### +#################### +lane :version_bump do + increment_version_number(version_number: package["version"], xcodeproj: "ios/#{appname}.xcodeproj") + commit_version_bump(message: "Release v#{version} :rocket:", xcodeproj: "ios/#{appname}.xcodeproj") + push_to_git_remote( + remote: "origin", + tags: false, + no_verify: true + ) +end + +###################### +### GITHUB RELEASE ### +###################### +lane :github_release do + ensure_env_vars( + env_vars: ['CODESIGNING_IDENTITY', 'GITHUB_TOKEN'] + ) + + ## BUILD IOS + build_ios_app( + workspace: "ios/#{appname}.xcworkspace", + output_directory: "builds/v#{version}", + export_options: { method: "app-store" }, + codesigning_identity: ENV['CODESIGNING_IDENTITY'] + ) + + ## BUILD ANDROID + gradle(task: 'clean', project_dir: 'android/') + gradle(task: 'bundle', build_type: 'Release', project_dir: 'android/') + + ## ADD TO GITHUB + set_github_release( + repository_name: "simpleweb/#{ENV['REPO_NAME']}", + api_token: ENV['GITHUB_TOKEN'], + name: "#{version}", + tag_name: "v#{version}", + description: "Add release notes here...", + commitish: "master", + is_prerelease: true, + upload_assets: ["builds/v#{version}/#{appname}.ipa", "android/app/build/outputs/bundle/release/app.aab"] + ) +end + +############################# +### FIREBASE BETA RELEASE ### +############################# +lane :firebase_release do |options| + + + ## SEND SLACK NOTIFICATION + if ENV['SLACK_URL'] + slack( + slack_url: ENV['SLACK_URL'], + message: "A beta release of #{appname}(v#{version}) is being uploaded to Firebase..." + ) + end + + + ## BUILD & UPLOAD IPA + unless options[:android_only] + unless options[:skip_build] + ensure_env_vars( + env_vars: ['CODESIGNING_IDENTITY'] + ) + build_ios_app( + workspace: "ios/#{appname}.xcworkspace", + output_directory: "builds/v#{version}", + export_options: { method: "app-store" }, + codesigning_identity: ENV['CODESIGNING_IDENTITY'] + ) + end + + ensure_env_vars( + env_vars: ['IOS_APP_ID', 'TESTERS'] + ) + puts "-------------------------------------------------------" + puts "--- Uploading #{appname}(v#{version}) IPA to Firebase ---" + puts "-------------------------------------------------------" + firebase_app_distribution( + app: ENV['IOS_APP_ID'], + ipa_path: "builds/v#{version}/#{appname}.ipa", + testers: ENV['TESTERS'], + release_notes: "Add release notes here...", + firebase_cli_path: "/usr/local/bin/firebase" + ) + end + + ## BUILD & UPLOAD APK + unless options[:ios_only] + unless options[:skip_build] + gradle(task: 'clean', project_dir: 'android/') + gradle(task: 'bundle', build_type: 'Release', project_dir: 'android/') + end + + ensure_env_vars( + env_vars: ['ANDROID_APP_ID', 'TESTERS'] + ) + puts "-------------------------------------------------------" + puts "--- Uploading #{appname}(v#{version}) APK to Firebase ---" + puts "-------------------------------------------------------" + firebase_app_distribution( + app: ENV['ANDROID_APP_ID'], + apk_path: "android/app/build/outputs/apk/release/app-release.apk", + testers: ENV['TESTERS'], + release_notes: "Add release notes here...", + firebase_cli_path: "/usr/local/bin/firebase" + ) + end + + ## SEND SLACK NOTIFICATION + if ENV['SLACK_URL'] + slack( + slack_url: ENV['SLACK_URL'], + message: "A beta release of #{appname}(v#{version}) is now available for testing on Firebase" + ) + end +end \ No newline at end of file diff --git a/generators/base/templates/fastlane/Pluginfile b/generators/base/templates/fastlane/Pluginfile new file mode 100644 index 0000000..9a39b1b --- /dev/null +++ b/generators/base/templates/fastlane/Pluginfile @@ -0,0 +1,6 @@ +# Autogenerated by fastlane +# +# Ensure this file is checked in to source control! + +gem 'fastlane-plugin-firebase_app_distribution' +gem 'fastlane-plugin-load_json'