diff --git a/README.md b/README.md index 22e3f34..3bd6290 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,66 @@ -Nativescript hook plugin to maintain native app version -======================================================= +# Nativescript hook plugin to maintain native app version -This plugin just takes the `nativescript.version` property from `package.json` and puts on the specific platform resources: `AndroidManifest.xml` file for the Android sources, and `Info.plist` for iOS sources. +This plugin takes the `version` and `versionNumber` properties from `package.json` and puts on the specific platform resources: `AndroidManifest.xml` file for the Android sources, and `Info.plist` for iOS sources. + +This plugin is mainly a fork of [jacargentina/nativescript-dev-version](https://github.com/jacargentina/nativescript-dev-version), with the great ideas from [speigg/nativescript-dev-version](https://github.com/speigg/nativescript-dev-version/tree/patch-1) and [simplec-dev/nativescript-dev-version](https://github.com/simplec-dev/nativescript-dev-version). + +Compatible with NS 6. + +## How to use -How to use ----------- ``` $ tns plugin add nativescript-dev-version ``` The above command installs this module and installs the necessary NativeScript hooks. -Then, specify and maintain the desired release version on the `package.json` file under the `nativescript.version` property, for example: +Then, specify and maintain the desired release version on the `./package.json` file under the `nativescript.version` property, for example: ```json { "nativescript": { "id": "org.nativescript.MySampleApp", - "version": "1.2.3" + "version": "1.2.3", + "versionNumber": "1" ... }, ... } ``` -When running `tns prepare ...` the hooks will take care of the native resources, and your app will get the `1.2.3` version number! +or: + +```json +{ + "version": "1.2.3", + "versionNumber": "1" + ... +} +``` + +When running `tns prepare ...` the hooks will take care of the native resources. + +> **Warning** +> Remove/comment the lines in your `App_Resources/Android/app.gradle`: +> ``` +> // Version Information +> // versionCode 1 +> // versionName "1.0.0" +> ``` + +On iOS, your `Info.plist` will get: + +``` +CFBundleShortVersionString +1.2.3 +CFBundleVersion +1 +``` + +On Android, `AndroidManifest.xml` will have: + +``` + acc + v * Math.pow(10, (a.length - i - 1) * 2), + 0 + ); + + if (appVersionNumber) { + versionCode = + versionCode * 100 + + (appVersionNumber < 10 ? '0' : '') + // left pad appVersionNumber + appVersionNumber; + } + + manifest.$('manifest').attr('android:versionCode', versionCode); + manifest.$('manifest').attr('android:versionName', appVersion); + manifest.writeFile(platformData.configurationFilePath); + $logger.info(`Updated android:versionCode: ${versionCode}, android:versionName: ${appVersion}`); + } else if (platform == 'ios') { + var plist = iOSPList.parse( + fs.readFileSync(platformData.configurationFilePath, 'utf8') + ); + plist.CFBundleShortVersionString = appVersion; + plist.CFBundleVersion = appVersionNumber; + fs.writeFileSync(platformData.configurationFilePath, iOSPList.build(plist)); + $logger.info(`Updated CFBundleShortVersionString: ${appVersion}, CFBundleVersion: ${appVersionNumber}`); + } +}; + +function getPlatformsData($injector) { + try { + return $injector.resolve('platformsData'); + } catch (err) { + return $injector.resolve('platformsDataService'); + } +} diff --git a/package.json b/package.json index cfed91a..652ee7a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-version", - "version": "0.1.1", + "version": "0.2.1", "description": "Installs nativescript hooks to maintain native app version (AndroidManifest.xml and Info.plist)'", "main": "index.js", "scripts": { @@ -20,9 +20,8 @@ ] }, "dependencies": { + "@nativescript/hook": "~2.0.0", "androidmanifest": "^2.0.0", - "bluebird": "^3.4.7", - "nativescript-hook": "^0.2.1", "plist": "^2.0.1" } } diff --git a/postinstall.js b/postinstall.js index 12a6403..f55236d 100644 --- a/postinstall.js +++ b/postinstall.js @@ -1 +1 @@ -require('nativescript-hook')(__dirname).postinstall(); \ No newline at end of file +require('@nativescript/hook')(__dirname).postinstall(); \ No newline at end of file diff --git a/preuninstall.js b/preuninstall.js index b72ac69..3c292e1 100644 --- a/preuninstall.js +++ b/preuninstall.js @@ -1 +1 @@ -require('nativescript-hook')(__dirname).preuninstall(); +require('@nativescript/hook')(__dirname).preuninstall();