@algocare/react-native-code-push 9.0.0 → 10.0.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,259 @@
1
+ const inquirer = require('inquirer').default
2
+ const { getBinaryVersions, getAppVersions } = require('../utils/version')
3
+ const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
4
+
5
+ async function getAppValue() {
6
+ const { app } = await inquirer.prompt([
7
+ {
8
+ type: 'list',
9
+ name: 'app',
10
+ message: 'Select the target app',
11
+ choices: ['user', 'device'],
12
+ },
13
+ ])
14
+ return app
15
+ }
16
+
17
+ async function getPlatformValue(app) {
18
+ const platformAnswer = await inquirer.prompt([
19
+ {
20
+ type: 'list',
21
+ name: 'platform',
22
+ message: 'Select the target platform',
23
+ choices: ['ios', 'android'],
24
+ when: () => app !== 'device',
25
+ },
26
+ ])
27
+ return app === 'device' ? 'android' : platformAnswer.platform
28
+ }
29
+
30
+ async function getIdentifierValue() {
31
+ const { identifier } = await inquirer.prompt([
32
+ {
33
+ type: 'list',
34
+ name: 'identifier',
35
+ message: 'Select the target env identifier',
36
+ choices: ['stg', 'prd'],
37
+ },
38
+ ])
39
+ return identifier
40
+ }
41
+
42
+ async function getBinaryVersionValue(
43
+ getBinaryVersionList,
44
+ app,
45
+ platform,
46
+ identifier,
47
+ count = 5
48
+ ) {
49
+ const [currentBinaryVersionList] = await getBinaryVersions(
50
+ getBinaryVersionList,
51
+ app,
52
+ platform,
53
+ identifier
54
+ )
55
+
56
+ if (!currentBinaryVersionList.length) {
57
+ console.log('There is no binary version list')
58
+ return []
59
+ }
60
+
61
+ if (typeof count !== 'number' || count < 1) {
62
+ console.warn('count must be a number and greater than 1')
63
+ return []
64
+ }
65
+
66
+ const latestBinaryVersion = currentBinaryVersionList.slice(-count)
67
+ const binaryVersionChoices = [
68
+ ...latestBinaryVersion,
69
+ new inquirer.Separator(),
70
+ 'Enter manually',
71
+ ]
72
+ const binaryVersionSelectionAnswer = await inquirer.prompt([
73
+ {
74
+ type: 'list',
75
+ name: 'versionChoice',
76
+ message:
77
+ 'This is last 5 versions. Select a binary version or enter manually',
78
+ choices: binaryVersionChoices,
79
+ },
80
+ ])
81
+ let binaryVersion
82
+ if (binaryVersionSelectionAnswer.versionChoice === 'Enter manually') {
83
+ const binaryVersionAnswer = await inquirer.prompt([
84
+ {
85
+ type: 'input',
86
+ name: 'binaryVersion',
87
+ message: 'Enter the target binary version',
88
+ validate: (input) => {
89
+ if (!semverRegex.test(input)) {
90
+ return 'Please enter a valid version number (x.y.z)'
91
+ }
92
+ if (currentBinaryVersionList.includes(input)) {
93
+ return `Version ${input} already exists`
94
+ }
95
+ return true
96
+ },
97
+ },
98
+ ])
99
+ binaryVersion = binaryVersionAnswer.binaryVersion
100
+ } else {
101
+ binaryVersion = binaryVersionSelectionAnswer.versionChoice
102
+ }
103
+
104
+ return binaryVersion
105
+ }
106
+
107
+ async function getBinaryVersionValueForInput(
108
+ getBinaryVersionList,
109
+ app,
110
+ platform,
111
+ identifier
112
+ ) {
113
+ const [currentBinaryVersionList, lastBinaryVersion] = await getBinaryVersions(
114
+ getBinaryVersionList,
115
+ app,
116
+ platform,
117
+ identifier
118
+ )
119
+
120
+ const message = lastBinaryVersion
121
+ ? `Enter the target binary version (current latest: ${lastBinaryVersion})`
122
+ : 'Enter the target binary version (there is no latest version)'
123
+
124
+ const { binaryVersion } = await inquirer.prompt([
125
+ {
126
+ type: 'input',
127
+ name: 'binaryVersion',
128
+ message,
129
+ validate: (input) => {
130
+ const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
131
+ if (!semverRegex.test(input)) {
132
+ return 'Please enter a valid version number (x.y.z)'
133
+ }
134
+ if (currentBinaryVersionList.includes(input)) {
135
+ return `Version ${input} already exists`
136
+ }
137
+ return true
138
+ },
139
+ },
140
+ ])
141
+
142
+ return binaryVersion
143
+ }
144
+
145
+ async function getAppVersionValue(
146
+ getReleaseHistory,
147
+ binaryVersion,
148
+ app,
149
+ platform,
150
+ identifier,
151
+ count = 5
152
+ ) {
153
+ const [currentAppVersionList] = await getAppVersions(
154
+ getReleaseHistory,
155
+ binaryVersion,
156
+ app,
157
+ platform,
158
+ identifier
159
+ )
160
+
161
+ if (!currentAppVersionList.length) {
162
+ console.log('There is no app version list')
163
+ return
164
+ }
165
+
166
+ if (typeof count !== 'number' || count < 1) {
167
+ console.warn('count must be a number and greater than 1')
168
+ return
169
+ }
170
+
171
+ const latestAppVersion = currentAppVersionList.slice(-count)
172
+ const appVersionChoices = [
173
+ ...latestAppVersion,
174
+ new inquirer.Separator(),
175
+ 'Enter manually',
176
+ ]
177
+ const appVersionSelectionAnswer = await inquirer.prompt([
178
+ {
179
+ type: 'list',
180
+ name: 'appVersionChoice',
181
+ message:
182
+ 'This is last 5 versions. Select a binary version or enter manually',
183
+ choices: appVersionChoices,
184
+ },
185
+ ])
186
+ let appVersion
187
+ if (appVersionSelectionAnswer.versionChoice === 'Enter manually') {
188
+ const appVersionAnswer = await inquirer.prompt([
189
+ {
190
+ type: 'input',
191
+ name: 'appVersion',
192
+ message: 'Enter the target app version',
193
+ validate: (input) => {
194
+ if (!semverRegex.test(input)) {
195
+ return 'Please enter a valid version number (x.y.z)'
196
+ }
197
+ if (currentAppVersionList.includes(input)) {
198
+ return `Version ${input} already exists`
199
+ }
200
+ return true
201
+ },
202
+ },
203
+ ])
204
+ appVersion = appVersionAnswer.appVersion
205
+ } else {
206
+ appVersion = appVersionSelectionAnswer.appVersion
207
+ }
208
+
209
+ return appVersion
210
+ }
211
+
212
+ async function getAppVersionValueForInput(
213
+ getReleaseHistory,
214
+ binaryVersion,
215
+ app,
216
+ platform,
217
+ identifier
218
+ ) {
219
+ const [currentAppVersionList, lastAppVersion] = await getAppVersions(
220
+ getReleaseHistory,
221
+ binaryVersion,
222
+ app,
223
+ platform,
224
+ identifier
225
+ )
226
+
227
+ const message = lastAppVersion
228
+ ? `Enter the target app version (current latest: ${lastAppVersion})`
229
+ : 'Enter the target app version (there is no latest version)'
230
+
231
+ const { appVersion } = await inquirer.prompt([
232
+ {
233
+ type: 'input',
234
+ name: 'appVersion',
235
+ message,
236
+ validate: (input) => {
237
+ if (!semverRegex.test(input)) {
238
+ return 'Please enter a valid version number (x.y.z)'
239
+ }
240
+ if (currentAppVersionList.includes(input)) {
241
+ return `Version ${input} already exists`
242
+ }
243
+ return true
244
+ },
245
+ },
246
+ ])
247
+
248
+ return appVersion
249
+ }
250
+
251
+ module.exports = {
252
+ getAppValue,
253
+ getPlatformValue,
254
+ getIdentifierValue,
255
+ getBinaryVersionValue,
256
+ getAppVersionValue,
257
+ getBinaryVersionValueForInput,
258
+ getAppVersionValueForInput,
259
+ }
@@ -23,19 +23,6 @@ async function createReleaseHistory(
23
23
  platform,
24
24
  identifier
25
25
  ) {
26
- const BINARY_RELEASE = {
27
- enabled: true,
28
- mandatory: false,
29
- downloadUrl: '',
30
- packageHash: '',
31
- }
32
-
33
- /** @type {ReleaseHistoryInterface} */
34
- // not use
35
- const INITIAL_HISTORY = {
36
- [targetVersion]: BINARY_RELEASE,
37
- }
38
-
39
26
  try {
40
27
  const JSON_FILE_NAME = `${targetVersion}.json`
41
28
  const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
@@ -0,0 +1,62 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ /**
5
+ * @param app {"user" | "device"}
6
+ * @param targetVersion {string}
7
+ * @param platform {"ios" | "android"}
8
+ * @param identifier {string}
9
+ * @param getBinaryVersionList {
10
+ * function(
11
+ * app: string,
12
+ * platform: string,
13
+ * identifier: string
14
+ * ): Promise<{ [version: string]: string }>
15
+ * }
16
+ * @param setBinaryVersionList {
17
+ * function(
18
+ * targetVersion: string,
19
+ * app: string,
20
+ * platform: string,
21
+ * identifier: string
22
+ * ): Promise<void>
23
+ * }
24
+ * @returns {Promise<void>}
25
+ */
26
+ async function createReleaseHistoryList(
27
+ app,
28
+ targetVersion,
29
+ platform,
30
+ identifier,
31
+ getBinaryVersionList,
32
+ setBinaryVersionList
33
+ ) {
34
+ try {
35
+ const JSON_FILE_NAME = 'list.json'
36
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
37
+
38
+ const currentList = await getBinaryVersionList(app, platform, identifier)
39
+
40
+ if (currentList[targetVersion]) {
41
+ console.error(`Version ${targetVersion} is already released`)
42
+ process.exit(1)
43
+ }
44
+
45
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(currentList))
46
+
47
+ await setBinaryVersionList(
48
+ targetVersion,
49
+ JSON_FILE_PATH,
50
+ app,
51
+ platform,
52
+ identifier
53
+ )
54
+
55
+ fs.unlinkSync(JSON_FILE_PATH)
56
+ } catch (error) {
57
+ console.error('Error occurred while creating new history list:', error)
58
+ process.exit(1)
59
+ }
60
+ }
61
+
62
+ module.exports = { createReleaseHistoryList }
@@ -1,8 +1,14 @@
1
1
  const { program } = require('commander')
2
- const inquirer = require('inquirer').default
3
2
  const { findAndReadConfigFile } = require('../../utils/fsUtils')
4
3
  const { createReleaseHistory } = require('./createReleaseHistory')
4
+ const { createReleaseHistoryList } = require('./createReleaseHistoryList')
5
5
  const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
6
+ const {
7
+ getAppValue,
8
+ getPlatformValue,
9
+ getIdentifierValue,
10
+ getBinaryVersionValueForInput,
11
+ } = require('../common')
6
12
 
7
13
  program
8
14
  .command('create-history')
@@ -13,44 +19,28 @@ program
13
19
  COMPILED_CONFIG_FILE_NAME
14
20
  )
