forked from expo-community/standard-version-expo
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds app version and build number bumpers for the native iOS/Android project configuration files (e.g. Info.plist, build.gradle). These are usable by expo bare workflow projects, but also react-native projects that don't use Expo, and even plain old iOS/Androd projects. Closes expo-community#9.
- Loading branch information
Showing
30 changed files
with
756 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/android-app-version'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/android-code'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/android-increment'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/android-code'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/ios-app-version'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/ios-code'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/ios-increment'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/ios-version'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('../../build/bumpers/native/buildnum/ios-version'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { androidAppVersionReader, androidAppVersionWriter } from './helpers'; | ||
|
||
/** | ||
* Read the app version from the `versionName` build.gradle property. | ||
*/ | ||
export const readVersion = androidAppVersionReader; | ||
|
||
/** | ||
* Write the app version to the `versionName` build.gradle property. | ||
*/ | ||
export const writeVersion = androidAppVersionWriter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { androidBuildnumReader, androidBuildnumWriter } from '../helpers'; | ||
import { getVersionCodeFromSdkVersion } from '../../../versions'; | ||
|
||
/** | ||
* Since a standard-version bumper only receives the contents of a single file, | ||
* we add a layer of indirection here and ask the user to supply the sdkVersion | ||
* directly. Note that they can choose to pull this from app.json, or even supply | ||
* the Android min SDK version if they're not using Expo. | ||
* | ||
* Configuration example in .versionrc.js: | ||
* | ||
* const sdkVersion = '37.0.0'; // or pull from app.json | ||
* module.exports = [ | ||
* ... | ||
* { | ||
* filename: 'android/app/build.gradle', | ||
* updater: require.resolve('standard-version-expo/android/native/code')(sdkVersion), | ||
* }, | ||
* ... | ||
* ]; | ||
* | ||
* This does add the requirement that they use .versionrc.js, not the other formats. | ||
*/ | ||
export default (sdkVersion: string) => ({ | ||
/** | ||
* Read the build code from the `versionCode` property. | ||
*/ | ||
readVersion: androidBuildnumReader, | ||
|
||
/** | ||
* Write the manifest version to the `versionCode` property. | ||
* This uses the Android version code approach of Maxi Rosson. | ||
* | ||
* @see https://medium.com/@maxirosson/versioning-android-apps-d6ec171cfd82 | ||
*/ | ||
writeVersion: (contents: string, version: string) => androidBuildnumWriter( | ||
contents, | ||
String( | ||
getVersionCodeFromSdkVersion(sdkVersion, version), | ||
), | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { androidBuildnumReader, androidBuildnumWriter } from '../helpers'; | ||
import { VersionWriter } from '../../../types'; | ||
|
||
/** | ||
* Read the buildnum stored at versionCode in the build.gradle. | ||
*/ | ||
export const readVersion = androidBuildnumReader; | ||
|
||
/** | ||
* Increment the buildnum stored at versionCode in the build.gradle. | ||
* This ignores the provided version. | ||
*/ | ||
export const writeVersion: VersionWriter = (contents, _version) => { | ||
const buildNumStr = androidBuildnumReader(contents); | ||
const buildNumber = buildNumStr != '' | ||
? Number(buildNumStr) | ||
: 0; | ||
|
||
if (Number.isNaN(buildNumber)) { | ||
throw new Error('Could not parse number from `versionCode`.'); | ||
} | ||
|
||
return androidBuildnumWriter(contents, String(buildNumber + 1)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { iosBuildnumReader, iosBuildnumWriter } from '../helpers'; | ||
import { getVersionCodeFromSdkVersion } from '../../../versions'; | ||
|
||
/** | ||
* Since a standard-version bumper only receives the contents of a single file, | ||
* we add a layer of indirection here and ask the user to supply the sdkVersion | ||
* directly. Note that they can choose to pull this from app.json, or even supply | ||
* the Android min SDK version if they're not using Expo. | ||
* | ||
* Configuration example in .versionrc.js: | ||
* | ||
* const sdkVersion = '37.0.0'; // or pull from app.json | ||
* module.exports = [ | ||
* ... | ||
* { | ||
* filename: 'ios/MyApp/Info.plist', | ||
* updater: require.resolve('standard-version-expo/ios/native/code')(sdkVersion), | ||
* }, | ||
* ... | ||
* ]; | ||
* | ||
* This does add the requirement that they use .versionrc.js, not the other formats. | ||
*/ | ||
export default (sdkVersion: string) => ({ | ||
/** | ||
* Read the build code from the `CFBundleVersion` property. | ||
*/ | ||
readVersion: iosBuildnumReader, | ||
|
||
/** | ||
* Write the manifest version to the `CFBundleVersion` property. | ||
* This uses the Android version code approach of Maxi Rosson. | ||
* | ||
* @see https://medium.com/@maxirosson/versioning-android-apps-d6ec171cfd82 | ||
*/ | ||
writeVersion: (contents: string, version: string) => iosBuildnumWriter( | ||
contents, | ||
String( | ||
getVersionCodeFromSdkVersion(sdkVersion, version), | ||
), | ||
), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { iosBuildnumReader, iosBuildnumWriter } from '../helpers'; | ||
import { VersionWriter } from '../../../types'; | ||
|
||
/** | ||
* Read the buildnum stored at CFBundleVersion in the Info.plist. | ||
*/ | ||
export const readVersion = iosBuildnumReader; | ||
|
||
/** | ||
* Increment the buildnum stored at CFBundleVersion in the Info.plist. | ||
* This ignores the provided version. | ||
*/ | ||
export const writeVersion: VersionWriter = (contents, _version) => { | ||
const buildNumStr = iosBuildnumReader(contents); | ||
const buildNumber = buildNumStr != '' | ||
? Number(buildNumStr) | ||
: 0; | ||
|
||
if (Number.isNaN(buildNumber)) { | ||
throw new Error('Could not parse number from `CFBundleVersion`.'); | ||
} | ||
|
||
return iosBuildnumWriter(contents, String(buildNumber + 1)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { iosBuildnumReader, iosBuildnumWriter } from '../helpers'; | ||
|
||
/** | ||
* Read the build version stored at CFBundleVersion in the Info.plist. | ||
*/ | ||
export const readVersion = iosBuildnumReader; | ||
|
||
/** | ||
* Write the manifest version at CFBundleVersion in the Info.plist. | ||
*/ | ||
export const writeVersion = iosBuildnumWriter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import os from 'os'; | ||
|
||
import plist, { PlistObject } from 'plist'; | ||
|
||
import { VersionReader, VersionWriter } from '../../types'; | ||
|
||
const androidAppVersionRegex = /^(.+versionName +["']?)([^"']+)(["']?.*)$/; | ||
const androidBuildnumRegex = /^(.+versionCode +["']?)([0-9]+)(["']?.*)$/; | ||
|
||
const replaceMatchingLines = (contents: string, rx: RegExp, version: string): string => { | ||
// it's a PITA to make sure we insert it in the right place, | ||
// and it's always there in the generated android project, | ||
// so if we don't find it, throw an error. | ||
if (!findMatchingLine(contents, rx)) { | ||
let field; | ||
if (rx === androidAppVersionRegex) { | ||
field = 'versionName'; | ||
} else if (rx === androidBuildnumRegex) { | ||
field = 'versionCode'; | ||
} else { | ||
throw new Error('NOTREACHED'); | ||
} | ||
throw new Error(`Could not find ${field} in build.gradle`) | ||
} | ||
|
||
return contents.split(os.EOL) | ||
.map(line => line.replace(rx, `$1${version}$3`)) | ||
.join(os.EOL) | ||
}; | ||
|
||
const findMatchingLine = (contents: string, rx: RegExp): string => { | ||
for (const line of contents.split(os.EOL)) { | ||
const match = line.match(rx); | ||
if (match) { | ||
return match[2]; | ||
} | ||
} | ||
return ''; | ||
} | ||
|
||
/** | ||
* The default android app version reader. | ||
* It reads the value from `android/app/build.gradle` and returns it as string. | ||
*/ | ||
export const androidAppVersionReader: VersionReader = (contents) => ( | ||
findMatchingLine(contents, androidAppVersionRegex) | ||
); | ||
|
||
/** | ||
* The default android buildnum reader. | ||
* It reads the value from `android/app/build.gradle` and returns it as string. | ||
*/ | ||
export const androidBuildnumReader: VersionReader = (contents) => ( | ||
findMatchingLine(contents, androidBuildnumRegex) | ||
); | ||
|
||
|
||
/** | ||
* The default android app version writer. | ||
* It replaces the value in the `android/app/build.gradle` contents and | ||
* returns the new contents as string. | ||
*/ | ||
export const androidAppVersionWriter: VersionWriter = (contents, version) => ( | ||
replaceMatchingLines(contents, androidAppVersionRegex, version) | ||
); | ||
|
||
/** | ||
* The default android buildnum writer. | ||
* It replaces the value in the `android/app/build.gradle` contents and | ||
* returns the new contents as string. | ||
*/ | ||
export const androidBuildnumWriter: VersionWriter = (contents, version) => ( | ||
replaceMatchingLines(contents, androidBuildnumRegex, version) | ||
); | ||
|
||
const iosReadVersion = (contents: string, key: string): string => ( | ||
(plist.parse(contents) as PlistObject)[key] as string || '' | ||
) | ||
|
||
/** | ||
* The default ios app version reader. | ||
* It reads the value from `Info.plist` and returns it as string. | ||
*/ | ||
export const iosAppVersionReader: VersionReader = (contents) => ( | ||
iosReadVersion(contents, 'CFBundleShortVersionString') | ||
); | ||
|
||
/** | ||
* The default ios buildnum reader. | ||
* It reads the value from `Info.plist` and returns it as string. | ||
*/ | ||
export const iosBuildnumReader: VersionReader = (contents) => ( | ||
iosReadVersion(contents, 'CFBundleVersion') | ||
); | ||
|
||
const iosWriteVersion = (contents: string, key: string, value: string): string => ( | ||
plist.build({ | ||
...(plist.parse(contents) as PlistObject), | ||
[key]: value, | ||
}) | ||
) | ||
|
||
/** | ||
* The default ios app version writer. | ||
* It replaces the value in the `Info.plist` contents and returns the new contents as string. | ||
*/ | ||
export const iosAppVersionWriter: VersionWriter = (contents, version) => ( | ||
iosWriteVersion(contents, 'CFBundleShortVersionString', version) | ||
); | ||
|
||
/** | ||
* The default ios buildnum writer. | ||
* It replaces the value in the `Info.plist` contents and returns the new contents as string. | ||
*/ | ||
export const iosBuildnumWriter: VersionWriter = (contents, version) => ( | ||
iosWriteVersion(contents, 'CFBundleVersion', version) | ||
); |
Oops, something went wrong.