@algocare/react-native-code-push 9.0.0-beta.3 → 9.0.0-beta.5

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.
@@ -1,8 +1,8 @@
1
- const fs = require('fs');
2
- const path = require('path');
1
+ const fs = require('fs')
2
+ const path = require('path')
3
3
 
4
4
  /**
5
- *
5
+ * @param app {"user" | "device"}
6
6
  * @param targetVersion {string}
7
7
  * @param setReleaseHistory {
8
8
  * function(
@@ -17,37 +17,49 @@ const path = require('path');
17
17
  * @returns {Promise<void>}
18
18
  */
19
19
  async function createReleaseHistory(
20
- targetVersion,
21
- setReleaseHistory,
22
- platform,
23
- identifier,
20
+ app,
21
+ targetVersion,
22
+ setReleaseHistory,
23
+ platform,
24
+ identifier
24
25
  ) {
25
- const BINARY_RELEASE = {
26
- enabled: true,
27
- mandatory: false,
28
- downloadUrl: "",
29
- packageHash: "",
30
- };
26
+ const BINARY_RELEASE = {
27
+ enabled: true,
28
+ mandatory: false,
29
+ downloadUrl: '',
30
+ packageHash: '',
31
+ }
31
32
 
32
- /** @type {ReleaseHistoryInterface} */
33
- const INITIAL_HISTORY = {
34
- [targetVersion]: BINARY_RELEASE
35
- };
33
+ /** @type {ReleaseHistoryInterface} */
34
+ // not use
35
+ const INITIAL_HISTORY = {
36
+ [targetVersion]: BINARY_RELEASE,
37
+ }
36
38
 
37
- try {
38
- const JSON_FILE_NAME = `${targetVersion}.json`;
39
- const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
39
+ try {
40
+ const JSON_FILE_NAME = `${targetVersion}.json`
41
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
40
42
 
41
- console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(INITIAL_HISTORY, null, 2));
42
- fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(INITIAL_HISTORY));
43
+ console.log(
44
+ `log: creating JSON file... ("${JSON_FILE_NAME}")\n`,
45
+ JSON.stringify({}, null, 2)
46
+ )
47
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify({}))
43
48
 
44
- await setReleaseHistory(targetVersion, JSON_FILE_PATH, INITIAL_HISTORY, platform, identifier)
49
+ await setReleaseHistory(
50
+ targetVersion,
51
+ JSON_FILE_PATH,
52
+ {},
53
+ app,
54
+ platform,
55
+ identifier
56
+ )
45
57
 
46
- fs.unlinkSync(JSON_FILE_PATH);
47
- } catch (error) {
48
- console.error('Error occurred while creating new history:', error);
49
- process.exit(1)
50
- }
58
+ fs.unlinkSync(JSON_FILE_PATH)
59
+ } catch (error) {
60
+ console.error('Error occurred while creating new history:', error)
61
+ process.exit(1)
62
+ }
51
63
  }
52
64
 
53
65
  module.exports = { createReleaseHistory: createReleaseHistory }
@@ -1,29 +1,50 @@
1
- const { program, Option } = require("commander");
2
- const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
- const { createReleaseHistory } = require("./createReleaseHistory");
4
- const { CONFIG_FILE_NAME } = require('../../constant');
1
+ const { program, Option } = require('commander')
2
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
3
+ const { createReleaseHistory } = require('./createReleaseHistory')
4
+ const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
5
5
 
