@bravemobile/react-native-code-push 9.0.0-alpha.3 → 9.0.0-beta.0

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 CHANGED
@@ -121,8 +121,8 @@ async function checkForUpdate(deploymentKey = null, handleBinaryVersionMismatchC
121
121
 
122
122
  if (!updateInfo) {
123
123
  return null;
124
- } else if (updateInfo.update_app_version) {
125
- return { updateAppVersion: true, appVersion: updateInfo.target_binary_range };
124
+ } else if (!updateInfo.download_url) {
125
+ return null;
126
126
  } else if (!updateInfo.is_available) {
127
127
  return null;
128
128
  }
@@ -1,31 +1,39 @@
1
+ const fs = require('fs');
1
2
  const { prepareToBundleJS } = require('../../functions/prepareToBundleJS');
2
3
  const { runReactNativeBundleCommand } = require('../../functions/runReactNativeBundleCommand');
3
4
  const { getReactTempDir } = require('../../functions/getReactTempDir');
4
5
  const { runHermesEmitBinaryCommand } = require('../../functions/runHermesEmitBinaryCommand');
5
6
  const { makeCodePushBundle } = require('../../functions/makeCodePushBundle');
7
+ const { ROOT_OUTPUT_DIR, ENTRY_FILE } = require('../../constant');
6
8
 
7
9
  /**
8
10
  * @param platform {string} 'ios' | 'android'
9
11
  * @param outputRootPath {string}
10
12
  * @param entryFile {string}
11
- * @param bundleName {string|undefined}
12
- * @return {Promise<{bundleFileName: string, packageHash: string}>}
13
+ * @param jsBundleName {string|undefined}
14
+ * @param bundleDirectory {string}
15
+ * @return {Promise<string>} CodePush bundle file name (equals to packageHash)
13
16
  */
14
17
  async function bundleCodePush(
15
18
  platform = 'ios',
16
- outputRootPath = 'build',
17
- entryFile = 'index.ts',
18
- bundleName,
19
+ outputRootPath = ROOT_OUTPUT_DIR,
20
+ entryFile = ENTRY_FILE,
21
+ jsBundleName, // JS bundle file name (not CodePush bundle file)
22
+ bundleDirectory, // CodePush bundle output directory
19
23
  ) {
24
+ if (fs.existsSync(outputRootPath)) {
25
+ fs.rmSync(outputRootPath, { recursive: true });
26
+ }
27
+
20
28
  const OUTPUT_CONTENT_PATH = `${outputRootPath}/CodePush`;
21
- const BUNDLE_NAME_DEFAULT = platform === 'ios' ? 'main.jsbundle' : 'index.android.bundle';
22
- const _bundleName = bundleName ? bundleName : BUNDLE_NAME_DEFAULT;
23
- const SOURCEMAP_OUTPUT = `${outputRootPath}/${_bundleName}.map`;
29
+ const DEFAULT_JS_BUNDLE_NAME = platform === 'ios' ? 'main.jsbundle' : 'index.android.bundle';
30
+ const _jsBundleName = jsBundleName || DEFAULT_JS_BUNDLE_NAME; // react-native JS bundle output name
31
+ const SOURCEMAP_OUTPUT = `${outputRootPath}/${_jsBundleName}.map`;
24
32
 
25
33
  prepareToBundleJS({ deleteDirs: [outputRootPath, getReactTempDir()], makeDir: OUTPUT_CONTENT_PATH });
26
34
 
27
35
  runReactNativeBundleCommand(
28
- _bundleName,
36
+ _jsBundleName,
29
37
  OUTPUT_CONTENT_PATH,
30
38
  platform,
31
39
  SOURCEMAP_OUTPUT,
@@ -34,16 +42,16 @@ async function bundleCodePush(
34
42
  console.log('log: JS bundling complete');
35
43
 
36
44
  await runHermesEmitBinaryCommand(
37
- _bundleName,
45
+ _jsBundleName,
38
46
  OUTPUT_CONTENT_PATH,
39
47
  SOURCEMAP_OUTPUT,
40
48
  );
41
49
  console.log('log: Hermes compilation complete');
42
50
 
43
- const { bundleFileName, packageHash } = await makeCodePushBundle(OUTPUT_CONTENT_PATH);
44
- console.log(`log: CodePush bundle created (file name: ${bundleFileName})`);
51
+ const { bundleFileName: codePushBundleFileName } = await makeCodePushBundle(OUTPUT_CONTENT_PATH, bundleDirectory);
52
+ console.log(`log: CodePush bundle created (file path: ./${bundleDirectory}/${codePushBundleFileName})`);
45
53
 
46
- return { bundleFileName, packageHash }; // returns for release command implementation
54
+ return codePushBundleFileName;
47
55
  }
48
56
 
49
57
  module.exports = { bundleCodePush: bundleCodePush };
@@ -1,18 +1,21 @@
1
1
  const { program, Option } = require("commander");
2
2
  const { bundleCodePush } = require("./bundleCodePush");
3
+ const { OUTPUT_BUNDLE_DIR, ROOT_OUTPUT_DIR, ENTRY_FILE } = require('../../constant');
3
4
 
4
5
  program.command('bundle')
5
6
  .description('Creates a CodePush bundle file (assumes Hermes is enabled).')
6
7
  .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
7
- .option('-o, --output-path <string>', 'path to output root directory', 'build')
8
- .option('-e, --entry-file <string>', 'path to JS/TS entry file', 'index.ts')
8
+ .option('-o, --output-path <string>', 'path to output root directory', ROOT_OUTPUT_DIR)
9
+ .option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
9
10
  .option('-b, --bundle-name <string>', 'bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
11
+ .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
10
12
  /**
11
13
  * @param {Object} options
12
14
  * @param {string} options.platform
13
15
  * @param {string} options.outputPath
14
16
  * @param {string} options.entryFile
15
17
  * @param {string} options.bundleName
18
+ * @param {string} options.outputBundleDir
16
19
  * @return {void}
17
20
  */
18
21
  .action((options) => {
@@ -21,5 +24,6 @@ program.command('bundle')
21
24
  options.outputPath,
22
25
  options.entryFile,
23
26
  options.bundleName,
27
+ `${options.outputPath}/${options.outputBundleDir}`,
24
28
  )
25
29
  });
@@ -1,13 +1,14 @@
1
1
  const { program, Option } = require("commander");
2
2
  const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
3
  const { createReleaseHistory } = require("./createReleaseHistory");
4
+ const { CONFIG_FILE_NAME } = require('../../constant');
4
5
 
5
6
  program.command('create-history')
6
7
  .description('Creates a new release history for the binary app.')
7
8
  .requiredOption('-b, --binary-version <string>', '(Required) The target binary version')
8
9
  .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
9
10
  .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
10
- .option('-c, --config <path>', 'set config file name (JS/TS)', 'code-push.config.ts')
11
+ .option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
11
12
  /**
12
13
  * @param {Object} options
13
14
  * @param {string} options.binaryVersion
@@ -1,7 +1,7 @@
1
1
  const { program, Option } = require("commander");
2
- const SemVer = require('semver');
3
2
  const { findAndReadConfigFile } = require("../../utils/fsUtils");
4
3
  const { release } = require("./release");
4
+ const { OUTPUT_BUNDLE_DIR, CONFIG_FILE_NAME, ROOT_OUTPUT_DIR, ENTRY_FILE } = require('../../constant');
5
5
 
6
6
  program.command('release')
7
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.')
@@ -9,12 +9,14 @@ program.command('release')
9
9
  .requiredOption('-v, --app-version <string>', '(Required) The app version to be released. It must be greater than the binary version.')
10
10
  .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
11
11
  .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
12
- .option('-c, --config <path>', 'set config file name (JS/TS)', 'code-push.config.ts')
13
- .option('-o, --output-path <string>', 'path to output root directory', 'build')
14
- .option('-e, --entry-file <string>', 'path to JS/TS entry file', 'index.ts')
12
+ .option('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
13
+ .option('-o, --output-path <string>', 'path to output root directory', ROOT_OUTPUT_DIR)
14
+ .option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
15
15
  .option('-j, --js-bundle-name <string>', 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
16
16
  .option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, false)
17
17
  .option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
18
+ .option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
19
+ .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
18
20
  /**
19
21
  * @param {Object} options
20
22
  * @param {string} options.binaryVersion
@@ -27,6 +29,8 @@ program.command('release')
27
29
  * @param {string} options.bundleName
28
30
  * @param {string} options.mandatory
29
31
  * @param {string} options.enable
32
+ * @param {string} options.skipBundle
33
+ * @param {string} options.outputBundleDir
30
34
  * @return {void}
31
35
  */
32
36
  .action(async (options) => {
@@ -45,6 +49,8 @@ program.command('release')
45
49
  options.bundleName,
46
50
  options.mandatory,
47
51
  options.enable,
52
+ options.skipBundle,
53
+ `${options.outputPath}/${options.outputBundleDir}`,
48
54
  )
49
55
 
50
56
  console.log('🚀 Release completed.')
@@ -1,3 +1,4 @@
1
+ const fs = require('fs');
1
2
  const { bundleCodePush } = require("../bundleCommand/bundleCodePush");
2
3
  const { addToReleaseHistory } = require("./addToReleaseHistory");
3
4
 
@@ -31,6 +32,8 @@ const { addToReleaseHistory } = require("./addToReleaseHistory");
31
32
  * @param jsBundleName {string}
32
33
  * @param mandatory {boolean}
33
34
  * @param enable {boolean}
35
+ * @param skipBundle {boolean}
36
+ * @param bundleDirectory {string}
34
37
  * @return {Promise<void>}
35
38
  */
36
39
  async function release(
@@ -46,17 +49,17 @@ async function release(
46
49
  jsBundleName,
47
50
  mandatory,
48
51
  enable,
52
+ skipBundle,
53
+ bundleDirectory,
49
54
  ) {
50
- const { bundleFileName, packageHash } = await bundleCodePush(
51
- platform,
52
- outputPath,
53
- entryFile,
54
- jsBundleName,
55
- );
55
+ const bundleFileName = skipBundle
56
+ ? readBundleFileNameFrom(bundleDirectory)
57
+ : await bundleCodePush(platform, outputPath, entryFile, jsBundleName, bundleDirectory);
58
+ const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;
56
59
 
57
60
  const downloadUrl = await (async () => {
58
61
  try {
59
- const { downloadUrl } = await bundleUploader(`./${bundleFileName}`, platform, identifier);
62
+ const { downloadUrl } = await bundleUploader(bundleFilePath, platform, identifier);
60
63
  return downloadUrl
61
64
  } catch (error) {
62
65
  console.error('Failed to upload the bundle file. Exiting the program.', error)
@@ -68,7 +71,7 @@ async function release(
68
71
  appVersion,
69
72
  binaryVersion,
70
73
  downloadUrl,
71
- packageHash,
74
+ bundleFileName,
72
75
  getReleaseHistory,
73
76
  setReleaseHistory,
74
77
  platform,
@@ -77,12 +80,26 @@ async function release(
77
80
  enable,
78
81
  )
79
82
 
80
- deleteUploadedBundleFile(bundleFileName);
83
+ cleanUpOutputs(outputPath);
84
+ }
85
+
86
+ function cleanUpOutputs(dir) {
87
+ fs.rmSync(dir, { recursive: true });
81
88
  }
82
89
 
83
- function deleteUploadedBundleFile(bundleFileName) {
84
- const fs = require('fs');
85
- fs.unlinkSync(`./${bundleFileName}`);
90
+ /**
91
+ * @param bundleDirectory {string}
92
+ * @return {string}
93
+ */
94
+ function readBundleFileNameFrom(bundleDirectory) {
95
+ const files = fs.readdirSync(bundleDirectory);
96
+ if (files.length !== 1) {
97
+ console.error('The bundlePath must contain only one file.');
98
+ process.exit(1);
99
+ }
100
+ const path = require('path');
101
+ const bundleFilePath = path.join(bundleDirectory, files[0]);
102
+ return path.basename(bundleFilePath);
86
103
  }
87
104
 
88
105
  module.exports = { release: release }
@@ -1,12 +1,13 @@
1
1
  const { program, Option } = require("commander");
2
2
  const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
+ const { CONFIG_FILE_NAME } = require('../../constant');
3
4
 
4
5
  program.command('show-history')
5
6
  .description('Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.')
6
7
  .requiredOption('-b, --binary-version <string>', '(Required) The target binary version for retrieving the release history.')
7
8
  .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
8
9
  .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
+ .option('-c, --config <path>', 'configuration file name (JS/TS)', CONFIG_FILE_NAME)
10
11
  /**
11
12
  * @param {Object} options
12
13
  * @param {string} options.binaryVersion
@@ -1,6 +1,7 @@
1
1
  const { program, Option } = require("commander");
2
2
  const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
3
  const { updateReleaseHistory } = require("./updateReleaseHistory");
4
+ const { CONFIG_FILE_NAME } = require('../../constant');
4
5
 
5
6
  program.command('update-history')
6
7
  .description('Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.')
@@ -8,7 +9,7 @@ program.command('update-history')
8
9
  .requiredOption('-b, --binary-version <string>', '(Required) The target binary version of the app for which update information is to be modified.')
9
10
  .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
10
11
  .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('-c, --config <path>', 'set config file name (JS/TS)', CONFIG_FILE_NAME)
12
13
  .option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, undefined)
13
14
  .option('-e, --enable <bool>', 'make the release to be enabled', parseBoolean, undefined)
14
15
  /**
package/cli/constant.js CHANGED
@@ -1,3 +1,6 @@
1
1
  module.exports = {
2
- configFileName: "code-push.config.ts",
2
+ CONFIG_FILE_NAME: "code-push.config.ts",
3
+ OUTPUT_BUNDLE_DIR: "bundleOutput",
4
+ ROOT_OUTPUT_DIR: "build",
5
+ ENTRY_FILE: "index.ts",
3
6
  };
@@ -1,4 +1,3 @@
1
- const { randomUUID } = require('crypto');
2
1
  const path = require('path');
3
2
  const shell = require('shelljs');
4
3
  const zip = require('../utils/zip');
@@ -8,19 +7,21 @@ const {generatePackageHashFromDirectory} = require('../utils/hash-utils');
8
7
  * Create a CodePush bundle file and return the information.
9
8
  *
10
9
  * @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 }>}
10
+ * @param bundleDirectory {string} The directory path to save the CodePush bundle file
11
+ * @return {Promise<{ bundleFileName: string }>}
12
12
  */
13
- async function makeCodePushBundle(contentsPath) {
13
+ async function makeCodePushBundle(contentsPath, bundleDirectory) {
14
14
  const updateContentsZipPath = await zip(contentsPath);
15
15
 
16
- const bundleFileName = randomUUID();
17
- shell.mv(updateContentsZipPath, `./${bundleFileName}`);
18
-
19
16
  const packageHash = await generatePackageHashFromDirectory(contentsPath, path.join(contentsPath, '..'));
20
17
 
18
+ shell.mkdir('-p', `./${bundleDirectory}`);
19
+ shell.mv(updateContentsZipPath, `./${bundleDirectory}/${packageHash}`);
20
+
21
21
  return {
22
- bundleFileName: bundleFileName,
23
- packageHash: packageHash,
22
+ // To allow the "release" command to get the file and hash value from the result of the "bundle" command,
23
+ // use the hash value as the name of the file.
24
+ bundleFileName: packageHash,
24
25
  };
25
26
  }
26
27
 
@@ -21,7 +21,7 @@ function runReactNativeBundleCommand(
21
21
  outputPath,
22
22
  platform,
23
23
  sourcemapOutput,
24
- entryFile = 'index.ts',
24
+ entryFile,
25
25
  extraBundlerOptions = [],
26
26
  ) {
27
27
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bravemobile/react-native-code-push",
3
- "version": "9.0.0-alpha.3",
3
+ "version": "9.0.0-beta.0",
4
4
  "description": "React Native plugin for the CodePush service",
5
5
  "main": "CodePush.js",
6
6
  "typings": "typings/react-native-code-push.d.ts",
@@ -524,7 +524,7 @@ export interface CliConfigInterface {
524
524
  * Used in the `release` command, and must return a URL that allows downloading the file after the upload is completed.
525
525
  * The URL is recorded in the ReleaseHistory, and the CodePush runtime library downloads the bundle file from this address.
526
526
  *
527
- * @param source The relative path of the generated bundle file. (e.g., ./2f156929-e474-46cd-9c9c-27a841043d98)
527
+ * @param source The relative path of the generated bundle file. (e.g. build/bundleOutput/1087bc338fc45a961c...)
528
528
  * @param platform The target platform of the bundle file. This is the string passed when executing the CLI command. ('ios'/'android')
529
529
  * @param identifier An additional identifier string. This can be used to distinguish execution environments by incorporating it into the upload path or file name. This string is passed when executing the CLI command.
530
530
  */