@bravemobile/react-native-code-push 8.3.1 → 9.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CodePush.js +107 -136
- package/README.md +0 -5
- package/babel.config.js +3 -0
- package/cli/commands/bundleCommand/bundleCodePush.js +49 -0
- package/cli/commands/bundleCommand/index.js +25 -0
- package/cli/commands/createHistoryCommand/createReleaseHistory.js +53 -0
- package/cli/commands/createHistoryCommand/index.js +28 -0
- package/cli/commands/releaseCommand/addToReleaseHistory.js +75 -0
- package/cli/commands/releaseCommand/index.js +61 -0
- package/cli/commands/releaseCommand/release.js +88 -0
- package/cli/commands/showHistoryCommand/index.js +28 -0
- package/cli/commands/updateHistoryCommand/index.js +49 -0
- package/cli/commands/updateHistoryCommand/updateReleaseHistory.js +62 -0
- package/cli/constant.js +3 -0
- package/cli/functions/getReactTempDir.js +16 -0
- package/cli/functions/makeCodePushBundle.js +27 -0
- package/cli/functions/prepareToBundleJS.js +12 -0
- package/cli/functions/runHermesEmitBinaryCommand.js +213 -0
- package/cli/functions/runReactNativeBundleCommand.js +59 -0
- package/cli/index.js +43 -0
- package/cli/utils/file-utils.js +42 -0
- package/cli/utils/fsUtils.js +49 -0
- package/cli/utils/hash-utils.js +227 -0
- package/cli/utils/promisfied-fs.js +29 -0
- package/cli/utils/showLogo.js +23 -0
- package/cli/utils/zip.js +89 -0
- package/code-push.config.example.supabase.ts +114 -0
- package/docs/setup-android.md +3 -11
- package/eslint.config.mjs +32 -0
- package/package-mixins.js +1 -8
- package/package.json +26 -23
- package/react-native.config.js +3 -1
- package/typings/react-native-code-push.d.ts +91 -16
- package/versioning/BaseVersioning.js +126 -0
- package/versioning/BaseVersioning.test.js +15 -0
- package/versioning/IncrementalVersioning.js +9 -0
- package/versioning/IncrementalVersioning.test.js +186 -0
- package/versioning/SemverVersioning.js +10 -0
- package/versioning/SemverVersioning.test.js +205 -0
- package/versioning/index.js +7 -0
- package/.azurepipelines/build-rn-code-push-1es.yml +0 -104
- package/.azurepipelines/test-rn-code-push.yml +0 -94
- package/.config/CredScanSuppressions.json +0 -14
- package/docs/setup-windows.md +0 -121
- package/request-fetch-adapter.js +0 -52
- package/scripts/postlink/android/postlink.js +0 -87
- package/scripts/postlink/ios/postlink.js +0 -116
- package/scripts/postlink/run.js +0 -11
- package/scripts/postunlink/android/postunlink.js +0 -74
- package/scripts/postunlink/ios/postunlink.js +0 -87
- package/scripts/postunlink/run.js +0 -11
- package/scripts/tools/linkToolsAndroid.js +0 -57
- package/scripts/tools/linkToolsIos.js +0 -130
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const { program, Option } = require("commander");
|
|
2
|
+
const SemVer = require('semver');
|
|
3
|
+
const { findAndReadConfigFile } = require("../../utils/fsUtils");
|
|
4
|
+
const { release } = require("./release");
|
|
5
|
+
|
|
6
|
+
program.command('release')
|
|
7
|
+
.description('Deploys a new CodePush update for a target binary app.\nAfter creating the CodePush bundle, it uploads the file and updates the ReleaseHistory information.\n`bundleUploader`, `getReleaseHistory`, and `setReleaseHistory` functions should be implemented in the config file.')
|
|
8
|
+
.requiredOption('-v, --app-version <string>', '(Required) The app version to be released. It must be greater than the binary version.')
|
|
9
|
+
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
|
|
10
|
+
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
|
|
11
|
+
.option('-c, --config <path>', 'set config file name (JS/TS)', 'code-push.config.ts')
|
|
12
|
+
.option('-o, --output-path <string>', 'path to output root directory', 'build')
|
|
13
|
+
.option('-e, --entry-file <string>', 'path to JS/TS entry file', 'index.ts')
|
|
14
|
+
.option('-j, --js-bundle-name <string>', 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
|
|
15
|
+
.option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, false)
|
|
16
|
+
.option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
|
|
17
|
+
/**
|
|
18
|
+
* @param {Object} options
|
|
19
|
+
* @param {string} options.binaryVersion
|
|
20
|
+
* @param {string} options.appVersion
|
|
21
|
+
* @param {string} options.platform
|
|
22
|
+
* @param {string} options.identifier
|
|
23
|
+
* @param {string} options.config
|
|
24
|
+
* @param {string} options.outputPath
|
|
25
|
+
* @param {string} options.entryFile
|
|
26
|
+
* @param {string} options.bundleName
|
|
27
|
+
* @param {string} options.mandatory
|
|
28
|
+
* @param {string} options.enable
|
|
29
|
+
* @return {void}
|
|
30
|
+
*/
|
|
31
|
+
.action(async (options) => {
|
|
32
|
+
if (SemVer.lte(options.appVersion, options.binaryVersion)) {
|
|
33
|
+
console.error('The app version must be greater than the binary version.');
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const config = findAndReadConfigFile(process.cwd(), options.config);
|
|
38
|
+
|
|
39
|
+
await release(
|
|
40
|
+
config.bundleUploader,
|
|
41
|
+
config.getReleaseHistory,
|
|
42
|
+
config.setReleaseHistory,
|
|
43
|
+
options.binaryVersion,
|
|
44
|
+
options.appVersion,
|
|
45
|
+
options.platform,
|
|
46
|
+
options.identifier,
|
|
47
|
+
options.outputPath,
|
|
48
|
+
options.entryFile,
|
|
49
|
+
options.bundleName,
|
|
50
|
+
options.mandatory,
|
|
51
|
+
options.enable,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
console.log('🚀 Release completed.')
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
function parseBoolean(value) {
|
|
58
|
+
if (value === 'true') return true;
|
|
59
|
+
if (value === 'false') return false;
|
|
60
|
+
else return undefined;
|
|
61
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
const { bundleCodePush } = require("../bundleCommand/bundleCodePush");
|
|
2
|
+
const { addToReleaseHistory } = require("./addToReleaseHistory");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param bundleUploader {
|
|
6
|
+
* function(
|
|
7
|
+
* source: string,
|
|
8
|
+
* platform: "ios" | "android",
|
|
9
|
+
* identifier?: string
|
|
10
|
+
* ): Promise<{ downloadUrl: string }>}
|
|
11
|
+
* @param getReleaseHistory {
|
|
12
|
+
* function(
|
|
13
|
+
* targetBinaryVersion: string,
|
|
14
|
+
* platform: "ios" | "android",
|
|
15
|
+
* identifier?: string
|
|
16
|
+
* ): Promise<ReleaseHistoryInterface>}
|
|
17
|
+
* @param setReleaseHistory {
|
|
18
|
+
* function(
|
|
19
|
+
* targetBinaryVersion: string,
|
|
20
|
+
* jsonFilePath: string,
|
|
21
|
+
* releaseInfo: ReleaseHistoryInterface,
|
|
22
|
+
* platform: "ios" | "android",
|
|
23
|
+
* identifier?: string
|
|
24
|
+
* ): Promise<void>}
|
|
25
|
+
* @param binaryVersion {string}
|
|
26
|
+
* @param appVersion {string}
|
|
27
|
+
* @param platform {"ios" | "android"}
|
|
28
|
+
* @param identifier {string?}
|
|
29
|
+
* @param outputPath {string}
|
|
30
|
+
* @param entryFile {string}
|
|
31
|
+
* @param jsBundleName {string}
|
|
32
|
+
* @param mandatory {boolean}
|
|
33
|
+
* @param enable {boolean}
|
|
34
|
+
* @return {Promise<void>}
|
|
35
|
+
*/
|
|
36
|
+
async function release(
|
|
37
|
+
bundleUploader,
|
|
38
|
+
getReleaseHistory,
|
|
39
|
+
setReleaseHistory,
|
|
40
|
+
binaryVersion,
|
|
41
|
+
appVersion,
|
|
42
|
+
platform,
|
|
43
|
+
identifier,
|
|
44
|
+
outputPath,
|
|
45
|
+
entryFile,
|
|
46
|
+
jsBundleName,
|
|
47
|
+
mandatory,
|
|
48
|
+
enable,
|
|
49
|
+
) {
|
|
50
|
+
const { bundleFileName, packageHash } = await bundleCodePush(
|
|
51
|
+
platform,
|
|
52
|
+
outputPath,
|
|
53
|
+
entryFile,
|
|
54
|
+
jsBundleName,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
const downloadUrl = await (async () => {
|
|
58
|
+
try {
|
|
59
|
+
const { downloadUrl } = await bundleUploader(`./${bundleFileName}`, platform, identifier);
|
|
60
|
+
return downloadUrl
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Failed to upload the bundle file. Exiting the program.', error)
|
|
63
|
+
process.exit(1)
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
|
|
67
|
+
await addToReleaseHistory(
|
|
68
|
+
appVersion,
|
|
69
|
+
binaryVersion,
|
|
70
|
+
downloadUrl,
|
|
71
|
+
packageHash,
|
|
72
|
+
getReleaseHistory,
|
|
73
|
+
setReleaseHistory,
|
|
74
|
+
platform,
|
|
75
|
+
identifier,
|
|
76
|
+
mandatory,
|
|
77
|
+
enable,
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
deleteUploadedBundleFile(bundleFileName);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function deleteUploadedBundleFile(bundleFileName) {
|
|
84
|
+
const fs = require('fs');
|
|
85
|
+
fs.unlinkSync(`./${bundleFileName}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { release: release }
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { program, Option } = require("commander");
|
|
2
|
+
const { findAndReadConfigFile } = require("../../utils/fsUtils");
|
|
3
|
+
|
|
4
|
+
program.command('show-history')
|
|
5
|
+
.description('Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.')
|
|
6
|
+
.requiredOption('-b, --binary-version <string>', '(Required) The target binary version for retrieving the release history.')
|
|
7
|
+
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
|
|
8
|
+
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
|
|
9
|
+
.option('-c, --config <path>', 'configuration file name (JS/TS)', 'code-push.config.ts')
|
|
10
|
+
/**
|
|
11
|
+
* @param {Object} options
|
|
12
|
+
* @param {string} options.binaryVersion
|
|
13
|
+
* @param {string} options.platform
|
|
14
|
+
* @param {string} options.identifier
|
|
15
|
+
* @param {string} options.config
|
|
16
|
+
* @return {void}
|
|
17
|
+
*/
|
|
18
|
+
.action(async (options) => {
|
|
19
|
+
const config = findAndReadConfigFile(process.cwd(), options.config);
|
|
20
|
+
|
|
21
|
+
const releaseHistory = await config.getReleaseHistory(
|
|
22
|
+
options.binaryVersion,
|
|
23
|
+
options.platform,
|
|
24
|
+
options.identifier
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
console.log(JSON.stringify(releaseHistory, null, 2));
|
|
28
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const { program, Option } = require("commander");
|
|
2
|
+
const { findAndReadConfigFile } = require("../../utils/fsUtils");
|
|
3
|
+
const { updateReleaseHistory } = require("./updateReleaseHistory");
|
|
4
|
+
|
|
5
|
+
program.command('update-history')
|
|
6
|
+
.description('Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.')
|
|
7
|
+
.requiredOption('-v, --app-version <string>', '(Required) The app version for which update information is to be modified.')
|
|
8
|
+
.requiredOption('-b, --binary-version <string>', '(Required) The target binary version of the app for which update information is to be modified.')
|
|
9
|
+
.addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
|
|
10
|
+
.option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
|
|
11
|
+
.option('-c, --config <path>', 'set config file name (JS/TS)', 'code-push.config.ts')
|
|
12
|
+
.option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, undefined)
|
|
13
|
+
.option('-e, --enable <bool>', 'make the release to be enabled', parseBoolean, undefined)
|
|
14
|
+
/**
|
|
15
|
+
* @param {Object} options
|
|
16
|
+
* @param {string} options.appVersion
|
|
17
|
+
* @param {string} options.binaryVersion
|
|
18
|
+
* @param {string} options.platform
|
|
19
|
+
* @param {string} options.identifier
|
|
20
|
+
* @param {string} options.config
|
|
21
|
+
* @param {string} options.mandatory
|
|
22
|
+
* @param {string} options.enable
|
|
23
|
+
* @return {void}
|
|
24
|
+
*/
|
|
25
|
+
.action(async (options) => {
|
|
26
|
+
const config = findAndReadConfigFile(process.cwd(), options.config);
|
|
27
|
+
|
|
28
|
+
if (typeof options.mandatory !== "boolean" && typeof options.enable !== "boolean") {
|
|
29
|
+
console.error('No options specified. Exiting the program.')
|
|
30
|
+
process.exit(1)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
await updateReleaseHistory(
|
|
34
|
+
options.appVersion,
|
|
35
|
+
options.binaryVersion,
|
|
36
|
+
config.getReleaseHistory,
|
|
37
|
+
config.setReleaseHistory,
|
|
38
|
+
options.platform,
|
|
39
|
+
options.identifier,
|
|
40
|
+
options.mandatory,
|
|
41
|
+
options.enable,
|
|
42
|
+
)
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
function parseBoolean(value) {
|
|
46
|
+
if (value === 'true') return true;
|
|
47
|
+
if (value === 'false') return false;
|
|
48
|
+
else return undefined;
|
|
49
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param appVersion {string}
|
|
7
|
+
* @param binaryVersion {string}
|
|
8
|
+
* @param getReleaseHistory {
|
|
9
|
+
* function(
|
|
10
|
+
* targetBinaryVersion: string,
|
|
11
|
+
* platform: string,
|
|
12
|
+
* identifier?: string
|
|
13
|
+
* ): Promise<ReleaseHistoryInterface>}
|
|
14
|
+
* @param setReleaseHistory {
|
|
15
|
+
* function(
|
|
16
|
+
* targetBinaryVersion: string,
|
|
17
|
+
* jsonFilePath: string,
|
|
18
|
+
* releaseInfo: ReleaseHistoryInterface,
|
|
19
|
+
* platform: string,
|
|
20
|
+
* identifier?: string
|
|
21
|
+
* ): Promise<void>}
|
|
22
|
+
* @param platform {"ios" | "android"}
|
|
23
|
+
* @param identifier {string?}
|
|
24
|
+
* @param mandatory {boolean?}
|
|
25
|
+
* @param enable {boolean?}
|
|
26
|
+
* @returns {Promise<void>}
|
|
27
|
+
*/
|
|
28
|
+
async function updateReleaseHistory(
|
|
29
|
+
appVersion,
|
|
30
|
+
binaryVersion,
|
|
31
|
+
getReleaseHistory,
|
|
32
|
+
setReleaseHistory,
|
|
33
|
+
platform,
|
|
34
|
+
identifier,
|
|
35
|
+
mandatory,
|
|
36
|
+
enable,
|
|
37
|
+
) {
|
|
38
|
+
const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier);
|
|
39
|
+
|
|
40
|
+
const updateInfo = releaseHistory[appVersion]
|
|
41
|
+
if (!updateInfo) throw new Error(`v${appVersion} is not released`)
|
|
42
|
+
|
|
43
|
+
if (typeof mandatory === "boolean") updateInfo.mandatory = mandatory;
|
|
44
|
+
if (typeof enable === "boolean") updateInfo.enabled = enable;
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const JSON_FILE_NAME = `${binaryVersion}.json`;
|
|
48
|
+
const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
|
|
49
|
+
|
|
50
|
+
console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(releaseHistory, null, 2));
|
|
51
|
+
fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(releaseHistory));
|
|
52
|
+
|
|
53
|
+
await setReleaseHistory(binaryVersion, JSON_FILE_PATH, releaseHistory, platform, identifier)
|
|
54
|
+
|
|
55
|
+
fs.unlinkSync(JSON_FILE_PATH);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.error('Error occurred while updating history:', error);
|
|
58
|
+
process.exit(1)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = { updateReleaseHistory: updateReleaseHistory }
|
package/cli/constant.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code based on appcenter-cli
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const os = require('os');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Return the path of the temporary directory for react-native bundling
|
|
9
|
+
*
|
|
10
|
+
* @return {string}
|
|
11
|
+
*/
|
|
12
|
+
function getReactTempDir() {
|
|
13
|
+
return `${os.tmpdir()}/react-*`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = { getReactTempDir };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const { randomUUID } = require('crypto');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const shell = require('shelljs');
|
|
4
|
+
const zip = require('../utils/zip');
|
|
5
|
+
const {generatePackageHashFromDirectory} = require('../utils/hash-utils');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Create a CodePush bundle file and return the information.
|
|
9
|
+
*
|
|
10
|
+
* @param contentsPath {string} The directory path containing the contents to be made into a CodePush bundle (usually the 'build/CodePush' directory))
|
|
11
|
+
* @return {Promise<{ bundleFileName: string, packageHash: string }>}
|
|
12
|
+
*/
|
|
13
|
+
async function makeCodePushBundle(contentsPath) {
|
|
14
|
+
const updateContentsZipPath = await zip(contentsPath);
|
|
15
|
+
|
|
16
|
+
const bundleFileName = randomUUID();
|
|
17
|
+
shell.mv(updateContentsZipPath, `./${bundleFileName}`);
|
|
18
|
+
|
|
19
|
+
const packageHash = await generatePackageHashFromDirectory(contentsPath, path.join(contentsPath, '..'));
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
bundleFileName: bundleFileName,
|
|
23
|
+
packageHash: packageHash,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = { makeCodePushBundle };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const shell = require('shelljs');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param deleteDirs {string[]} Directories to delete
|
|
5
|
+
* @param makeDir {string} Directory path to create
|
|
6
|
+
*/
|
|
7
|
+
function prepareToBundleJS({ deleteDirs, makeDir }) {
|
|
8
|
+
shell.rm('-rf', deleteDirs);
|
|
9
|
+
shell.mkdir('-p', makeDir);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = { prepareToBundleJS };
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code based on appcenter-cli
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const childProcess = require('child_process');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const shell = require('shelljs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Run Hermes compile CLI command
|
|
12
|
+
*
|
|
13
|
+
* @param bundleName {string} JS bundle file name
|
|
14
|
+
* @param outputPath {string} Path to output .hbc file
|
|
15
|
+
* @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
|
|
16
|
+
* @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
|
|
17
|
+
* @return {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
async function runHermesEmitBinaryCommand(
|
|
20
|
+
bundleName,
|
|
21
|
+
outputPath,
|
|
22
|
+
sourcemapOutput,
|
|
23
|
+
extraHermesFlags = [],
|
|
24
|
+
) {
|
|
25
|
+
/**
|
|
26
|
+
* @type {string[]}
|
|
27
|
+
*/
|
|
28
|
+
const hermesArgs = [
|
|
29
|
+
'-emit-binary',
|
|
30
|
+
'-out',
|
|
31
|
+
path.join(outputPath, bundleName + '.hbc'),
|
|
32
|
+
path.join(outputPath, bundleName),
|
|
33
|
+
...extraHermesFlags,
|
|
34
|
+
];
|
|
35
|
+
if (sourcemapOutput) {
|
|
36
|
+
hermesArgs.push('-output-source-map');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log('Converting JS bundle to byte code via Hermes, running command:\n');
|
|
40
|
+
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
try {
|
|
43
|
+
const hermesCommand = getHermesCommand();
|
|
44
|
+
|
|
45
|
+
const disableAllWarningsArg = '-w';
|
|
46
|
+
shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
|
|
47
|
+
|
|
48
|
+
// Copy HBC bundle to overwrite JS bundle
|
|
49
|
+
const source = path.join(outputPath, bundleName + '.hbc');
|
|
50
|
+
const destination = path.join(outputPath, bundleName);
|
|
51
|
+
shell.cp(source, destination);
|
|
52
|
+
shell.rm(source);
|
|
53
|
+
resolve();
|
|
54
|
+
} catch (e) {
|
|
55
|
+
reject(e);
|
|
56
|
+
}
|
|
57
|
+
}).then(() => {
|
|
58
|
+
if (!sourcemapOutput) {
|
|
59
|
+
// skip source map compose if source map is not enabled
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// compose-source-maps.js file path
|
|
64
|
+
const composeSourceMapsPath = getComposeSourceMapsPath();
|
|
65
|
+
if (composeSourceMapsPath === null) {
|
|
66
|
+
throw new Error('react-native compose-source-maps.js scripts is not found');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const jsCompilerSourceMapFile = path.join(outputPath, bundleName + '.hbc' + '.map');
|
|
70
|
+
if (!fs.existsSync(jsCompilerSourceMapFile)) {
|
|
71
|
+
throw new Error(`sourcemap file ${jsCompilerSourceMapFile} is not found`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const composeSourceMapsArgs = [
|
|
76
|
+
composeSourceMapsPath,
|
|
77
|
+
sourcemapOutput,
|
|
78
|
+
jsCompilerSourceMapFile,
|
|
79
|
+
'-o',
|
|
80
|
+
sourcemapOutput,
|
|
81
|
+
];
|
|
82
|
+
const composeSourceMapsProcess = childProcess.spawn('node', composeSourceMapsArgs);
|
|
83
|
+
console.log(`${composeSourceMapsPath} ${composeSourceMapsArgs.join(' ')}`);
|
|
84
|
+
|
|
85
|
+
composeSourceMapsProcess.stdout.on('data', (data) => {
|
|
86
|
+
console.log(data.toString().trim());
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
composeSourceMapsProcess.stderr.on('data', (data) => {
|
|
90
|
+
console.error(data.toString().trim());
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
composeSourceMapsProcess.on('close', (exitCode, signal) => {
|
|
94
|
+
if (exitCode !== 0) {
|
|
95
|
+
reject(new Error(`"compose-source-maps" command failed (exitCode=${exitCode}, signal=${signal}).`));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Delete the HBC sourceMap, otherwise it will be included in 'code-push' bundle as well
|
|
99
|
+
fs.unlink(jsCompilerSourceMapFile, (err) => {
|
|
100
|
+
if (err != null) {
|
|
101
|
+
console.error(err);
|
|
102
|
+
reject(err);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
resolve();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @return {string}
|
|
114
|
+
*/
|
|
115
|
+
function getHermesCommand() {
|
|
116
|
+
/**
|
|
117
|
+
* @type {(file: string) => boolean}
|
|
118
|
+
*/
|
|
119
|
+
const fileExists = (file) => {
|
|
120
|
+
try {
|
|
121
|
+
return fs.statSync(file).isFile();
|
|
122
|
+
} catch (e) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
// Hermes is bundled with react-native since 0.69
|
|
127
|
+
const bundledHermesEngine = path.join(
|
|
128
|
+
getReactNativePackagePath(),
|
|
129
|
+
'sdks',
|
|
130
|
+
'hermesc',
|
|
131
|
+
getHermesOSBin(),
|
|
132
|
+
getHermesOSExe(),
|
|
133
|
+
);
|
|
134
|
+
if (fileExists(bundledHermesEngine)) {
|
|
135
|
+
return bundledHermesEngine;
|
|
136
|
+
}
|
|
137
|
+
throw new Error('Hermes engine binary not found. Please upgrade to react-native 0.69 or later');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @return {string}
|
|
142
|
+
*/
|
|
143
|
+
function getHermesOSBin() {
|
|
144
|
+
switch (process.platform) {
|
|
145
|
+
case 'win32':
|
|
146
|
+
return 'win64-bin';
|
|
147
|
+
case 'darwin':
|
|
148
|
+
return 'osx-bin';
|
|
149
|
+
case 'freebsd':
|
|
150
|
+
case 'linux':
|
|
151
|
+
case 'sunos':
|
|
152
|
+
default:
|
|
153
|
+
return 'linux64-bin';
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @return {string}
|
|
159
|
+
*/
|
|
160
|
+
function getHermesOSExe() {
|
|
161
|
+
const hermesExecutableName = 'hermesc';
|
|
162
|
+
switch (process.platform) {
|
|
163
|
+
case 'win32':
|
|
164
|
+
return hermesExecutableName + '.exe';
|
|
165
|
+
default:
|
|
166
|
+
return hermesExecutableName;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @return {string | null}
|
|
172
|
+
*/
|
|
173
|
+
function getComposeSourceMapsPath() {
|
|
174
|
+
// detect if compose-source-maps.js script exists
|
|
175
|
+
const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
|
|
176
|
+
if (fs.existsSync(composeSourceMaps)) {
|
|
177
|
+
return composeSourceMaps;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @return {string}
|
|
184
|
+
*/
|
|
185
|
+
function getReactNativePackagePath() {
|
|
186
|
+
const result = childProcess.spawnSync('node', [
|
|
187
|
+
'--print',
|
|
188
|
+
"require.resolve('react-native/package.json')",
|
|
189
|
+
]);
|
|
190
|
+
const packagePath = path.dirname(result.stdout.toString());
|
|
191
|
+
if (result.status === 0 && directoryExistsSync(packagePath)) {
|
|
192
|
+
return packagePath;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return path.join('node_modules', 'react-native');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* @param dirname {string}
|
|
200
|
+
* @return {boolean}
|
|
201
|
+
*/
|
|
202
|
+
function directoryExistsSync(dirname) {
|
|
203
|
+
try {
|
|
204
|
+
return fs.statSync(dirname).isDirectory();
|
|
205
|
+
} catch (err) {
|
|
206
|
+
if (err.code !== 'ENOENT') {
|
|
207
|
+
throw err;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = { runHermesEmitBinaryCommand };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code based on appcenter-cli
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const shell = require('shelljs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Run `react-native bundle` CLI command
|
|
10
|
+
*
|
|
11
|
+
* @param bundleName {string} JS bundle file name
|
|
12
|
+
* @param entryFile {string} App code entry file name (default: index.ts)
|
|
13
|
+
* @param outputPath {string} Path to output JS bundle file and assets
|
|
14
|
+
* @param platform {string} Platform (ios | android)
|
|
15
|
+
* @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
|
|
16
|
+
* @param extraBundlerOptions {string[]} Additional options to pass to `react-native bundle` command
|
|
17
|
+
* @return {void}
|
|
18
|
+
*/
|
|
19
|
+
function runReactNativeBundleCommand(
|
|
20
|
+
bundleName,
|
|
21
|
+
outputPath,
|
|
22
|
+
platform,
|
|
23
|
+
sourcemapOutput,
|
|
24
|
+
entryFile = 'index.ts',
|
|
25
|
+
extraBundlerOptions = [],
|
|
26
|
+
) {
|
|
27
|
+
/**
|
|
28
|
+
* @return {string}
|
|
29
|
+
*/
|
|
30
|
+
function getCliPath() {
|
|
31
|
+
return path.join('node_modules', '.bin', 'react-native');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @type {string[]}
|
|
36
|
+
*/
|
|
37
|
+
const reactNativeBundleArgs = [
|
|
38
|
+
'bundle',
|
|
39
|
+
'--assets-dest',
|
|
40
|
+
outputPath,
|
|
41
|
+
'--bundle-output',
|
|
42
|
+
path.join(outputPath, bundleName),
|
|
43
|
+
'--dev',
|
|
44
|
+
'false',
|
|
45
|
+
'--entry-file',
|
|
46
|
+
entryFile,
|
|
47
|
+
'--platform',
|
|
48
|
+
platform,
|
|
49
|
+
'--sourcemap-output',
|
|
50
|
+
sourcemapOutput,
|
|
51
|
+
...extraBundlerOptions,
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
console.log('Running "react-native bundle" command:\n');
|
|
55
|
+
|
|
56
|
+
shell.exec(`${getCliPath()} ${reactNativeBundleArgs.join(' ')}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = { runReactNativeBundleCommand };
|
package/cli/index.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require("commander");
|
|
4
|
+
const shell = require("shelljs");
|
|
5
|
+
const { showLogo } = require("./utils/showLogo");
|
|
6
|
+
|
|
7
|
+
shell.set("-e");
|
|
8
|
+
shell.set("+v");
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name("npx code-push")
|
|
12
|
+
.description("Command line interface for @bravemobile/react-native-code-push")
|
|
13
|
+
.version("1.0.0")
|
|
14
|
+
.action(() => {
|
|
15
|
+
showLogo();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* npx code-push bundle
|
|
20
|
+
*/
|
|
21
|
+
require("./commands/bundleCommand");
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* npx code-push create-history
|
|
25
|
+
*/
|
|
26
|
+
require('./commands/createHistoryCommand');
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* npx code-push update-history
|
|
30
|
+
*/
|
|
31
|
+
require('./commands/updateHistoryCommand');
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* npx code-push release
|
|
35
|
+
*/
|
|
36
|
+
require('./commands/releaseCommand');
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* npx code-push show-history
|
|
40
|
+
*/
|
|
41
|
+
require('./commands/showHistoryCommand')
|
|
42
|
+
|
|
43
|
+
program.parse();
|