From b06e9ae3811d7721f215640aa03ab22895ef1e54 Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 28 Oct 2020 16:09:13 -0700 Subject: [PATCH 01/10] Write android + iOS regardless if "expo" app. This lib thinks we're an "expo" app just because we have the package + an app.json, which is outdated now. This let's us write the app.json, android, and iOS all together. It also will update the versions of our postExport hooks, if they exist. --- index.js | 176 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 74 deletions(-) diff --git a/index.js b/index.js index 345f3d4..986747c 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const Xcode = require("pbxproj-dom/xcode").Xcode; */ const env = { - target: process.env.RNV && list(process.env.RNV) + target: process.env.RNV && list(process.env.RNV), }; /** @@ -34,7 +34,7 @@ const env = { function getDefaults() { return { android: "android/app/build.gradle", - ios: "ios" + ios: "ios", }; } @@ -47,10 +47,10 @@ function getDefaults() { function getPlistFilenames(xcode) { return unique( flattenDeep( - xcode.document.projects.map(project => { - return project.targets.filter(Boolean).map(target => { + xcode.document.projects.map((project) => { + return project.targets.filter(Boolean).map((target) => { return target.buildConfigurationsList.buildConfigurations.map( - config => { + (config) => { return config.ast.value.get("buildSettings").get("INFOPLIST_FILE") .text; } @@ -141,7 +141,7 @@ function version(program, projectPath) { const programOpts = Object.assign({}, prog, { android: path.join(projPath, prog.android), - ios: path.join(projPath, prog.ios) + ios: path.join(projPath, prog.ios), }); const targets = [].concat(programOpts.target, env.target).filter(Boolean); @@ -154,24 +154,24 @@ function version(program, projectPath) { if (err.message === "Cannot find module 'react-native'") { log({ style: "red", - text: `Is this the right folder? ${err.message} in ${projPath}` + text: `Is this the right folder? ${err.message} in ${projPath}`, }); } else { log({ style: "red", - text: err.message + text: err.message, }); log({ style: "red", text: - "Is this the right folder? Looks like there isn't a package.json here" + "Is this the right folder? Looks like there isn't a package.json here", }); } log({ style: "yellow", - text: "Pass the project path as an argument, see --help for usage" + text: "Pass the project path as an argument, see --help for usage", }); if (program.outputHelp) { @@ -193,8 +193,8 @@ function version(program, projectPath) { if (isExpoApp && !programOpts.incrementBuild) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { - version: appPkg.version - }) + version: appPkg.version, + }), }); } } catch (err) {} @@ -203,7 +203,7 @@ function version(program, projectPath) { var ios; if (!targets.length || targets.indexOf("android") > -1) { - android = new Promise(function(resolve, reject) { + android = new Promise(function (resolve, reject) { log({ text: "Versioning Android..." }, programOpts.quiet); var gradleFile; @@ -215,16 +215,16 @@ function version(program, projectPath) { reject([ { style: "red", - text: "No gradle file found at " + programOpts.android + text: "No gradle file found at " + programOpts.android, }, { style: "yellow", - text: 'Use the "--android" option to specify the path manually' - } + text: 'Use the "--android" option to specify the path manually', + }, ]); } - if (!programOpts.incrementBuild && !isExpoApp) { + if (!programOpts.incrementBuild) { gradleFile = gradleFile.replace( /versionName (["'])(.*)["']/, "versionName $1" + appPkg.version + "$1" @@ -242,12 +242,12 @@ function version(program, projectPath) { programOpts, versionCode, appPkg.version - ) - }) - }) + ), + }), + }), }); } else { - gradleFile = gradleFile.replace(/versionCode (\d+)/, function( + gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( match, cg1 ) { @@ -262,11 +262,7 @@ function version(program, projectPath) { } } - if (isExpoApp) { - fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); - } else { - fs.writeFileSync(programOpts.android, gradleFile); - } + fs.writeFileSync(programOpts.android, gradleFile); log({ text: "Android updated" }, programOpts.quiet); resolve(); @@ -274,53 +270,82 @@ function version(program, projectPath) { } if (!targets.length || targets.indexOf("ios") > -1) { - ios = new Promise(function(resolve, reject) { + ios = new Promise(function (resolve, reject) { log({ text: "Versioning iOS..." }, programOpts.quiet); if (isExpoApp) { if (!programOpts.neverIncrementBuild) { const buildNumber = dottie.get(appJSON, "expo.ios.buildNumber"); + const newBuildVersion = getNewVersionCode( + programOpts, + parseInt(buildNumber, 10), + appPkg.version, + programOpts.resetBuild + ).toString(); appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: getNewVersionCode( - programOpts, - parseInt(buildNumber, 10), - appPkg.version, - programOpts.resetBuild - ).toString() - }) - }) + buildNumber: newBuildVersion, + }), + }), }); + + if (appJSON.expo.hooks) { + appJSON = Object.assign({}, appJSON, { + expo: Object.assign({}, appJSON.expo, { + hooks: Object.assign({}, appJSON.expo.hooks, { + postExport: appJSON.expo.hooks.postExport.map(function ( + hook + ) { + if (hook.file === "sentry-expo/upload-sourcemaps") { + return { + file: "sentry-expo/upload-sourcemaps", + config: Object.assign({}, hook.config, { + release: + appJSON.expo.ios.bundleIdentifier + + appPkg.version + + "+" + + newBuildVersion, + distribution: newBuildVersion, + }), + }; + } else { + return hook; + } + }), + }), + }), + }); + } } - - fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); - } else if (program.legacy) { + } + fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); + if (program.legacy) { try { child.execSync("xcode-select --print-path", { - stdio: ["ignore", "ignore", "pipe"] + stdio: ["ignore", "ignore", "pipe"], }); } catch (err) { reject([ { style: "red", - text: err + text: err, }, { style: "yellow", - text: "Looks like Xcode Command Line Tools aren't installed" + text: "Looks like Xcode Command Line Tools aren't installed", }, { - text: "\n Install:\n\n $ xcode-select --install\n" - } + text: "\n Install:\n\n $ xcode-select --install\n", + }, ]); return; } const agvtoolOpts = { - cwd: programOpts.ios + cwd: programOpts.ios, }; try { @@ -333,18 +358,18 @@ function version(program, projectPath) { ? [ { style: "red", - text: "No project folder found at " + programOpts.ios + text: "No project folder found at " + programOpts.ios, }, { style: "yellow", - text: 'Use the "--ios" option to specify the path manually' - } + text: 'Use the "--ios" option to specify the path manually', + }, ] : [ { style: "red", - text: stdout - } + text: stdout, + }, ] ); @@ -384,7 +409,7 @@ function version(program, projectPath) { // Find any folder ending in .xcodeproj const xcodeProjects = fs .readdirSync(programOpts.ios) - .filter(file => /\.xcodeproj$/i.test(file)); + .filter((file) => /\.xcodeproj$/i.test(file)); if (xcodeProjects.length < 1) { throw new Error(`Xcode project not found in "${programOpts.ios}"`); @@ -394,12 +419,13 @@ function version(program, projectPath) { const xcode = Xcode.open(path.join(projectFolder, "project.pbxproj")); const plistFilenames = getPlistFilenames(xcode); - xcode.document.projects.forEach(project => { + xcode.document.projects.forEach((project) => { !programOpts.neverIncrementBuild && - project.targets.filter(Boolean).forEach(target => { + project.targets.filter(Boolean).forEach((target) => { target.buildConfigurationsList.buildConfigurations.forEach( - config => { + (config) => { if (target.name === appPkg.name) { + console.log(target.name, appPkg.name); const CURRENT_PROJECT_VERSION = getNewVersionCode( programOpts, parseInt( @@ -414,22 +440,22 @@ function version(program, projectPath) { config.patch({ buildSettings: { - CURRENT_PROJECT_VERSION - } + CURRENT_PROJECT_VERSION, + }, }); } } ); }); - const plistFiles = plistFilenames.map(filename => { + const plistFiles = plistFilenames.map((filename) => { return fs.readFileSync( path.join(programOpts.ios, filename), "utf8" ); }); - const parsedPlistFiles = plistFiles.map(file => { + const parsedPlistFiles = plistFiles.map((file) => { return plist.parse(file); }); @@ -444,7 +470,7 @@ function version(program, projectPath) { ? { CFBundleShortVersionString: getCFBundleShortVersionString( appPkg.version - ) + ), } : {}, !programOpts.neverIncrementBuild @@ -454,7 +480,7 @@ function version(program, projectPath) { parseInt(json.CFBundleVersion, 10), appPkg.version, programOpts.resetBuild - ).toString() + ).toString(), } : {} ) @@ -499,21 +525,21 @@ function version(program, projectPath) { } return pSettle([android, ios].filter(Boolean)) - .then(function(result) { + .then(function (result) { const errs = result - .filter(function(item) { + .filter(function (item) { return item.isRejected; }) - .map(function(item) { + .map(function (item) { return item.reason; }); if (errs.length) { errs - .reduce(function(a, b) { + .reduce(function (a, b) { return a.concat(b); }, []) - .forEach(function(err) { + .forEach(function (err) { if (program.outputHelp) { log( Object.assign({ style: "red", text: err.toString() }, err), @@ -527,9 +553,9 @@ function version(program, projectPath) { } throw errs - .map(function(errGrp, index) { + .map(function (errGrp, index) { return errGrp - .map(function(err) { + .map(function (err) { return err.text; }) .join(", "); @@ -538,7 +564,7 @@ function version(program, projectPath) { } const gitCmdOpts = { - cwd: projPath + cwd: projPath, }; if ( @@ -571,9 +597,11 @@ function version(program, projectPath) { case "version": child.spawnSync( "git", - ["add"].concat( - isExpoApp ? appJSONPath : [programOpts.android, programOpts.ios] - ), + ["add"].concat([ + appJSONPath, + programOpts.android, + programOpts.ios, + ]), gitCmdOpts ); @@ -597,7 +625,7 @@ function version(program, projectPath) { log( { style: "green", - text: "Done" + text: "Done", }, programOpts.quiet ); @@ -608,14 +636,14 @@ function version(program, projectPath) { return child.execSync("git log -1 --pretty=%H", gitCmdOpts).toString(); }) - .catch(function(err) { + .catch(function (err) { if (process.env.RNV_ENV === "ava") { console.error(err); } log({ style: "red", - text: "Done, with errors." + text: "Done, with errors.", }); process.exit(1); @@ -627,5 +655,5 @@ module.exports = { getDefaults: getDefaults, getPlistFilenames: getPlistFilenames, isExpoProject: isExpoProject, - version: version + version: version, }; From 93dd59a4742c8ed472366162bdad6fe60b2ed1d3 Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 28 Oct 2020 16:47:18 -0700 Subject: [PATCH 02/10] Set Android versionCode as well based off app.json --- index.js | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 986747c..101cefb 100644 --- a/index.js +++ b/index.js @@ -232,34 +232,26 @@ function version(program, projectPath) { } if (!programOpts.neverIncrementBuild) { - if (isExpoApp) { - const versionCode = dottie.get(appJSON, "expo.android.versionCode"); - - appJSON = Object.assign({}, appJSON, { - expo: Object.assign({}, appJSON.expo, { - android: Object.assign({}, appJSON.expo.android, { - versionCode: getNewVersionCode( - programOpts, - versionCode, - appPkg.version - ), - }), + const versionCode = dottie.get(appJSON, "expo.android.versionCode"); + + appJSON = Object.assign({}, appJSON, { + expo: Object.assign({}, appJSON.expo, { + android: Object.assign({}, appJSON.expo.android, { + versionCode: getNewVersionCode( + programOpts, + versionCode, + appPkg.version + ), }), - }); - } else { - gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( - match, - cg1 - ) { - const newVersionCodeNumber = getNewVersionCode( - programOpts, - parseInt(cg1, 10), - appPkg.version - ); + }), + }); - return "versionCode " + newVersionCodeNumber; - }); - } + gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( + match, + cg1 + ) { + return "versionCode " + versionCode; + }); } fs.writeFileSync(programOpts.android, gradleFile); @@ -290,7 +282,7 @@ function version(program, projectPath) { }), }), }); - + if (appJSON.expo.hooks) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { From 05157d6ff5c5321f28035e12a3c9204a795cafee Mon Sep 17 00:00:00 2001 From: zibs Date: Fri, 30 Oct 2020 17:30:59 -0700 Subject: [PATCH 03/10] Update index.js --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 101cefb..3bcdba7 100644 --- a/index.js +++ b/index.js @@ -232,16 +232,16 @@ function version(program, projectPath) { } if (!programOpts.neverIncrementBuild) { - const versionCode = dottie.get(appJSON, "expo.android.versionCode"); - + const versionCode = parseInt(dottie.get(appJSON, "expo.android.versionCode")); + const newVersionCode = getNewVersionCode( + programOpts, + versionCode, + appPkg.version + ); appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { android: Object.assign({}, appJSON.expo.android, { - versionCode: getNewVersionCode( - programOpts, - versionCode, - appPkg.version - ), + versionCode: newVersionCode }), }), }); @@ -250,7 +250,7 @@ function version(program, projectPath) { match, cg1 ) { - return "versionCode " + versionCode; + return "versionCode " + newVersionCode; }); } From dcc48c00d17b5c4e7f287a30e9b55fa363aae059 Mon Sep 17 00:00:00 2001 From: zibs Date: Fri, 30 Oct 2020 18:09:13 -0700 Subject: [PATCH 04/10] tabs --- index.js | 132 +++++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/index.js b/index.js index 3bcdba7..f72817f 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const Xcode = require("pbxproj-dom/xcode").Xcode; */ const env = { - target: process.env.RNV && list(process.env.RNV), + target: process.env.RNV && list(process.env.RNV) }; /** @@ -34,7 +34,7 @@ const env = { function getDefaults() { return { android: "android/app/build.gradle", - ios: "ios", + ios: "ios" }; } @@ -47,10 +47,10 @@ function getDefaults() { function getPlistFilenames(xcode) { return unique( flattenDeep( - xcode.document.projects.map((project) => { - return project.targets.filter(Boolean).map((target) => { + xcode.document.projects.map(project => { + return project.targets.filter(Boolean).map(target => { return target.buildConfigurationsList.buildConfigurations.map( - (config) => { + config => { return config.ast.value.get("buildSettings").get("INFOPLIST_FILE") .text; } @@ -141,7 +141,7 @@ function version(program, projectPath) { const programOpts = Object.assign({}, prog, { android: path.join(projPath, prog.android), - ios: path.join(projPath, prog.ios), + ios: path.join(projPath, prog.ios) }); const targets = [].concat(programOpts.target, env.target).filter(Boolean); @@ -154,24 +154,24 @@ function version(program, projectPath) { if (err.message === "Cannot find module 'react-native'") { log({ style: "red", - text: `Is this the right folder? ${err.message} in ${projPath}`, + text: `Is this the right folder? ${err.message} in ${projPath}` }); } else { log({ style: "red", - text: err.message, + text: err.message }); log({ style: "red", text: - "Is this the right folder? Looks like there isn't a package.json here", + "Is this the right folder? Looks like there isn't a package.json here" }); } log({ style: "yellow", - text: "Pass the project path as an argument, see --help for usage", + text: "Pass the project path as an argument, see --help for usage" }); if (program.outputHelp) { @@ -193,8 +193,8 @@ function version(program, projectPath) { if (isExpoApp && !programOpts.incrementBuild) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { - version: appPkg.version, - }), + version: appPkg.version + }) }); } } catch (err) {} @@ -203,7 +203,7 @@ function version(program, projectPath) { var ios; if (!targets.length || targets.indexOf("android") > -1) { - android = new Promise(function (resolve, reject) { + android = new Promise(function(resolve, reject) { log({ text: "Versioning Android..." }, programOpts.quiet); var gradleFile; @@ -215,12 +215,12 @@ function version(program, projectPath) { reject([ { style: "red", - text: "No gradle file found at " + programOpts.android, + text: "No gradle file found at " + programOpts.android }, { style: "yellow", - text: 'Use the "--android" option to specify the path manually', - }, + text: 'Use the "--android" option to specify the path manually' + } ]); } @@ -232,7 +232,9 @@ function version(program, projectPath) { } if (!programOpts.neverIncrementBuild) { - const versionCode = parseInt(dottie.get(appJSON, "expo.android.versionCode")); + const versionCode = parseInt( + dottie.get(appJSON, "expo.android.versionCode") + ); const newVersionCode = getNewVersionCode( programOpts, versionCode, @@ -242,11 +244,11 @@ function version(program, projectPath) { expo: Object.assign({}, appJSON.expo, { android: Object.assign({}, appJSON.expo.android, { versionCode: newVersionCode - }), - }), + }) + }) }); - gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( + gradleFile = gradleFile.replace(/versionCode (\d+)/, function( match, cg1 ) { @@ -262,7 +264,7 @@ function version(program, projectPath) { } if (!targets.length || targets.indexOf("ios") > -1) { - ios = new Promise(function (resolve, reject) { + ios = new Promise(function(resolve, reject) { log({ text: "Versioning iOS..." }, programOpts.quiet); if (isExpoApp) { @@ -278,18 +280,16 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: newBuildVersion, - }), - }), + buildNumber: newBuildVersion + }) + }) }); if (appJSON.expo.hooks) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { hooks: Object.assign({}, appJSON.expo.hooks, { - postExport: appJSON.expo.hooks.postExport.map(function ( - hook - ) { + postExport: appJSON.expo.hooks.postExport.map(function(hook) { if (hook.file === "sentry-expo/upload-sourcemaps") { return { file: "sentry-expo/upload-sourcemaps", @@ -299,15 +299,15 @@ function version(program, projectPath) { appPkg.version + "+" + newBuildVersion, - distribution: newBuildVersion, - }), + distribution: newBuildVersion + }) }; } else { return hook; } - }), - }), - }), + }) + }) + }) }); } } @@ -316,28 +316,28 @@ function version(program, projectPath) { if (program.legacy) { try { child.execSync("xcode-select --print-path", { - stdio: ["ignore", "ignore", "pipe"], + stdio: ["ignore", "ignore", "pipe"] }); } catch (err) { reject([ { style: "red", - text: err, + text: err }, { style: "yellow", - text: "Looks like Xcode Command Line Tools aren't installed", + text: "Looks like Xcode Command Line Tools aren't installed" }, { - text: "\n Install:\n\n $ xcode-select --install\n", - }, + text: "\n Install:\n\n $ xcode-select --install\n" + } ]); return; } const agvtoolOpts = { - cwd: programOpts.ios, + cwd: programOpts.ios }; try { @@ -350,18 +350,18 @@ function version(program, projectPath) { ? [ { style: "red", - text: "No project folder found at " + programOpts.ios, + text: "No project folder found at " + programOpts.ios }, { style: "yellow", - text: 'Use the "--ios" option to specify the path manually', - }, + text: 'Use the "--ios" option to specify the path manually' + } ] : [ { style: "red", - text: stdout, - }, + text: stdout + } ] ); @@ -401,7 +401,7 @@ function version(program, projectPath) { // Find any folder ending in .xcodeproj const xcodeProjects = fs .readdirSync(programOpts.ios) - .filter((file) => /\.xcodeproj$/i.test(file)); + .filter(file => /\.xcodeproj$/i.test(file)); if (xcodeProjects.length < 1) { throw new Error(`Xcode project not found in "${programOpts.ios}"`); @@ -411,11 +411,11 @@ function version(program, projectPath) { const xcode = Xcode.open(path.join(projectFolder, "project.pbxproj")); const plistFilenames = getPlistFilenames(xcode); - xcode.document.projects.forEach((project) => { + xcode.document.projects.forEach(project => { !programOpts.neverIncrementBuild && - project.targets.filter(Boolean).forEach((target) => { + project.targets.filter(Boolean).forEach(target => { target.buildConfigurationsList.buildConfigurations.forEach( - (config) => { + config => { if (target.name === appPkg.name) { console.log(target.name, appPkg.name); const CURRENT_PROJECT_VERSION = getNewVersionCode( @@ -432,22 +432,22 @@ function version(program, projectPath) { config.patch({ buildSettings: { - CURRENT_PROJECT_VERSION, - }, + CURRENT_PROJECT_VERSION + } }); } } ); }); - const plistFiles = plistFilenames.map((filename) => { + const plistFiles = plistFilenames.map(filename => { return fs.readFileSync( path.join(programOpts.ios, filename), "utf8" ); }); - const parsedPlistFiles = plistFiles.map((file) => { + const parsedPlistFiles = plistFiles.map(file => { return plist.parse(file); }); @@ -462,7 +462,7 @@ function version(program, projectPath) { ? { CFBundleShortVersionString: getCFBundleShortVersionString( appPkg.version - ), + ) } : {}, !programOpts.neverIncrementBuild @@ -472,7 +472,7 @@ function version(program, projectPath) { parseInt(json.CFBundleVersion, 10), appPkg.version, programOpts.resetBuild - ).toString(), + ).toString() } : {} ) @@ -517,21 +517,21 @@ function version(program, projectPath) { } return pSettle([android, ios].filter(Boolean)) - .then(function (result) { + .then(function(result) { const errs = result - .filter(function (item) { + .filter(function(item) { return item.isRejected; }) - .map(function (item) { + .map(function(item) { return item.reason; }); if (errs.length) { errs - .reduce(function (a, b) { + .reduce(function(a, b) { return a.concat(b); }, []) - .forEach(function (err) { + .forEach(function(err) { if (program.outputHelp) { log( Object.assign({ style: "red", text: err.toString() }, err), @@ -545,9 +545,9 @@ function version(program, projectPath) { } throw errs - .map(function (errGrp, index) { + .map(function(errGrp, index) { return errGrp - .map(function (err) { + .map(function(err) { return err.text; }) .join(", "); @@ -556,7 +556,7 @@ function version(program, projectPath) { } const gitCmdOpts = { - cwd: projPath, + cwd: projPath }; if ( @@ -592,7 +592,7 @@ function version(program, projectPath) { ["add"].concat([ appJSONPath, programOpts.android, - programOpts.ios, + programOpts.ios ]), gitCmdOpts ); @@ -617,7 +617,7 @@ function version(program, projectPath) { log( { style: "green", - text: "Done", + text: "Done" }, programOpts.quiet ); @@ -628,14 +628,14 @@ function version(program, projectPath) { return child.execSync("git log -1 --pretty=%H", gitCmdOpts).toString(); }) - .catch(function (err) { + .catch(function(err) { if (process.env.RNV_ENV === "ava") { console.error(err); } log({ style: "red", - text: "Done, with errors.", + text: "Done, with errors." }); process.exit(1); @@ -647,5 +647,5 @@ module.exports = { getDefaults: getDefaults, getPlistFilenames: getPlistFilenames, isExpoProject: isExpoProject, - version: version, + version: version }; From 6e76532f9b5ff4e08c864c1994b5a773956e345f Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 11 Nov 2020 19:54:59 -0800 Subject: [PATCH 05/10] Adds two CLI options: 1. --is-bare-expo-workflow Bare workflow expo apps want to update *everything*. This will update the app.json values and the /android and the /ios values. 2. --is-self-hosting-bundles This one is a bit more esoteric, but it's meant for bare workflow apps using sentry-expo to upload their sourcemaps in a postExport hook, where it's essential to keep the release/dist versions align with the build/release versions. If it's passed in, it will look in the hooks inside the app.json file to update these values as needed. --- cli.js | 2 ++ index.js | 80 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/cli.js b/cli.js index 15f4c32..6254d28 100755 --- a/cli.js +++ b/cli.js @@ -32,6 +32,8 @@ program "-L, --legacy", "Version iOS using agvtool (macOS only). Requires Xcode Command Line Tools." ) + .option("--is-bare-expo-workflow", "todo") + .option("--is-self-hosting-bundles", "todo") .option("-q, --quiet", "Be quiet, only report errors.") .option( "-r, --reset-build", diff --git a/index.js b/index.js index 345f3d4..8b78d42 100644 --- a/index.js +++ b/index.js @@ -183,7 +183,8 @@ function version(program, projectPath) { var appJSON; const appJSONPath = path.join(projPath, "app.json"); - const isExpoApp = isExpoProject(projPath); + const isExpoApp = isExpoProject(projPath) || programOpts.isBareExpoWorkflow; + const isBareExpoWorkflow = programOpts.isBareExpoWorkflow; isExpoApp && log({ text: "Expo detected" }, programOpts.quiet); @@ -224,7 +225,7 @@ function version(program, projectPath) { ]); } - if (!programOpts.incrementBuild && !isExpoApp) { + if ((!programOpts.incrementBuild && !isExpoApp) || isBareExpoWorkflow) { gradleFile = gradleFile.replace( /versionName (["'])(.*)["']/, "versionName $1" + appPkg.version + "$1" @@ -262,6 +263,34 @@ function version(program, projectPath) { } } + if (isBareExpoWorkflow) { + // if bare expo workflow, combine the two exclusive blocks above + const versionCode = parseInt( + dottie.get(appJSON, "expo.android.versionCode") + ); + const newVersionCode = getNewVersionCode( + programOpts, + versionCode, + appPkg.version + ); + appJSON = Object.assign({}, appJSON, { + expo: Object.assign({}, appJSON.expo, { + android: Object.assign({}, appJSON.expo.android, { + versionCode: newVersionCode + }) + }) + }); + + gradleFile = gradleFile.replace(/versionCode (\d+)/, function( + match, + cg1 + ) { + return "versionCode " + newVersionCode; + }); + fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); + fs.writeFileSync(programOpts.android, gradleFile); + } + if (isExpoApp) { fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); } else { @@ -277,26 +306,55 @@ function version(program, projectPath) { ios = new Promise(function(resolve, reject) { log({ text: "Versioning iOS..." }, programOpts.quiet); - if (isExpoApp) { + if (isExpoApp || isBareExpoWorkflow) { if (!programOpts.neverIncrementBuild) { const buildNumber = dottie.get(appJSON, "expo.ios.buildNumber"); + const newBuildVersion = getNewVersionCode( + programOpts, + parseInt(buildNumber, 10), + appPkg.version, + programOpts.resetBuild + ).toString(); + appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: getNewVersionCode( - programOpts, - parseInt(buildNumber, 10), - appPkg.version, - programOpts.resetBuild - ).toString() + buildNumber: newBuildVersion }) }) }); - } + if (appJSON.expo.hooks) { + appJSON = Object.assign({}, appJSON, { + expo: Object.assign({}, appJSON.expo, { + hooks: Object.assign({}, appJSON.expo.hooks, { + // someone can add their own postPub + postExport: appJSON.expo.hooks.postExport.map(function(hook) { + if (hook.file === "sentry-expo/upload-sourcemaps") { + return { + file: "sentry-expo/upload-sourcemaps", + config: Object.assign({}, hook.config, { + release: + appJSON.expo.ios.bundleIdentifier + + appPkg.version + + "+" + + newBuildVersion, + distribution: newBuildVersion + }) + }; + } else { + return hook; + } + }) + }) + }) + }); + } + } fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); - } else if (program.legacy) { + } + if (program.legacy) { try { child.execSync("xcode-select --print-path", { stdio: ["ignore", "ignore", "pipe"] From 0cf05827228a5eb2b3a7073509559c52cfa01000 Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 11 Nov 2020 20:04:04 -0800 Subject: [PATCH 06/10] finish todos --- cli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index 6254d28..05b5d99 100755 --- a/cli.js +++ b/cli.js @@ -32,8 +32,8 @@ program "-L, --legacy", "Version iOS using agvtool (macOS only). Requires Xcode Command Line Tools." ) - .option("--is-bare-expo-workflow", "todo") - .option("--is-self-hosting-bundles", "todo") + .option("--is-bare-expo-workflow", "Bare workflow expo apps want to update *everything*. This will update the app.json values and the /android and the /ios values.") + .option("--is-self-hosting-bundles", "This will increment the values in the postExport hook inside the app.json to what Sentry expects when uploading sourcemaps. This value auto-tracks your build version/build number.") .option("-q, --quiet", "Be quiet, only report errors.") .option( "-r, --reset-build", From d3aa74867ba3bf211dfa0e1d5a8f630ea3456e51 Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 11 Nov 2020 20:09:30 -0800 Subject: [PATCH 07/10] run docs --- README.md | 56 +++++++++++++++++---- index.js | 142 +++++++++++++++++++++++++++--------------------------- 2 files changed, 118 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index df2b501..2b2add8 100644 --- a/README.md +++ b/README.md @@ -59,20 +59,58 @@ $ react-native-version -V, --version output the version number - -a, --amend Amend the previous commit. This is done automatically when react-native-version is run from the "version" or "postversion" npm script. Use "--never-amend" if you never want to amend. Also, if the previous commit is a valid npm-version commit, react-native-version will update the Git tag pointing to this commit. - --skip-tag For use with "--amend", if you don't want to update Git tags. Use this option if you have git-tag-version set to false in your npm config or you use "--no-git-tag-version" during npm-version. + -a, --amend Amend the previous commit. This is done + automatically when react-native-version is run + from the "version" or "postversion" npm script. + Use "--never-amend" if you never want to amend. + Also, if the previous commit is a valid + npm-version commit, react-native-version will + update the Git tag pointing to this commit. + --skip-tag For use with "--amend", if you don't want to + update Git tags. Use this option if you have + git-tag-version set to false in your npm config + or you use "--no-git-tag-version" during + npm-version. -A, --never-amend Never amend the previous commit. -b, --increment-build Only increment build number. -B, --never-increment-build Never increment build number. - -d, --android [path] Path to your "android/app/build.gradle" file. (default: "android/app/build.gradle") + -d, --android [path] Path to your "android/app/build.gradle" file. + (default: "android/app/build.gradle") -i, --ios [path] Path to your "ios/" folder. (default: "ios") - -L, --legacy Version iOS using agvtool (macOS only). Requires Xcode Command Line Tools. + -L, --legacy Version iOS using agvtool (macOS only). Requires + Xcode Command Line Tools. + --is-bare-expo-workflow Bare workflow expo apps want to update + *everything*. This will update the app.json + values and the /android and the /ios values. + --is-self-hosting-bundles This will increment the values in the postExport + hook inside the app.json to what Sentry expects + when uploading sourcemaps. This value + auto-tracks your build version/build number. -q, --quiet Be quiet, only report errors. - -r, --reset-build Reset build number back to "1" (iOS only). Unlike Android's "versionCode", iOS doesn't require you to bump the "CFBundleVersion", as long as "CFBundleShortVersionString" changes. To make it consistent across platforms, react-native-version bumps both by default. You can use this option if you prefer to keep the build number value at "1" after every version change. If you then need to push another build under the same version, you can use "-bt ios" to increment. - -s, --set-build Set a build number. WARNING: Watch out when setting high values. This option follows Android's app versioning specifics - the value has to be an integer and cannot be greater than 2100000000. You cannot decrement this value after publishing to Google Play! More info at: https://developer.android.com/studio/publish/versioning.html#appversioning - --generate-build Generate build number from the package version number. (e.g. build number for version 1.22.3 will be 1022003) - -t, --target Only version specified platforms, e.g. "--target android,ios". - -h, --help output usage information + -r, --reset-build Reset build number back to "1" (iOS only). + Unlike Android's "versionCode", iOS doesn't + require you to bump the "CFBundleVersion", as + long as "CFBundleShortVersionString" changes. To + make it consistent across platforms, + react-native-version bumps both by default. You + can use this option if you prefer to keep the + build number value at "1" after every version + change. If you then need to push another build + under the same version, you can use "-bt ios" to + increment. + -s, --set-build Set a build number. WARNING: Watch out when + setting high values. This option follows + Android's app versioning specifics - the value + has to be an integer and cannot be greater than + 2100000000. You cannot decrement this value + after publishing to Google Play! More info at: + https://developer.android.com/studio/publish/versioning.html#appversioning + --generate-build Generate build number from the package version + number. (e.g. build number for version 1.22.3 + will be 1022003) + -t, --target Only version specified platforms, e.g. "--target + android,ios". + -h, --help display help for command diff --git a/index.js b/index.js index 8b78d42..fc041ef 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const Xcode = require("pbxproj-dom/xcode").Xcode; */ const env = { - target: process.env.RNV && list(process.env.RNV) + target: process.env.RNV && list(process.env.RNV), }; /** @@ -34,7 +34,7 @@ const env = { function getDefaults() { return { android: "android/app/build.gradle", - ios: "ios" + ios: "ios", }; } @@ -47,10 +47,10 @@ function getDefaults() { function getPlistFilenames(xcode) { return unique( flattenDeep( - xcode.document.projects.map(project => { - return project.targets.filter(Boolean).map(target => { + xcode.document.projects.map((project) => { + return project.targets.filter(Boolean).map((target) => { return target.buildConfigurationsList.buildConfigurations.map( - config => { + (config) => { return config.ast.value.get("buildSettings").get("INFOPLIST_FILE") .text; } @@ -141,7 +141,7 @@ function version(program, projectPath) { const programOpts = Object.assign({}, prog, { android: path.join(projPath, prog.android), - ios: path.join(projPath, prog.ios) + ios: path.join(projPath, prog.ios), }); const targets = [].concat(programOpts.target, env.target).filter(Boolean); @@ -154,24 +154,24 @@ function version(program, projectPath) { if (err.message === "Cannot find module 'react-native'") { log({ style: "red", - text: `Is this the right folder? ${err.message} in ${projPath}` + text: `Is this the right folder? ${err.message} in ${projPath}`, }); } else { log({ style: "red", - text: err.message + text: err.message, }); log({ style: "red", text: - "Is this the right folder? Looks like there isn't a package.json here" + "Is this the right folder? Looks like there isn't a package.json here", }); } log({ style: "yellow", - text: "Pass the project path as an argument, see --help for usage" + text: "Pass the project path as an argument, see --help for usage", }); if (program.outputHelp) { @@ -194,8 +194,8 @@ function version(program, projectPath) { if (isExpoApp && !programOpts.incrementBuild) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { - version: appPkg.version - }) + version: appPkg.version, + }), }); } } catch (err) {} @@ -204,11 +204,10 @@ function version(program, projectPath) { var ios; if (!targets.length || targets.indexOf("android") > -1) { - android = new Promise(function(resolve, reject) { + android = new Promise(function (resolve, reject) { log({ text: "Versioning Android..." }, programOpts.quiet); var gradleFile; - try { gradleFile = fs.readFileSync(programOpts.android, "utf8"); } catch (err) { @@ -216,12 +215,12 @@ function version(program, projectPath) { reject([ { style: "red", - text: "No gradle file found at " + programOpts.android + text: "No gradle file found at " + programOpts.android, }, { style: "yellow", - text: 'Use the "--android" option to specify the path manually' - } + text: 'Use the "--android" option to specify the path manually', + }, ]); } @@ -243,12 +242,12 @@ function version(program, projectPath) { programOpts, versionCode, appPkg.version - ) - }) - }) + ), + }), + }), }); } else { - gradleFile = gradleFile.replace(/versionCode (\d+)/, function( + gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( match, cg1 ) { @@ -264,7 +263,7 @@ function version(program, projectPath) { } if (isBareExpoWorkflow) { - // if bare expo workflow, combine the two exclusive blocks above + // if bare expo workflow, combine the two exclusive blocks above const versionCode = parseInt( dottie.get(appJSON, "expo.android.versionCode") ); @@ -276,12 +275,12 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { android: Object.assign({}, appJSON.expo.android, { - versionCode: newVersionCode - }) - }) + versionCode: newVersionCode, + }), + }), }); - gradleFile = gradleFile.replace(/versionCode (\d+)/, function( + gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( match, cg1 ) { @@ -303,7 +302,7 @@ function version(program, projectPath) { } if (!targets.length || targets.indexOf("ios") > -1) { - ios = new Promise(function(resolve, reject) { + ios = new Promise(function (resolve, reject) { log({ text: "Versioning iOS..." }, programOpts.quiet); if (isExpoApp || isBareExpoWorkflow) { @@ -316,13 +315,12 @@ function version(program, projectPath) { programOpts.resetBuild ).toString(); - appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: newBuildVersion - }) - }) + buildNumber: newBuildVersion, + }), + }), }); if (appJSON.expo.hooks) { @@ -330,7 +328,9 @@ function version(program, projectPath) { expo: Object.assign({}, appJSON.expo, { hooks: Object.assign({}, appJSON.expo.hooks, { // someone can add their own postPub - postExport: appJSON.expo.hooks.postExport.map(function(hook) { + postExport: appJSON.expo.hooks.postExport.map(function ( + hook + ) { if (hook.file === "sentry-expo/upload-sourcemaps") { return { file: "sentry-expo/upload-sourcemaps", @@ -340,45 +340,45 @@ function version(program, projectPath) { appPkg.version + "+" + newBuildVersion, - distribution: newBuildVersion - }) + distribution: newBuildVersion, + }), }; } else { return hook; } - }) - }) - }) + }), + }), + }), }); } } fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); - } + } if (program.legacy) { try { child.execSync("xcode-select --print-path", { - stdio: ["ignore", "ignore", "pipe"] + stdio: ["ignore", "ignore", "pipe"], }); } catch (err) { reject([ { style: "red", - text: err + text: err, }, { style: "yellow", - text: "Looks like Xcode Command Line Tools aren't installed" + text: "Looks like Xcode Command Line Tools aren't installed", }, { - text: "\n Install:\n\n $ xcode-select --install\n" - } + text: "\n Install:\n\n $ xcode-select --install\n", + }, ]); return; } const agvtoolOpts = { - cwd: programOpts.ios + cwd: programOpts.ios, }; try { @@ -391,18 +391,18 @@ function version(program, projectPath) { ? [ { style: "red", - text: "No project folder found at " + programOpts.ios + text: "No project folder found at " + programOpts.ios, }, { style: "yellow", - text: 'Use the "--ios" option to specify the path manually' - } + text: 'Use the "--ios" option to specify the path manually', + }, ] : [ { style: "red", - text: stdout - } + text: stdout, + }, ] ); @@ -442,7 +442,7 @@ function version(program, projectPath) { // Find any folder ending in .xcodeproj const xcodeProjects = fs .readdirSync(programOpts.ios) - .filter(file => /\.xcodeproj$/i.test(file)); + .filter((file) => /\.xcodeproj$/i.test(file)); if (xcodeProjects.length < 1) { throw new Error(`Xcode project not found in "${programOpts.ios}"`); @@ -452,11 +452,11 @@ function version(program, projectPath) { const xcode = Xcode.open(path.join(projectFolder, "project.pbxproj")); const plistFilenames = getPlistFilenames(xcode); - xcode.document.projects.forEach(project => { + xcode.document.projects.forEach((project) => { !programOpts.neverIncrementBuild && - project.targets.filter(Boolean).forEach(target => { + project.targets.filter(Boolean).forEach((target) => { target.buildConfigurationsList.buildConfigurations.forEach( - config => { + (config) => { if (target.name === appPkg.name) { const CURRENT_PROJECT_VERSION = getNewVersionCode( programOpts, @@ -472,22 +472,22 @@ function version(program, projectPath) { config.patch({ buildSettings: { - CURRENT_PROJECT_VERSION - } + CURRENT_PROJECT_VERSION, + }, }); } } ); }); - const plistFiles = plistFilenames.map(filename => { + const plistFiles = plistFilenames.map((filename) => { return fs.readFileSync( path.join(programOpts.ios, filename), "utf8" ); }); - const parsedPlistFiles = plistFiles.map(file => { + const parsedPlistFiles = plistFiles.map((file) => { return plist.parse(file); }); @@ -502,7 +502,7 @@ function version(program, projectPath) { ? { CFBundleShortVersionString: getCFBundleShortVersionString( appPkg.version - ) + ), } : {}, !programOpts.neverIncrementBuild @@ -512,7 +512,7 @@ function version(program, projectPath) { parseInt(json.CFBundleVersion, 10), appPkg.version, programOpts.resetBuild - ).toString() + ).toString(), } : {} ) @@ -557,21 +557,21 @@ function version(program, projectPath) { } return pSettle([android, ios].filter(Boolean)) - .then(function(result) { + .then(function (result) { const errs = result - .filter(function(item) { + .filter(function (item) { return item.isRejected; }) - .map(function(item) { + .map(function (item) { return item.reason; }); if (errs.length) { errs - .reduce(function(a, b) { + .reduce(function (a, b) { return a.concat(b); }, []) - .forEach(function(err) { + .forEach(function (err) { if (program.outputHelp) { log( Object.assign({ style: "red", text: err.toString() }, err), @@ -585,9 +585,9 @@ function version(program, projectPath) { } throw errs - .map(function(errGrp, index) { + .map(function (errGrp, index) { return errGrp - .map(function(err) { + .map(function (err) { return err.text; }) .join(", "); @@ -596,7 +596,7 @@ function version(program, projectPath) { } const gitCmdOpts = { - cwd: projPath + cwd: projPath, }; if ( @@ -655,7 +655,7 @@ function version(program, projectPath) { log( { style: "green", - text: "Done" + text: "Done", }, programOpts.quiet ); @@ -666,14 +666,14 @@ function version(program, projectPath) { return child.execSync("git log -1 --pretty=%H", gitCmdOpts).toString(); }) - .catch(function(err) { + .catch(function (err) { if (process.env.RNV_ENV === "ava") { console.error(err); } log({ style: "red", - text: "Done, with errors." + text: "Done, with errors.", }); process.exit(1); @@ -685,5 +685,5 @@ module.exports = { getDefaults: getDefaults, getPlistFilenames: getPlistFilenames, isExpoProject: isExpoProject, - version: version + version: version, }; From 5bf97e79d43f0307275447aa854ac848a6d10410 Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 11 Nov 2020 20:28:58 -0800 Subject: [PATCH 08/10] fix tests --- index.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index fc041ef..2f0f1ac 100644 --- a/index.js +++ b/index.js @@ -183,7 +183,7 @@ function version(program, projectPath) { var appJSON; const appJSONPath = path.join(projPath, "app.json"); - const isExpoApp = isExpoProject(projPath) || programOpts.isBareExpoWorkflow; + const isExpoApp = isExpoProject(projPath); const isBareExpoWorkflow = programOpts.isBareExpoWorkflow; isExpoApp && log({ text: "Expo detected" }, programOpts.quiet); @@ -305,7 +305,7 @@ function version(program, projectPath) { ios = new Promise(function (resolve, reject) { log({ text: "Versioning iOS..." }, programOpts.quiet); - if (isExpoApp || isBareExpoWorkflow) { + if (isBareExpoWorkflow) { if (!programOpts.neverIncrementBuild) { const buildNumber = dottie.get(appJSON, "expo.ios.buildNumber"); const newBuildVersion = getNewVersionCode( @@ -354,7 +354,26 @@ function version(program, projectPath) { } fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); } - if (program.legacy) { + if (isExpoApp && !isBareExpoWorkflow) { + if (!programOpts.neverIncrementBuild) { + const buildNumber = dottie.get(appJSON, "expo.ios.buildNumber"); + const newBuildVersion = getNewVersionCode( + programOpts, + parseInt(buildNumber, 10), + appPkg.version, + programOpts.resetBuild + ).toString(); + + appJSON = Object.assign({}, appJSON, { + expo: Object.assign({}, appJSON.expo, { + ios: Object.assign({}, appJSON.expo.ios, { + buildNumber: newBuildVersion, + }), + }), + }); + fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); + } + } else if (program.legacy) { try { child.execSync("xcode-select --print-path", { stdio: ["ignore", "ignore", "pipe"], From 8323fefad960cbf0f3774c629022eecf52c8f40a Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 11 Nov 2020 20:32:37 -0800 Subject: [PATCH 09/10] remove trailing comma --- index.js | 96 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/index.js b/index.js index 2f0f1ac..c024a14 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const Xcode = require("pbxproj-dom/xcode").Xcode; */ const env = { - target: process.env.RNV && list(process.env.RNV), + target: process.env.RNV && list(process.env.RNV) }; /** @@ -34,7 +34,7 @@ const env = { function getDefaults() { return { android: "android/app/build.gradle", - ios: "ios", + ios: "ios" }; } @@ -141,7 +141,7 @@ function version(program, projectPath) { const programOpts = Object.assign({}, prog, { android: path.join(projPath, prog.android), - ios: path.join(projPath, prog.ios), + ios: path.join(projPath, prog.ios) }); const targets = [].concat(programOpts.target, env.target).filter(Boolean); @@ -154,24 +154,24 @@ function version(program, projectPath) { if (err.message === "Cannot find module 'react-native'") { log({ style: "red", - text: `Is this the right folder? ${err.message} in ${projPath}`, + text: `Is this the right folder? ${err.message} in ${projPath}` }); } else { log({ style: "red", - text: err.message, + text: err.message }); log({ style: "red", text: - "Is this the right folder? Looks like there isn't a package.json here", + "Is this the right folder? Looks like there isn't a package.json here" }); } log({ style: "yellow", - text: "Pass the project path as an argument, see --help for usage", + text: "Pass the project path as an argument, see --help for usage" }); if (program.outputHelp) { @@ -194,8 +194,8 @@ function version(program, projectPath) { if (isExpoApp && !programOpts.incrementBuild) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { - version: appPkg.version, - }), + version: appPkg.version + }) }); } } catch (err) {} @@ -215,12 +215,12 @@ function version(program, projectPath) { reject([ { style: "red", - text: "No gradle file found at " + programOpts.android, + text: "No gradle file found at " + programOpts.android }, { style: "yellow", - text: 'Use the "--android" option to specify the path manually', - }, + text: 'Use the "--android" option to specify the path manually' + } ]); } @@ -242,9 +242,9 @@ function version(program, projectPath) { programOpts, versionCode, appPkg.version - ), - }), - }), + ) + }) + }) }); } else { gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( @@ -275,9 +275,9 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { android: Object.assign({}, appJSON.expo.android, { - versionCode: newVersionCode, - }), - }), + versionCode: newVersionCode + }) + }) }); gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( @@ -318,9 +318,9 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: newBuildVersion, - }), - }), + buildNumber: newBuildVersion + }) + }) }); if (appJSON.expo.hooks) { @@ -340,15 +340,15 @@ function version(program, projectPath) { appPkg.version + "+" + newBuildVersion, - distribution: newBuildVersion, - }), + distribution: newBuildVersion + }) }; } else { return hook; } - }), - }), - }), + }) + }) + }) }); } } @@ -367,37 +367,37 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: newBuildVersion, - }), - }), + buildNumber: newBuildVersion + }) + }) }); fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); } } else if (program.legacy) { try { child.execSync("xcode-select --print-path", { - stdio: ["ignore", "ignore", "pipe"], + stdio: ["ignore", "ignore", "pipe"] }); } catch (err) { reject([ { style: "red", - text: err, + text: err }, { style: "yellow", - text: "Looks like Xcode Command Line Tools aren't installed", + text: "Looks like Xcode Command Line Tools aren't installed" }, { - text: "\n Install:\n\n $ xcode-select --install\n", - }, + text: "\n Install:\n\n $ xcode-select --install\n" + } ]); return; } const agvtoolOpts = { - cwd: programOpts.ios, + cwd: programOpts.ios }; try { @@ -410,18 +410,18 @@ function version(program, projectPath) { ? [ { style: "red", - text: "No project folder found at " + programOpts.ios, + text: "No project folder found at " + programOpts.ios }, { style: "yellow", - text: 'Use the "--ios" option to specify the path manually', - }, + text: 'Use the "--ios" option to specify the path manually' + } ] : [ { style: "red", - text: stdout, - }, + text: stdout + } ] ); @@ -491,8 +491,8 @@ function version(program, projectPath) { config.patch({ buildSettings: { - CURRENT_PROJECT_VERSION, - }, + CURRENT_PROJECT_VERSION + } }); } } @@ -521,7 +521,7 @@ function version(program, projectPath) { ? { CFBundleShortVersionString: getCFBundleShortVersionString( appPkg.version - ), + ) } : {}, !programOpts.neverIncrementBuild @@ -531,7 +531,7 @@ function version(program, projectPath) { parseInt(json.CFBundleVersion, 10), appPkg.version, programOpts.resetBuild - ).toString(), + ).toString() } : {} ) @@ -615,7 +615,7 @@ function version(program, projectPath) { } const gitCmdOpts = { - cwd: projPath, + cwd: projPath }; if ( @@ -674,7 +674,7 @@ function version(program, projectPath) { log( { style: "green", - text: "Done", + text: "Done" }, programOpts.quiet ); @@ -692,7 +692,7 @@ function version(program, projectPath) { log({ style: "red", - text: "Done, with errors.", + text: "Done, with errors." }); process.exit(1); @@ -704,5 +704,5 @@ module.exports = { getDefaults: getDefaults, getPlistFilenames: getPlistFilenames, isExpoProject: isExpoProject, - version: version, + version: version }; From 39c3519fc9f59db89b0f07ba91b4d64625788c0c Mon Sep 17 00:00:00 2001 From: zibs Date: Wed, 6 Jan 2021 08:09:25 -0800 Subject: [PATCH 10/10] Actually use isSelfHostingBundles flag --- index.js | 144 +++++++++++++++++++++++++++---------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/index.js b/index.js index 15923c4..d7d86ac 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const Xcode = require("pbxproj-dom/xcode").Xcode; */ const env = { - target: process.env.RNV && list(process.env.RNV) + target: process.env.RNV && list(process.env.RNV), }; /** @@ -34,7 +34,7 @@ const env = { function getDefaults() { return { android: "android/app/build.gradle", - ios: "ios" + ios: "ios", }; } @@ -141,7 +141,7 @@ function version(program, projectPath) { const programOpts = Object.assign({}, prog, { android: path.join(projPath, prog.android), - ios: path.join(projPath, prog.ios) + ios: path.join(projPath, prog.ios), }); const targets = [].concat(programOpts.target, env.target).filter(Boolean); @@ -154,24 +154,24 @@ function version(program, projectPath) { if (err.message === "Cannot find module 'react-native'") { log({ style: "red", - text: `Is this the right folder? ${err.message} in ${projPath}` + text: `Is this the right folder? ${err.message} in ${projPath}`, }); } else { log({ style: "red", - text: err.message + text: err.message, }); log({ style: "red", text: - "Is this the right folder? Looks like there isn't a package.json here" + "Is this the right folder? Looks like there isn't a package.json here", }); } log({ style: "yellow", - text: "Pass the project path as an argument, see --help for usage" + text: "Pass the project path as an argument, see --help for usage", }); if (program.outputHelp) { @@ -185,6 +185,7 @@ function version(program, projectPath) { const appJSONPath = path.join(projPath, "app.json"); const isExpoApp = isExpoProject(projPath); const isBareExpoWorkflow = programOpts.isBareExpoWorkflow; + const isSelfHostingBundles = programOpts.isSelfHostingBundles; isExpoApp && log({ text: "Expo detected" }, programOpts.quiet); @@ -194,8 +195,8 @@ function version(program, projectPath) { if (isExpoApp && !programOpts.incrementBuild) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { - version: appPkg.version - }) + version: appPkg.version, + }), }); } } catch (err) {} @@ -215,14 +216,15 @@ function version(program, projectPath) { reject([ { style: "red", - text: "No gradle file found at " + programOpts.android + text: "No gradle file found at " + programOpts.android, }, { style: "yellow", - text: 'Use the "--android" option to specify the path manually' - } + text: 'Use the "--android" option to specify the path manually', + }, ]); } + if ((!programOpts.incrementBuild && !isExpoApp) || isBareExpoWorkflow) { gradleFile = gradleFile.replace( /versionName (["'])(.*)["']/, @@ -231,19 +233,19 @@ function version(program, projectPath) { } if (!programOpts.neverIncrementBuild) { - const versionCode = parseInt( - dottie.get(appJSON, "expo.android.versionCode") - ); - const newVersionCode = getNewVersionCode( - programOpts, - versionCode, - appPkg.version - ); - appJSON = Object.assign({}, appJSON, { - expo: Object.assign({}, appJSON.expo, { - android: Object.assign({}, appJSON.expo.android, { - versionCode: newVersionCode - }) + if (isExpoApp) { + const versionCode = dottie.get(appJSON, "expo.android.versionCode"); + + appJSON = Object.assign({}, appJSON, { + expo: Object.assign({}, appJSON.expo, { + android: Object.assign({}, appJSON.expo.android, { + versionCode: getNewVersionCode( + programOpts, + versionCode, + appPkg.version + ), + }), + }), }); } else { gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( @@ -256,12 +258,9 @@ function version(program, projectPath) { appPkg.version ); - gradleFile = gradleFile.replace(/versionCode (\d+)/, function( - match, - cg1 - ) { - return "versionCode " + newVersionCode; - }); + return "versionCode " + newVersionCodeNumber; + }); + } } if (isBareExpoWorkflow) { @@ -277,11 +276,10 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { android: Object.assign({}, appJSON.expo.android, { - versionCode: newVersionCode - }) - }) + versionCode: newVersionCode, + }), + }), }); - gradleFile = gradleFile.replace(/versionCode (\d+)/, function ( match, cg1 @@ -320,12 +318,12 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: newBuildVersion - }) - }) + buildNumber: newBuildVersion, + }), + }), }); - if (appJSON.expo.hooks) { + if (isSelfHostingBundles && appJSON.expo.hooks) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { hooks: Object.assign({}, appJSON.expo.hooks, { @@ -339,18 +337,19 @@ function version(program, projectPath) { config: Object.assign({}, hook.config, { release: appJSON.expo.ios.bundleIdentifier + + "@" + appPkg.version + "+" + newBuildVersion, - distribution: newBuildVersion - }) + distribution: newBuildVersion, + }), }; } else { return hook; } - }) - }) - }) + }), + }), + }), }); } } @@ -369,37 +368,37 @@ function version(program, projectPath) { appJSON = Object.assign({}, appJSON, { expo: Object.assign({}, appJSON.expo, { ios: Object.assign({}, appJSON.expo.ios, { - buildNumber: newBuildVersion - }) - }) + buildNumber: newBuildVersion, + }), + }), }); fs.writeFileSync(appJSONPath, JSON.stringify(appJSON, null, 2)); } } else if (program.legacy) { try { child.execSync("xcode-select --print-path", { - stdio: ["ignore", "ignore", "pipe"] + stdio: ["ignore", "ignore", "pipe"], }); } catch (err) { reject([ { style: "red", - text: err + text: err, }, { style: "yellow", - text: "Looks like Xcode Command Line Tools aren't installed" + text: "Looks like Xcode Command Line Tools aren't installed", }, { - text: "\n Install:\n\n $ xcode-select --install\n" - } + text: "\n Install:\n\n $ xcode-select --install\n", + }, ]); return; } const agvtoolOpts = { - cwd: programOpts.ios + cwd: programOpts.ios, }; try { @@ -412,18 +411,18 @@ function version(program, projectPath) { ? [ { style: "red", - text: "No project folder found at " + programOpts.ios + text: "No project folder found at " + programOpts.ios, }, { style: "yellow", - text: 'Use the "--ios" option to specify the path manually' - } + text: 'Use the "--ios" option to specify the path manually', + }, ] : [ { style: "red", - text: stdout - } + text: stdout, + }, ] ); @@ -479,7 +478,6 @@ function version(program, projectPath) { target.buildConfigurationsList.buildConfigurations.forEach( (config) => { if (target.name === appPkg.name) { - console.log(target.name, appPkg.name); const CURRENT_PROJECT_VERSION = getNewVersionCode( programOpts, parseInt( @@ -494,8 +492,8 @@ function version(program, projectPath) { config.patch({ buildSettings: { - CURRENT_PROJECT_VERSION - } + CURRENT_PROJECT_VERSION, + }, }); } } @@ -524,7 +522,7 @@ function version(program, projectPath) { ? { CFBundleShortVersionString: getCFBundleShortVersionString( appPkg.version - ) + ), } : {}, !programOpts.neverIncrementBuild @@ -534,7 +532,7 @@ function version(program, projectPath) { parseInt(json.CFBundleVersion, 10), appPkg.version, programOpts.resetBuild - ).toString() + ).toString(), } : {} ) @@ -618,7 +616,7 @@ function version(program, projectPath) { } const gitCmdOpts = { - cwd: projPath + cwd: projPath, }; if ( @@ -651,11 +649,13 @@ function version(program, projectPath) { case "version": child.spawnSync( "git", - ["add"].concat([ - appJSONPath, - programOpts.android, - programOpts.ios - ]), + ["add"].concat( + isBareExpoWorkflow + ? [appJSONPath, programOpts.android, programOpts.ios] + : isExpoApp + ? appJSONPath + : [programOpts.android, programOpts.ios] + ), gitCmdOpts ); @@ -679,7 +679,7 @@ function version(program, projectPath) { log( { style: "green", - text: "Done" + text: "Done", }, programOpts.quiet ); @@ -697,7 +697,7 @@ function version(program, projectPath) { log({ style: "red", - text: "Done, with errors." + text: "Done, with errors.", }); process.exit(1); @@ -709,5 +709,5 @@ module.exports = { getDefaults: getDefaults, getPlistFilenames: getPlistFilenames, isExpoProject: isExpoProject, - version: version + version: version, };