15
21
  .action(async (options) => {
16
- const answers = await inquirer.prompt([
17
- {
18
- type: 'list',
19
- name: 'app',
20
- message: 'Select the target app',
21
- choices: ['user', 'device'],
22
- },
23
- {
24
- type: 'list',
25
- name: 'platform',
26
- message: 'Select the target platform',
27
- choices: ['ios', 'android'],
28
- when: (answers) => answers.app !== 'device',
29
- },
30
- {
31
- type: 'list',
32
- name: 'identifier',
33
- message: 'Select the target env identifier',
34
- choices: ['stg', 'prd'],
35
- },
36
- {
37
- type: 'input',
38
- name: 'binaryVersion',
39
- message: 'Enter the target binary version',
40
- validate: (input) => {
41
- const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
42
- if (semverRegex.test(input)) return true
43
- return 'Please enter a valid version number (x.y.z)'
44
- },
45
- },
46
- ])
22
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
23
+ // app
24
+ const app = await getAppValue()
25
+ // platform
26
+ const platform = await getPlatformValue(app)
27
+ // identifier
28
+ const identifier = await getIdentifierValue()
29
+ // binaryVersion
30
+ const binaryVersion = await getBinaryVersionValueForInput(
31
+ config.getBinaryVersionList,
32
+ app,
33
+ platform,
34
+ identifier
35
+ )
47
36
 
48
- if (answers.app === 'device') {
49
- answers.platform = 'android'
37
+ const answers = {
38
+ app,
39
+ platform,
40
+ identifier,
41
+ binaryVersion,
50
42
  }
51
43
 
52
- const config = await findAndReadConfigFile(process.cwd(), options.config)
53
-
54
44
  await createReleaseHistory(
55
45
  answers.app,
56
46
  answers.binaryVersion,
@@ -58,4 +48,13 @@ program
58
48
  answers.platform,
59
49
  answers.identifier
60
50
  )
51
+
52
+ await createReleaseHistoryList(
53
+ answers.app,
54
+ answers.binaryVersion,
55
+ answers.platform,
56
+ answers.identifier,
57
+ config.getBinaryVersionList,
58
+ config.setBinaryVersionList
59
+ )
61
60
  })
@@ -1,5 +1,4 @@
1
1
  const { program } = require('commander')
2
- const inquirer = require('inquirer').default
3
2
  const { findAndReadConfigFile } = require('../../utils/fsUtils')
4
3
  const { release } = require('./release')
5
4
  const {
@@ -8,12 +7,24 @@ const {
8
7
  ROOT_OUTPUT_DIR,
9
8
  ENTRY_FILE,
10
9
  } = require('../../constant')
10
+ const {
11
+ getAppValue,
12
+ getPlatformValue,
13
+ getIdentifierValue,
14
+ getBinaryVersionValueForInput,
15
+ getAppVersionValueForInput,
16
+ } = require('../common')
11
17
 
12
18
  program
13
19
  .command('release')
14
20
  .description(
15
21
  '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.'
16
22
  )
23
+ .option('-a, --app <string>', 'target app (user/device)')
24
+ .option('-p, --platform <string>', 'target platform (ios/android)')
25
+ .option('-i, --identifier <string>', 'target env identifier (stg/prd)')
26
+ .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
27
+ .option('-v, --app-version <string>', 'target codepush version (x.y.z)')
17
28
  .option(
18
29
  '-c, --config <path>',
19
30
  'set config file name (JS/TS)',
@@ -44,58 +55,89 @@ program
44
55
  OUTPUT_BUNDLE_DIR
45
56
  )
46
57
  .action(async (options) => {
47
- const answers = await inquirer.prompt([
48
- {
49
- type: 'list',
50
- name: 'app',
51
- message: 'Select the target app',
52
- choices: ['user', 'device'],
53
- },
54
- {
55
- type: 'list',
56
- name: 'platform',
57
- message: 'Select the target platform',
58
- choices: ['ios', 'android'],
59
- when: (answers) => answers.app !== 'device',
60
- },
61
- {
62
- type: 'list',
63
- name: 'identifier',
64
- message: 'Select the target env identifier',
65
- choices: ['stg', 'prd'],
66
- },
67
- {
68
- type: 'input',
69
- name: 'binaryVersion',
70
- message: 'Enter the target binary version',
71
- validate: (input) => {
72
- const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
73
- if (semverRegex.test(input)) return true
74
- return 'Please enter a valid version number (x.y.z)'
75
- },
76
- },
77
- {
78
- type: 'input',
79
- name: 'appVersion',
80
- message: 'Enter the target codepush version',
81
- validate: (input) => {
82
- const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
83
- if (semverRegex.test(input)) return true
84
- return 'Please enter a valid version number (x.y.z)'
85
- },
86
- },
87
- ])
58
+ if (options.app && !['user', 'device'].includes(options.app)) {
59
+ throw new Error('App must be either "user" or "device"')
60
+ }
61
+
62
+ if (options.platform && !['ios', 'android'].includes(options.platform)) {
63
+ throw new Error('Platform must be either "ios" or "android"')
64
+ }
88
65
 
89
- if (answers.app === 'device') {
90
- answers.platform = 'android'
66
+ if (options.app === 'device' && options.platform === 'ios') {
67
+ throw new Error('Device app is not supported on iOS')
91
68
  }
92
69
 
93
- const config = await findAndReadConfigFile(process.cwd(), options.config)
70
+ if (options.identifier && !['stg', 'prd'].includes(options.identifier)) {
71
+ throw new Error('Identifier must be either "stg" or "prd"')
72
+ }
73
+
74
+ const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
75
+ if (options.binaryVersion && !semverRegex.test(options.binaryVersion)) {
76
+ throw new Error('Binary version must be a valid semver format (x.y.z)')
77
+ }
78
+
79
+ if (options.appVersion && !semverRegex.test(options.appVersion)) {
80
+ throw new Error('App version must be a valid semver format (x.y.z)')
81
+ }
82
+
83
+ let answers = {}
84
+ const {
85
+ bundleUploader,
86
+ getReleaseHistory,
87
+ setReleaseHistory,
88
+ getBinaryVersionList,
89
+ } = await findAndReadConfigFile(process.cwd(), options.config)
90
+
91
+ if (
92
+ options.app &&
93
+ options.identifier &&
94
+ options.binaryVersion &&
95
+ options.appVersion &&
96
+ (options.app === 'device' || options.platform)
97
+ ) {
98
+ answers = {
99
+ app: options.app,
100
+ platform: options.platform || (options.app === 'device' && 'android'),
101
+ identifier: options.identifier,
102
+ binaryVersion: options.binaryVersion,
103
+ appVersion: options.appVersion,
104
+ }
105
+ } else {
106
+ // app
107
+ const app = await getAppValue()
108
+ // platform
109
+ const platform = await getPlatformValue(app)
110
+ // identifier
111
+ const identifier = await getIdentifierValue()
112
+ // binaryVersion
113
+ const binaryVersion = await getBinaryVersionValueForInput(
114
+ getBinaryVersionList,
115
+ app,
116
+ platform,
117
+ identifier
118
+ )
119
+ // appVersion
120
+ const appVersion = await getAppVersionValueForInput(
121
+ getReleaseHistory,
122
+ binaryVersion,
123
+ app,
124
+ platform,
125
+ identifier
126
+ )
127
+
128
+ answers = {
129
+ app,
130
+ platform,
131
+ identifier,
132
+ binaryVersion,
133
+ appVersion,
134
+ }
135
+ }
94
136
 
95
137
  await release(
96
- config.bundleUploader,
97
- config.getReleaseHistory,
98
- config.setReleaseHistory,
138
+ bundleUploader,
139
+ getReleaseHistory,
140
+ setReleaseHistory,
99
141
  answers.app,
100
142
  answers.binaryVersion,
101
143
  answers.appVersion,
@@ -1,7 +1,12 @@
1
1
  const { program } = require('commander')
2
- const inquirer = require('inquirer').default
3
2
  const { findAndReadConfigFile } = require('../../utils/fsUtils')
4
3
  const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
4
+ const {
5
+ getAppValue,
6
+ getPlatformValue,
7
+ getIdentifierValue,
8
+ getBinaryVersionValue,
9
+ } = require('../common')
5
10
 
6
11
  program
7
12
  .command('show-history')
@@ -14,44 +19,28 @@ program
14
19
  COMPILED_CONFIG_FILE_NAME
15
20
  )
16
21
  .action(async (options) => {
17
- const answers = await inquirer.prompt([
18
- {
19
- type: 'list',
20
- name: 'app',
21
- message: 'Select the target app',
22
- choices: ['user', 'device'],
23
- },
24
- {
25
- type: 'list',
26
- name: 'platform',
27
- message: 'Select the target platform',
28
- choices: ['ios', 'android'],
29
- when: (answers) => answers.app !== 'device',
30
- },
31
- {
32
- type: 'list',
33
- name: 'identifier',
34
- message: 'Select the target env identifier',
35
- choices: ['stg', 'prd'],
36
- },
37
- {
38
- type: 'input',
39
- name: 'binaryVersion',
40
- message: 'Enter the target binary version',
41
- validate: (input) => {
42
- const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
43
- if (semverRegex.test(input)) return true
44
- return 'Please enter a valid version number (x.y.z)'
45
- },
46
- },
47
- ])
22
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
23
+ // app
24
+ const app = await getAppValue()
25
+ // platform
26
+ const platform = await getPlatformValue(app)
27
+ // identifier
28
+ const identifier = await getIdentifierValue()
29
+ // binaryVersion
30
+ const binaryVersion = await getBinaryVersionValue(
31
+ config.getBinaryVersionList,
32
+ app,
33
+ platform,
34
+ identifier
35
+ )
48
36
 
49
- if (answers.app === 'device') {
50
- answers.platform = 'android'
37
+ const answers = {
38
+ app,
39
+ platform,
40
+ identifier,
41
+ binaryVersion,
51
42
  }
52
43
 
53
- const config = await findAndReadConfigFile(process.cwd(), options.config)
54
-
55
44
  const releaseHistory = await config.getReleaseHistory(
56
45
  answers.app,
57
46
  answers.binaryVersion,
@@ -1,8 +1,14 @@
1
1
  const { program } = require('commander')
2
- const inquirer = require('inquirer').default
3
2
  const { findAndReadConfigFile } = require('../../utils/fsUtils')
4
3
  const { updateReleaseHistory } = require('./updateReleaseHistory')
5
4
  const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
5
+ const {
6
+ getAppValue,
7
+ getPlatformValue,
8
+ getIdentifierValue,
9
+ getBinaryVersionValue,
10
+ getAppVersionValue,
11
+ } = require('../common')
6
12
 
7
13
  program
8
14
  .command('update-history')
@@ -22,54 +28,37 @@ program
22
28
  )
23
29
  .option('--no-enable', 'make the release to be disabled')
24
30
  .action(async (options) => {
25
- const answers = await inquirer.prompt([
26
- {
27
- type: 'list',
28
- name: 'app',
29
- message: 'Select the target app',
30
- choices: ['user', 'device'],
31
- },
32
- {
33
- type: 'list',
34
- name: 'platform',
35
- message: 'Select the target platform',
36
- choices: ['ios', 'android'],
37
- when: (answers) => answers.app !== 'device',
38
- },
39
- {
40
- type: 'list',
41
- name: 'identifier',
42
- message: 'Select the target env identifier',
43
- choices: ['stg', 'prd'],
44
- },
45
- {
46
- type: 'input',
47
- name: 'binaryVersion',
48
- message: 'Enter the target binary version',
49
- validate: (input) => {
50
- const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
51
- if (semverRegex.test(input)) return true
52
- return 'Please enter a valid version number (x.y.z)'
53
- },
54
- },
55
- {
56
- type: 'input',
57
- name: 'appVersion',
58
- message: 'Enter the target codepush version',
59
- validate: (input) => {
60
- const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
61
- if (semverRegex.test(input)) return true
62
- return 'Please enter a valid version number (x.y.z)'
63
- },
64
- },
65
- ])
31
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
32
+ // app
33
+ const app = await getAppValue()
34
+ // platform
35
+ const platform = await getPlatformValue(app)
36
+ // identifier
37
+ const identifier = await getIdentifierValue()
38
+ // binaryVersion
39
+ const binaryVersion = await getBinaryVersionValue(
40
+ config.getBinaryVersionList,
41
+ app,
42
+ platform,
43
+ identifier
44
+ )
45
+ // appVersion
46
+ const appVersion = await getAppVersionValue(
47
+ config.getReleaseHistory,
48
+ binaryVersion,
49
+ app,
50
+ platform,
51
+ identifier
52
+ )
66
53
 
67
- if (answers.app === 'device') {
68
- answers.platform = 'android'
54
+ const answers = {
55
+ app,
56
+ platform,
57
+ identifier,
58
+ binaryVersion,
59
+ appVersion,
69
60
  }
70
61
 
71
- const config = await findAndReadConfigFile(process.cwd(), options.config)
72
-
73
62
  if (
74
63
  typeof options.mandatory !== 'boolean' &&
75
64
  typeof options.enable !== 'boolean'
@@ -0,0 +1,37 @@
1
+ async function getBinaryVersions(
2
+ getBinaryVersionList,
3
+ app,
4
+ platform,
5
+ identifier
6
+ ) {
7
+ const currentVersionList = await getBinaryVersionList(
8
+ app,
9
+ platform,
10
+ identifier
11
+ )
12
+ return [
13
+ Object.keys(currentVersionList),
14
+ Object.keys(currentVersionList).pop(),
15
+ ]
16
+ }
17
+
18
+ async function getAppVersions(
19
+ getReleaseHistory,
20
+ binaryVersion,
21
+ app,
22
+ platform,
23
+ identifier
24
+ ) {
25
+ const releaseHistory = await getReleaseHistory(
26
+ app,
27
+ binaryVersion,
28
+ platform,
29
+ identifier
30
+ )
31
+ return [Object.keys(releaseHistory), Object.keys(releaseHistory).pop()]
32
+ }
33
+
34
+ module.exports = {
35
+ getBinaryVersions,
36
+ getAppVersions,
37
+ }
@@ -63,7 +63,6 @@ const Config = {
63
63
  throw error
64
64
  }
65
65
  },
66
-
67
66
  getReleaseHistory: async (app, targetBinaryVersion, platform, identifier) => {
68
67
  const CDN_URL = getCDNUrl(identifier)
69
68
  const remoteJsonPath = historyJsonFileRemotePath(
@@ -112,6 +111,63 @@ const Config = {
112
111
  throw error
113
112
  }
114
113
  },
114
+ getBinaryVersionList: async (app, platform, identifier) => {
115
+ const CDN_URL = getCDNUrl(identifier)
116
+ const remoteJsonPath = `histories/${app}/${platform}/list.json`
117
+ let currentList = {}
118
+ try {
119
+ console.log('Getting existing version list file')
120
+ const { data } = await axios.get(`${CDN_URL}/${remoteJsonPath}`)
121
+ currentList = { ...data }
122
+ } catch (error) {
123
+ console.error(
124
+ 'Error occurred while getting existing version list file, maybe it is not exist.',
125
+ error.status
126
+ )
127
+ }
128
+ return currentList
129
+ },
130
+ setBinaryVersionList: async (
131
+ targetVersion,
132
+ jsonFilePath,
133
+ app,
134
+ platform,
135
+ identifier
136
+ ) => {
137
+ const remoteJsonPath = `histories/${app}/${platform}/list.json`
138
+ const BUCKET_NAME = getBucketName(identifier)
139
+ const CDN_URL = getCDNUrl(identifier)
140
+
141
+ const currentList = JSON.parse(fs.readFileSync(jsonFilePath, 'utf8'))
142
+ const targetVersionPath = historyJsonFileRemotePath(
143
+ app,
144
+ platform,
145
+ targetVersion
146
+ )
147
+ currentList[targetVersion] = `${CDN_URL}/${targetVersionPath}`
148
+
149
+ try {
150
+ await s3Client.send(
151
+ new PutObjectCommand({
152
+ Bucket: BUCKET_NAME,
153
+ Key: remoteJsonPath,
154
+ Body: JSON.stringify(currentList),
155
+ ContentType: 'application/json',
156
+ CacheControl: 'max-age=5',
157
+ })
158
+ )
159
+
160
+ console.log(
161
+ 'Binary version list uploaded:',
162
+ `${CDN_URL}/${remoteJsonPath}`,
163
+ '\nContent:',
164
+ JSON.stringify(currentList, null, 2)
165
+ )
166
+ } catch (error) {
167
+ console.error('Error uploading binary version list:', error)
168
+ throw error
169
+ }
170
+ },
115
171
  }
116
172
 
117
173
  module.exports = Config
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algocare/react-native-code-push",
3
- "version": "9.0.0",
3
+ "version": "10.0.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",