Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding skip flags for package/android/ios #43

Open
bartaxyz opened this issue Jan 27, 2023 · 0 comments
Open

Adding skip flags for package/android/ios #43

bartaxyz opened this issue Jan 27, 2023 · 0 comments

Comments

@bartaxyz
Copy link

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant