@algocare/react-native-code-push 10.1.0 → 10.3.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.
@@ -0,0 +1,34 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ async function createPullRequestHistory(
5
+ setReleaseHistory,
6
+ prNumber,
7
+ app,
8
+ platform
9
+ ) {
10
+ try {
11
+ const JSON_FILE_NAME = `${prNumber}.json`
12
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
13
+
14
+ console.log(
15
+ `log: creating JSON file... ("${JSON_FILE_NAME}")\n`,
16
+ JSON.stringify({}, null, 2)
17
+ )
18
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify({}))
19
+
20
+ await setReleaseHistory(prNumber, JSON_FILE_PATH, {}, app, platform)
21
+
22
+ fs.unlinkSync(JSON_FILE_PATH)
23
+ } catch (error) {
24
+ console.error(
25
+ 'Error occurred while creating new pull request history:',
26
+ error
27
+ )
28
+ process.exit(1)
29
+ }
30
+ }
31
+
32
+ module.exports = {
33
+ createPullRequestHistory,
34
+ }
@@ -0,0 +1,29 @@
1
+ const { program } = require('commander')
2
+ const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
3
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
4
+ const { createPullRequestHistory } = require('./createPullRequestHistory')
5
+
6
+ program
7
+ .command('create-pr-history')
8
+ .description('Creates a new pull request history.')
9
+ .option('-a, --app <string>', 'target app (user/device)')
10
+ .option('-p, --platform <string>', 'target platform (ios/android)')
11
+ .option('-r, --pr-number <number>', 'pull request number')
12
+ .option(
13
+ '-c, --config <path>',
14
+ 'set config file name (JS/TS)',
15
+ COMPILED_CONFIG_FILE_NAME
16
+ )
17
+ .action(async (options) => {
18
+ const { setReleaseHistory } = await findAndReadConfigFile(
19
+ process.cwd(),
20
+ options.config
21
+ )
22
+
23
+ await createPullRequestHistory(
24
+ setReleaseHistory,
25
+ options.prNumber,
26
+ options.app,
27
+ options.platform
28
+ )
29
+ })
@@ -0,0 +1,57 @@
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+
4
+ async function addToPullRequestRelease(
5
+ app,
6
+ binaryVersion,
7
+ prNumber,
8
+ bundleDownloadUrl,
9
+ packageHash,
10
+ platform,
11
+ mandatory,
12
+ enable,
13
+ setReleaseHistory,
14
+ getReleaseHistory
15
+ ) {
16
+ const releaseHistory = await getReleaseHistory(app, prNumber, platform)
17
+ const latestReleaseHistoryNumber = Object.keys(releaseHistory).at(-1)
18
+
19
+ const newReleaseHistoryNumber = latestReleaseHistoryNumber
20
+ ? latestReleaseHistoryNumber + 1
21
+ : 1
22
+ const newReleaseHistory = structuredClone(releaseHistory)
23
+
24
+ newReleaseHistory[newReleaseHistoryNumber] = {
25
+ binaryVersion,
26
+ enabled: enable,
27
+ mandatory,
28
+ downloadUrl: bundleDownloadUrl,
29
+ packageHash,
30
+ }
31
+
32
+ try {
33
+ const JSON_FILE_NAME = `${prNumber}.json`
34
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
35
+
36
+ console.log(
37
+ `log: creating JSON file... ("${JSON_FILE_NAME}")\n`,
38
+ JSON.stringify(newReleaseHistory, null, 2)
39
+ )
40
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(newReleaseHistory))
41
+
42
+ await setReleaseHistory(
43
+ prNumber,
44
+ JSON_FILE_PATH,
45
+ newReleaseHistory,
46
+ app,
47
+ platform
48
+ )
49
+ } catch (error) {
50
+ console.error('Error occurred while updating history:', error)
51
+ process.exit(1)
52
+ }
53
+ }
54
+
55
+ module.exports = {
56
+ addToPullRequestRelease,
57
+ }
@@ -0,0 +1,91 @@
1
+ const fs = require('fs')
2
+ const { bundleCodePush } = require('../bundleCommand/bundleCodePush')
3
+ const { addToPullRequestRelease } = require('./addToPullRequestRelease')
4
+
5
+ async function createPullRequestRelease(
6
+ bundleUploader,
7
+ getReleaseHistory,
8
+ setReleaseHistory,
9
+ app,
10
+ binaryVersion,
11
+ prNumber,
12
+ platform,
13
+ outputPath,
14
+ entryFile,
15
+ jsBundleName,
16
+ mandatory,
17
+ enable,
18
+ skipBundle,
19
+ skipCleanup,
20
+ bundleDirectory
21
+ ) {
22
+ const bundleFileName = skipBundle
23
+ ? readBundleFileNameFrom(bundleDirectory)
24
+ : await bundleCodePush(
25
+ platform,
26
+ outputPath,
27
+ entryFile,
28
+ jsBundleName,
29
+ bundleDirectory
30
+ )
31
+ const bundleFilePath = `${bundleDirectory}/${bundleFileName}`
32
+
33
+ const downloadUrl = await (async () => {
34
+ try {
35
+ console.log('Uploading Bundle File...')
36
+ const { downloadUrl } = await bundleUploader(
37
+ bundleFilePath,
38
+ app,
39
+ platform
40
+ )
41
+ console.log('Bundle File uploaded:', downloadUrl)
42
+ return downloadUrl
43
+ } catch (error) {
44
+ console.error(
45
+ 'Failed to upload the bundle file. Exiting the program.',
46
+ error
47
+ )
48
+ process.exit(1)
49
+ }
50
+ })()
51
+
52
+ await addToPullRequestRelease(
53
+ app,
54
+ binaryVersion,
55
+ prNumber,
56
+ downloadUrl,
57
+ bundleFileName,
58
+ platform,
59
+ mandatory,
60
+ enable,
61
+ setReleaseHistory,
62
+ getReleaseHistory
63
+ )
64
+
65
+ if (!skipCleanup) {
66
+ cleanUpOutputs(outputPath)
67
+ }
68
+ }
69
+
70
+ function cleanUpOutputs(dir) {
71
+ fs.rmSync(dir, { recursive: true })
72
+ }
73
+
74
+ /**
75
+ * @param bundleDirectory {string}
76
+ * @return {string}
77
+ */
78
+ function readBundleFileNameFrom(bundleDirectory) {
79
+ const files = fs.readdirSync(bundleDirectory)
80
+ if (files.length !== 1) {
81
+ console.error('The bundlePath must contain only one file.')
82
+ process.exit(1)
83
+ }
84
+ const path = require('path')
85
+ const bundleFilePath = path.join(bundleDirectory, files[0])
86
+ return path.basename(bundleFilePath)
87
+ }
88
+
89
+ module.exports = {
90
+ createPullRequestRelease,
91
+ }
@@ -0,0 +1,68 @@
1
+ const { program } = require('commander')
2
+ const {
3
+ OUTPUT_BUNDLE_DIR,
4
+ COMPILED_CONFIG_FILE_NAME,
5
+ ROOT_OUTPUT_DIR,
6
+ ENTRY_FILE,
7
+ } = require('../../constant')
8
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
9
+ const { createPullRequestRelease } = require('./createPullRequestRelease')
10
+
11
+ program
12
+ .command('create-pr-release')
13
+ .description('Creates a new pull request release.')
14
+ .option('-a, --app <string>', 'target app (user/device)')
15
+ .option('-p, --platform <string>', 'target platform (ios/android)')
16
+ .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
17
+ .option('-r, --pr-number <number>', 'pull request number')
18
+ .option(
19
+ '-c, --config <path>',
20
+ 'set config file name (JS/TS)',
21
+ COMPILED_CONFIG_FILE_NAME
22
+ )
23
+ .option(
24
+ '-o, --output-path <string>',
25
+ 'path to output root directory',
26
+ ROOT_OUTPUT_DIR
27
+ )
28
+ .option('-e, --entry-file <string>', 'path to JS/TS entry file', ENTRY_FILE)
29
+ .option(
30
+ '-j, --js-bundle-name <string>',
31
+ 'JS bundle file name (default-ios: "main.jsbundle" / default-android: "index.android.bundle")'
32
+ )
33
+ .option('-m, --mandatory', 'make the release to be mandatory', false)
34
+ .option(
35
+ '--enable',
36
+ 'make the release to be enabled (use --no-enable to disable)',
37
+ true
38
+ )
39
+ .option('--no-enable', 'make the release to be disabled')
40
+ .option('--skip-bundle', 'skip bundle process', false)
41
+ .option('--skip-cleanup', 'skip cleanup process', false)
42
+ .option(
43
+ '--output-bundle-dir <string>',
44
+ 'name of directory containing the bundle file created by the "bundle" command',
45
+ OUTPUT_BUNDLE_DIR
46
+ )
47
+ .action(async (options) => {
48
+ const { bundleUploader, setReleaseHistory, getReleaseHistory } =
49
+ await findAndReadConfigFile(process.cwd(), options.config)
50
+
51
+ await createPullRequestRelease(
52
+ bundleUploader,
53
+ setReleaseHistory,
54
+ getReleaseHistory,
55
+ options.app,
56
+ options.binaryVersion,
57
+ options.prNumber,
58
+ options.platform,
59
+ options.outputPath,
60
+ options.entryFile,
61
+ options.jsBundleName,
62
+ options.mandatory,
63
+ options.enable,
64
+ options.skipBundle,
65
+ options.skipCleanup,
66
+ options.outputBundleDir
67
+ )
68
+ })
@@ -0,0 +1,31 @@
1
+ const { program } = require('commander')
2
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
3
+ const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
4
+
5
+ program
6
+ .command('get-development-key')
7
+ .description('the development key for a specific app and platform.')
8
+ .option('-a, --app <string>', 'target app (user/device)')
9
+ .option('-p, --platform <string>', 'target platform (ios/android)')
10
+ .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
11
+ .option('-r, --pr-number <number>', 'pull request number')
12
+ .option(
13
+ '-c, --config <path>',
14
+ 'configuration file name (JS/TS)',
15
+ COMPILED_CONFIG_FILE_NAME
16
+ )
17
+ .action(async (options) => {
18
+ const { getReleaseHistory } = await findAndReadConfigFile(
19
+ process.cwd(),
20
+ options.config
21
+ )
22
+
23
+ const releaseHistory = await getReleaseHistory(
24
+ options.app,
25
+ options.binaryVersion || options.prNumber,
26
+ options.platform
27
+ )
28
+
29
+ const latestReleaseVersion = Object.keys(releaseHistory).at(-1)
30
+ return releaseHistory[latestReleaseVersion].packageHash
31
+ })
@@ -0,0 +1,28 @@
1
+ const { program } = require('commander')
2
+ const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
3
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
4
+ const { removePullRequestHistory } = require('./removePullRequestHistory')
5
+
6
+ program
7
+ .command('remove-pr-history')
8
+ .description('Removes a pull request history.')
9
+ .option('-a, --app <string>', 'target app (user/device)')
10
+ .option('-p, --platform <string>', 'target platform (ios/android)')
11
+ .option('-r, --pr-number <number>', 'pull request number')
12
+ .option(
13
+ '-c, --config <path>',
14
+ 'set config file name (JS/TS)',
15
+ COMPILED_CONFIG_FILE_NAME
16
+ )
17
+ .action(async (options) => {
18
+ const { getReleaseHistory, removeReleaseHistory } =
19
+ await findAndReadConfigFile(process.cwd(), options.config)
20
+
21
+ await removePullRequestHistory(
22
+ getReleaseHistory,
23
+ removeReleaseHistory,
24
+ options.app,
25
+ options.prNumber,
26
+ options.platform
27
+ )
28
+ })
@@ -0,0 +1,23 @@
1
+ async function removePullRequestHistory(
2
+ getReleaseHistory,
3
+ removeReleaseHistory,
4
+ app,
5
+ prNumber,
6
+ platform
7
+ ) {
8
+ const releaseHistory = await getReleaseHistory(app, prNumber, platform)
9
+
10
+ if (!releaseHistory) {
11
+ console.error(`v${prNumber} is already removed or is not released.`)
12
+ process.exit(1)
13
+ }
14
+
15
+ try {
16
+ await removeReleaseHistory(app, prNumber, platform)
17
+ } catch (error) {
18
+ console.error('Error occurred while removing history:', error)
19
+ process.exit(1)
20
+ }
21
+ }
22
+
23
+ module.exports = { removePullRequestHistory }
package/cli/index.js CHANGED
@@ -40,4 +40,24 @@ require('./commands/releaseCommand')
40
40
  */