6
- program.command('create-history')
7
- .description('Creates a new release history for the binary app.')
8
- .requiredOption('-b, --binary-version <string>', '(Required) The target 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)', CONFIG_FILE_NAME)
12
- /**
13
- * @param {Object} options
14
- * @param {string} options.binaryVersion
15
- * @param {string} options.platform
16
- * @param {string} options.identifier
17
- * @param {string} options.config
18
- * @return {void}
19
- */
20
- .action(async (options) => {
21
- const config = findAndReadConfigFile(process.cwd(), options.config);
6
+ program
7
+ .command('create-history')
8
+ .description('Creates a new release history for the binary app.')
9
+ .requiredOption(
10
+ '-a, --app <string>',
11
+ '(Required) The target app: user or device'
12
+ )
13
+ .requiredOption(
14
+ '-b, --binary-version <string>',
15
+ '(Required) The target binary version'
16
+ )
17
+ .addOption(
18
+ new Option('-p, --platform <type>', 'platform')
19
+ .choices(['ios', 'android'])
20
+ .default('ios')
21
+ )
22
+ .option(
23
+ '-i, --identifier <string>',
24
+ 'reserved characters to distinguish the release.'
25
+ )
26
+ .option(
27
+ '-c, --config <path>',
28
+ 'set config file name (JS/TS)',
29
+ COMPILED_CONFIG_FILE_NAME
30
+ )
31
+ /**
32
+ * @param {Object} options
33
+ * @param {string} options.app
34
+ * @param {string} options.binaryVersion
35
+ * @param {string} options.platform
36
+ * @param {string} options.identifier
37
+ * @param {string} options.config
38
+ * @return {void}
39
+ */
40
+ .action(async (options) => {
41
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
22
42
 
23
- await createReleaseHistory(
24
- options.binaryVersion,
25
- config.setReleaseHistory,
26
- options.platform,
27
- options.identifier
28
- );
29
- });
43
+ await createReleaseHistory(
44
+ options.app,
45
+ options.binaryVersion,
46
+ config.setReleaseHistory,
47
+ options.platform,
48
+ options.identifier
49
+ )
50
+ })
@@ -1,8 +1,8 @@
1
- const path = require("path");
2
- const fs = require("fs");
1
+ const path = require('path')
2
+ const fs = require('fs')
3
3
 
4
4
  /**
5
- *
5
+ * @param app {"user" | "device"}
6
6
  * @param appVersion {string}
7
7
  * @param binaryVersion {string}
8
8
  * @param bundleDownloadUrl {string}
@@ -28,48 +28,64 @@ const fs = require("fs");
28
28
  * @returns {Promise<void>}
29
29
  */
30
30
  async function addToReleaseHistory(
31
- appVersion,
31
+ app,
32
+ appVersion,
33
+ binaryVersion,
34
+ bundleDownloadUrl,
35
+ packageHash,
36
+ getReleaseHistory,
37
+ setReleaseHistory,
38
+ platform,
39
+ identifier,
40
+ mandatory,
41
+ enable
42
+ ) {
43
+ const releaseHistory = await getReleaseHistory(
44
+ app,
32
45
  binaryVersion,
33
- bundleDownloadUrl,
34
- packageHash,
35
- getReleaseHistory,
36
- setReleaseHistory,
37
46
  platform,
38
- identifier,
39
- mandatory,
40
- enable,
41
- ) {
42
- const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier);
47
+ identifier
48
+ )
43
49
 
44
- const updateInfo = releaseHistory[appVersion]
45
- if (updateInfo) {
46
- console.error(`v${appVersion} is already released`)
47
- process.exit(1)
48
- }
50
+ const updateInfo = releaseHistory[appVersion]
51
+ if (updateInfo) {
52
+ console.error(`v${appVersion} is already released`)
53
+ process.exit(1)
54
+ }
49
55
 
50
- const newReleaseHistory = structuredClone(releaseHistory);
56
+ const newReleaseHistory = structuredClone(releaseHistory)
51
57
 
52
- newReleaseHistory[appVersion] = {
53
- enabled: enable,
54
- mandatory: mandatory,
55
- downloadUrl: bundleDownloadUrl,
56
- packageHash: packageHash,
57
- }
58
+ newReleaseHistory[appVersion] = {
59
+ enabled: enable,
60
+ mandatory: mandatory,
61
+ downloadUrl: bundleDownloadUrl,
62
+ packageHash: packageHash,
63
+ }
58
64
 
59
- try {
60
- const JSON_FILE_NAME = `${binaryVersion}.json`;
61
- const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
65
+ try {
66
+ const JSON_FILE_NAME = `${binaryVersion}.json`
67
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
62
68
 
63
- console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(newReleaseHistory, null, 2));
64
- fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(newReleaseHistory));
69
+ console.log(
70
+ `log: creating JSON file... ("${JSON_FILE_NAME}")\n`,
71
+ JSON.stringify(newReleaseHistory, null, 2)
72
+ )
73
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(newReleaseHistory))
65
74
 
