Skip to content

Adding skip flags for package/android/ios #43

@bartaxyz

Description

@bartaxyz

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch react-native-set-version@1.1.2 for the project I'm working on.

For my project, I wanted to skip specific version updates.

Here is the diff that adds support for flags like --skip-package-json, --skip-android & --skip-ios. These flags add support for skipping certain environment version updates.

diff --git a/node_modules/react-native-set-version/src/index.js b/node_modules/react-native-set-version/src/index.js
index 3e6a27d..07bd2c8 100755
--- a/node_modules/react-native-set-version/src/index.js
+++ b/node_modules/react-native-set-version/src/index.js
@@ -17,14 +17,17 @@ const paths = {
   packageJson: './package.json',
 };
 
-function setPackageVersion(versionText) {
+function setPackageVersion(versionText, skipPackageVersion = false) {
   let packageJSON = null;
   try {
     packageJSON = JSON.parse(fs.readFileSync(paths.packageJson));
-    display(chalk.yellow(`Will set package version to ${chalk.bold.underline(versionText)}`));
-    packageJSON.version = versionText;
-    fs.writeFileSync(paths.packageJson, `${JSON.stringify(packageJSON, null, '\t')}\n`);
-    display(chalk.green(`Version replaced in ${chalk.bold('package.json')}`));
+    
+    if (!skipPackageVersion) {
+      display(chalk.yellow(`Will set package version to ${chalk.bold.underline(versionText)}`));
+      packageJSON.version = versionText;
+      fs.writeFileSync(paths.packageJson, `${JSON.stringify(packageJSON, null, '\t')}\n`);
+      display(chalk.green(`Version replaced in ${chalk.bold('package.json')}`));
+    }
   } catch (err) {
     display(chalk.red(`${chalk.bold.underline('ERROR:')} Cannot find file with name ${path.resolve(paths.packageJson)}`));
     process.exit(1);
@@ -147,11 +150,16 @@ async function setAndroidApplicationVersion(versionText) {
 
 const changeVersion = async () => {
   const versionText = process.argv[2];
-  const appName = setPackageVersion(versionText).name;
+  const skipPackageVersion = process.argv.includes('--skip-package-json');
+  const skipAndroidVersion = process.argv.includes('--skip-android');
+  const skipIosVersion = process.argv.includes('--skip-ios');
+
+  const appName = setPackageVersion(versionText, skipPackageVersion).name;
 
   paths.infoPlist = paths.infoPlist.replace('<APP_NAME>', appName);
-  await setAndroidApplicationVersion(versionText);
-  await setIosApplicationVersion(versionText);
+
+  if (!skipAndroidVersion) await setAndroidApplicationVersion(versionText);
+  if (!skipIosVersion) await setIosApplicationVersion(versionText);
 
   display('');
 };

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions