stovmascript / react-native-version

:1234: Version your React Native or Expo app in a `npm version` fashion.
MIT License
576 stars 75 forks source link

Add --skip-expo option to skip Expo versioning even if detected #325

Open sregg opened 1 year ago

sregg commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

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

We have a vanilla React Native app that uses expo-updates. We don't need to update app.json but we do need to update the native files (i.e. Info.plist and build.gradle). I added a new option --skip-expo to manually skip expo versioning even if detected.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-version/README.md b/node_modules/react-native-version/README.md
index 1f3aa85..21ce3ff 100644
--- a/node_modules/react-native-version/README.md
+++ b/node_modules/react-native-version/README.md
@@ -72,6 +72,7 @@ $ react-native-version
     -s, --set-build <number>     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 <platforms>     Only version specified platforms, e.g. "--target android,ios".
+    -e, --skip-expo              Skip Expo versioning even if detected.
     -h, --help                   output usage information

 <!-- END cli -->
diff --git a/node_modules/react-native-version/cli.js b/node_modules/react-native-version/cli.js
index 15f4c32..678d5b5 100755
--- a/node_modules/react-native-version/cli.js
+++ b/node_modules/react-native-version/cli.js
@@ -53,6 +53,7 @@ program
        'Only version specified platforms, e.g. "--target android,ios".',
        list
    )
+   .option("-e, --skip-expo", "Skip Expo versioning even if detected.")
    .parse(process.argv);

 rnv.version(program);
diff --git a/node_modules/react-native-version/index.js b/node_modules/react-native-version/index.js
index 345f3d4..de5e692 100644
--- a/node_modules/react-native-version/index.js
+++ b/node_modules/react-native-version/index.js
@@ -114,12 +114,12 @@ function getCFBundleShortVersionString(versionName) {
  * @private
  * @return {Boolean} true if the project is an Expo app
  */
-function isExpoProject(projPath) {
+function isExpoProject(projPath, programOpts) {
    try {
        let module = resolveFrom(projPath, "expo");
        let appInfo = require(`${projPath}/app.json`);

-       return !!(module && appInfo.expo);
+       return !!(!programOpts.skipExpo && module && appInfo.expo);
    } catch (err) {
        return false;
    }
@@ -183,7 +183,7 @@ function version(program, projectPath) {

    var appJSON;
    const appJSONPath = path.join(projPath, "app.json");
-   const isExpoApp = isExpoProject(projPath);
+   const isExpoApp = isExpoProject(projPath, programOpts);

    isExpoApp && log({ text: "Expo detected" }, programOpts.quiet);

This issue body was partially generated by patch-package.

geolffreym commented 8 months ago

Great! Definitely we need this feature too!

omniboyOK commented 1 month ago

Same, this would be very useful for us too.