66
- await setReleaseHistory(binaryVersion, JSON_FILE_PATH, newReleaseHistory, platform, identifier)
75
+ await setReleaseHistory(
76
+ binaryVersion,
77
+ JSON_FILE_PATH,
78
+ newReleaseHistory,
79
+ app,
80
+ platform,
81
+ identifier
82
+ )
67
83
 
68
- fs.unlinkSync(JSON_FILE_PATH);
69
- } catch (error) {
70
- console.error('Error occurred while updating history:', error);
71
- process.exit(1)
72
- }
84
+ fs.unlinkSync(JSON_FILE_PATH)
85
+ } catch (error) {
86
+ console.error('Error occurred while updating history:', error)
87
+ process.exit(1)
88
+ }
73
89
  }
74
90
 
75
91
  module.exports = { addToReleaseHistory: addToReleaseHistory }
@@ -1,66 +1,118 @@
1
- const { program, Option } = require("commander");
2
- const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
- const { release } = require("./release");
4
- const { OUTPUT_BUNDLE_DIR, CONFIG_FILE_NAME, ROOT_OUTPUT_DIR, ENTRY_FILE } = require('../../constant');
1
+ const { program, Option } = require('commander')
2
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
3
+ const { release } = require('./release')
4
+ const {
5
+ OUTPUT_BUNDLE_DIR,
6
+ COMPILED_CONFIG_FILE_NAME,
7
+ ROOT_OUTPUT_DIR,
8
+ ENTRY_FILE,
9
+ } = require('../../constant')
5
10
 
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('-b, --binary-version <string>', '(Required) The target binary version')
9
- .requiredOption('-v, --app-version <string>', '(Required) The app version to be released. It must be greater than the binary version.')
10
- .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
11
- .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
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
- .option('-j, --js-bundle-name <string>', 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")')
16
- .option('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, false)
17
- .option('--enable <bool>', 'make the release to be enabled', parseBoolean, true)
18
- .option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
19
- .option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
20
- .option('--output-bundle-dir <string>', 'name of directory containing the bundle file created by the "bundle" command', OUTPUT_BUNDLE_DIR)
21
- /**
22
- * @param {Object} options
23
- * @param {string} options.binaryVersion
24
- * @param {string} options.appVersion
25
- * @param {string} options.platform
26
- * @param {string} options.identifier
27
- * @param {string} options.config
28
- * @param {string} options.outputPath
29
- * @param {string} options.entryFile
30
- * @param {string} options.bundleName
31
- * @param {string} options.mandatory
32
- * @param {string} options.enable
33
- * @param {string} options.skipBundle
34
- * @param {string} options.skipCleanup
35
- * @param {string} options.outputBundleDir
36
- * @return {void}
37
- */
38
- .action(async (options) => {
39
- const config = findAndReadConfigFile(process.cwd(), options.config);
11
+ program
12
+ .command('release')
13
+ .description(
14
+ '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.'
15
+ )
16
+ .requiredOption(
17
+ '-a, --app <string>',
18
+ '(Required) The target app: user or device'
19
+ )
20
+ .requiredOption(
21
+ '-b, --binary-version <string>',
22
+ '(Required) The target binary version'
23
+ )
24
+ .requiredOption(
25
+ '-v, --app-version <string>',
26
+ '(Required) The app version to be released. It must be greater than the binary version.'
27
+ )
28
+ .addOption(
29
+ new Option('-p, --platform <type>', 'platform')
30
+ .choices(['ios', 'android'])
31
+ .default('ios')
32
+ )
33
+ .option(
34
+ '-i, --identifier <string>',
35
+ 'reserved characters to distinguish the release.'
36
+ )
37
+ .option(
38
+ '-c, --config <path>',
39
+ 'set config file name (JS/TS)',
40
+ COMPILED_CONFIG_FILE_NAME
41
+ )
42
+ .option(
43
+ '-o, --output-path <string>',
44
+ 'path to output root directory',
45
+ ROOT_OUTPUT_DIR
46
+ )
47
+ .option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
48
+ .option(
49
+ '-j, --js-bundle-name <string>',
50
+ 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")'
51
+ )
52
+ .option(
53
+ '-m, --mandatory <bool>',
54
+ 'make the release to be mandatory',
55
+ parseBoolean,
56
+ false
57
+ )
58
+ .option(
59
+ '--enable <bool>',
60
+ 'make the release to be enabled',
61
+ parseBoolean,
62
+ true
63
+ )
64
+ .option('--skip-bundle <bool>', 'skip bundle process', parseBoolean, false)
65
+ .option('--skip-cleanup <bool>', 'skip cleanup process', parseBoolean, false)
66
+ .option(
67
+ '--output-bundle-dir <string>',
68
+ 'name of directory containing the bundle file created by the "bundle" command',
69
+ OUTPUT_BUNDLE_DIR
70
+ )
71
+ /**
72
+ * @param {Object} options
73
+ * @param {string} options.app
74
+ * @param {string} options.binaryVersion
75
+ * @param {string} options.appVersion
76
+ * @param {string} options.platform
77
+ * @param {string} options.identifier
78
+ * @param {string} options.config
79
+ * @param {string} options.outputPath
80
+ * @param {string} options.entryFile
81
+ * @param {string} options.bundleName
82
+ * @param {string} options.mandatory
83
+ * @param {string} options.enable
84
+ * @param {string} options.skipBundle
85
+ * @param {string} options.skipCleanup
86
+ * @param {string} options.outputBundleDir
87
+ * @return {void}
88
+ */
89
+ .action(async (options) => {
90
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
40
91
 
41
- await release(
42
- config.bundleUploader,
43
- config.getReleaseHistory,
44
- config.setReleaseHistory,
45
- options.binaryVersion,
46
- options.appVersion,
47
- options.platform,
48
- options.identifier,
49
- options.outputPath,
50
- options.entryFile,
51
- options.bundleName,
52
- options.mandatory,
53
- options.enable,
54
- options.skipBundle,
55
- options.skipCleanup,
56
- `${options.outputPath}/${options.outputBundleDir}`,
57
- )
92
+ await release(
93
+ config.bundleUploader,
94
+ config.getReleaseHistory,
95
+ config.setReleaseHistory,
96
+ options.app,
97
+ options.binaryVersion,
98
+ options.appVersion,
99
+ options.platform,
100
+ options.identifier,
101
+ options.outputPath,
102
+ options.entryFile,
103
+ options.bundleName,
104
+ options.mandatory,
105
+ options.enable,
106
+ options.skipBundle,
107
+ options.skipCleanup,
108
+ `${options.outputPath}/${options.outputBundleDir}`
109
+ )
58
110
 
59
- console.log('🚀 Release completed.')
60
- });
111
+ console.log('🚀 Release completed.')
112
+ })
61
113
 
62
114
  function parseBoolean(value) {
63
- if (value === 'true') return true;
64
- if (value === 'false') return false;
65
- else return undefined;
115
+ if (value === 'true') return true
116
+ if (value === 'false') return false
117
+ else return undefined
66
118
  }
@@ -1,6 +1,6 @@
1
- const fs = require('fs');
2
- const { bundleCodePush } = require("../bundleCommand/bundleCodePush");
3
- const { addToReleaseHistory } = require("./addToReleaseHistory");
1
+ const fs = require('fs')
2
+ const { bundleCodePush } = require('../bundleCommand/bundleCodePush')
3
+ const { addToReleaseHistory } = require('./addToReleaseHistory')
4
4
 
5
5
  /**
6
6
  * @param bundleUploader {
@@ -23,6 +23,7 @@ const { addToReleaseHistory } = require("./addToReleaseHistory");
23
23
  * platform: "ios" | "android",
24
24
  * identifier?: string
25
25
  * ): Promise<void>}
26
+ * @param app {"user" | "device"}
26
27
  * @param binaryVersion {string}
27
28
  * @param appVersion {string}
28
29
  * @param platform {"ios" | "android"}
@@ -38,57 +39,75 @@ const { addToReleaseHistory } = require("./addToReleaseHistory");
38
39
  * @return {Promise<void>}
39
40
  */
40
41
  async function release(
41
- bundleUploader,
42
+ bundleUploader,
43
+ getReleaseHistory,
44
+ setReleaseHistory,
45
+ app,
46
+ binaryVersion,
47
+ appVersion,
48
+ platform,
49
+ identifier,
50
+ outputPath,
51
+ entryFile,
52
+ jsBundleName,
53
+ mandatory,
54
+ enable,
55
+ skipBundle,
56
+ skipCleanup,
57
+ bundleDirectory
58
+ ) {
59
+ const bundleFileName = skipBundle
60
+ ? readBundleFileNameFrom(bundleDirectory)
61
+ : await bundleCodePush(
62
+ platform,
63
+ outputPath,
64
+ entryFile,
65
+ jsBundleName,
66
+ bundleDirectory
67
+ )
68
+ const bundleFilePath = `${bundleDirectory}/${bundleFileName}`
69
+
70
+ const downloadUrl = await (async () => {
71
+ try {
72
+ console.log('Uploading Bundle File...')
73
+ const { downloadUrl } = await bundleUploader(
74
+ bundleFilePath,
75
+ app,
76
+ platform,
77
+ identifier
78
+ )
79
+ console.log('Bundle File uploaded:', downloadUrl)
80
+ return downloadUrl
81
+ } catch (error) {
82
+ console.error(
83
+ 'Failed to upload the bundle file. Exiting the program.',
84
+ error
85
+ )
86
+ process.exit(1)
87
+ }
88
+ })()
89
+
90
+ await addToReleaseHistory(
91
+ app,
92
+ appVersion,
93
+ binaryVersion,
94
+ downloadUrl,
95
+ bundleFileName,
42
96
  getReleaseHistory,
43
97
  setReleaseHistory,
44
- binaryVersion,
45
- appVersion,
46
98
  platform,
47
99
  identifier,
48
- outputPath,
49
- entryFile,
50
- jsBundleName,
51
100
  mandatory,
52
- enable,
53
- skipBundle,
54
- skipCleanup,
55
- bundleDirectory,
56
- ) {
57
- const bundleFileName = skipBundle
58
- ? readBundleFileNameFrom(bundleDirectory)
59
- : await bundleCodePush(platform, outputPath, entryFile, jsBundleName, bundleDirectory);
60
- const bundleFilePath = `${bundleDirectory}/${bundleFileName}`;
61
-
62
- const downloadUrl = await (async () => {
63
- try {
64
- const { downloadUrl } = await bundleUploader(bundleFilePath, platform, identifier);
65
- return downloadUrl
66
- } catch (error) {
67
- console.error('Failed to upload the bundle file. Exiting the program.', error)
68
- process.exit(1)
69
- }
70
- })();
101
+ enable
102
+ )
71
103
 
72
- await addToReleaseHistory(
73
- appVersion,
74
- binaryVersion,
75
- downloadUrl,
76
- bundleFileName,
77
- getReleaseHistory,
78
- setReleaseHistory,
79
- platform,
80
- identifier,
81
- mandatory,
82
- enable,
83
- )
84
-
85
- if (!skipCleanup) {
86
- cleanUpOutputs(outputPath);
87
- }
104
+ if (!skipCleanup) {
105
+ cleanUpOutputs(outputPath)
106
+ }
88
107
  }
89
108
 
90
109
  function cleanUpOutputs(dir) {
91
- fs.rmSync(dir, { recursive: true });
110
+ fs.rmSync(dir, { recursive: true })
92
111
  }
93
112
 
94
113
  /**
@@ -96,14 +115,14 @@ function cleanUpOutputs(dir) {
96
115
  * @return {string}
97
116
  */
98
117
  function readBundleFileNameFrom(bundleDirectory) {
99
- const files = fs.readdirSync(bundleDirectory);
100
- if (files.length !== 1) {
101
- console.error('The bundlePath must contain only one file.');
102
- process.exit(1);
103
- }
104
- const path = require('path');
105
- const bundleFilePath = path.join(bundleDirectory, files[0]);
106
- return path.basename(bundleFilePath);
118
+ const files = fs.readdirSync(bundleDirectory)
119
+ if (files.length !== 1) {
120
+ console.error('The bundlePath must contain only one file.')
121
+ process.exit(1)
122
+ }
123
+ const path = require('path')
124
+ const bundleFilePath = path.join(bundleDirectory, files[0])
125
+ return path.basename(bundleFilePath)
107
126
  }
108
127
 
109
128
  module.exports = { release: release }