41
41
  require('./commands/showHistoryCommand')
42
42
 
43
+ /**
44
+ * npx code-push create-pr-history
45
+ */
46
+ require('./commands/createPullRequestHistoryCommand')
47
+
48
+ /**
49
+ * npx code-push create-pr-release
50
+ */
51
+ require('./commands/createPullRequestReleaseCommand')
52
+
53
+ /**
54
+ * npx code-push remove-pr-history
55
+ */
56
+ require('./commands/removePullRequestHistoryCommand')
57
+
58
+ /**
59
+ * npx code-push get-development-key
60
+ */
61
+ require('./commands/getDevelopmentKeyCommand')
62
+
43
63
  program.parse()
@@ -1,7 +1,11 @@
1
1
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
2
  // @ts-nocheck
3
3
 
4
- const { S3Client, PutObjectCommand } = require('@aws-sdk/client-s3')
4
+ const {
5
+ S3Client,
6
+ PutObjectCommand,
7
+ DeleteObjectCommand,
8
+ } = require('@aws-sdk/client-s3')
5
9
  const fs = require('fs')
6
10
  const axios = require('axios')
7
11
  require('dotenv').config()
@@ -60,7 +64,6 @@ const Config = {
60
64
  const { data } = await axios.get(`${CDN_URL}/${remoteJsonPath}`)
61
65
  return data
62
66
  },
63
-
64
67
  setReleaseHistory: async (
65
68
  targetBinaryVersion,
66
69
  jsonFilePath,
@@ -143,6 +146,25 @@ const Config = {
143
146
  throw error
144
147
  }
145
148
  },
149
+ removeReleaseHistory: async (app, targetBinaryVersion, platform) => {
150
+ const remoteJsonPath = historyJsonFileRemotePath(
151
+ app,
152
+ platform,
153
+ targetBinaryVersion
154
+ )
155
+ try {
156
+ await s3Client.send(
157
+ new DeleteObjectCommand({
158
+ Bucket: BUCKET_NAME,
159
+ Key: remoteJsonPath,
160
+ })
161
+ )
162
+
163
+ console.log('Release history removed:', `${CDN_URL}/${remoteJsonPath}`)
164
+ } catch (error) {
165
+ console.error('Error removing release history:', error)
166
+ }
167
+ },
146
168
  }
147
169
 
148
170
  module.exports = Config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algocare/react-native-code-push",
3
- "version": "10.1.0",
3
+ "version": "10.3.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",