@algocare/react-native-code-push 12.1.1 → 12.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.
@@ -8,7 +8,7 @@ async function getAppValue() {
8
8
  type: 'list',
9
9
  name: 'app',
10
10
  message: 'Select the target app',
11
- choices: ['user', 'device'],
11
+ choices: ['user', 'device', 'b2c-device'],
12
12
  },
13
13
  ])
14
14
  return app
@@ -21,10 +21,10 @@ async function getPlatformValue(app) {
21
21
  name: 'platform',
22
22
  message: 'Select the target platform',
23
23
  choices: ['ios', 'android'],
24
- when: () => app !== 'device',
24
+ when: () => app === 'user',
25
25
  },
26
26
  ])
27
- return app === 'device' ? 'android' : platformAnswer.platform
27
+ return app === 'user' ? platformAnswer.platform : 'android'
28
28
  }
29
29
 
30
30
  async function getIdentifierValue() {
@@ -157,7 +157,7 @@ async function getAppVersionValueFromList(
157
157
  ])
158
158
  appVersion = appVersionAnswer.appVersion
159
159
  } else {
160
- appVersion = appVersionSelectionAnswer.appVersion
160
+ appVersion = appVersionSelectionAnswer.appVersionChoice
161
161
  }
162
162
 
163
163
  return appVersion
@@ -13,26 +13,63 @@ const {
13
13
  program
14
14
  .command('create-history')
15
15
  .description('Creates a new release history for the binary app.')
16
+ .option('-a, --app <string>', 'target app (user/device/b2c-device)')
17
+ .option('-p, --platform <string>', 'target platform (ios/android)')
18
+ .option('-i, --identifier <string>', 'target env identifier (dev/stg/prd)')
19
+ .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
16
20
  .option(
17
21
  '-c, --config <path>',
18
22
  'set config file name (JS/TS)',
19
23
  COMPILED_CONFIG_FILE_NAME
20
24
  )
21
25
  .action(async (options) => {
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 getBinaryVersionValueFromInput(
31
- config.getBinaryVersionList,
32
- app,
33
- platform,
34
- identifier
35
- )
26
+ if (
27
+ options.app &&
28
+ !['user', 'device', 'b2c-device'].includes(options.app)
29
+ ) {
30
+ throw new Error('App must be either "user" or "device" or "b2c-device"')
31
+ }
32
+
33
+ if (options.platform && !['ios', 'android'].includes(options.platform)) {
34
+ throw new Error('Platform must be either "ios" or "android"')
35
+ }
36
+
37
+ if (options.app !== 'user' && options.platform === 'ios') {
38
+ throw new Error('Device app is not supported on iOS')
39
+ }
40
+
41
+ if (
42
+ options.identifier &&
43
+ !['dev', 'stg', 'prd'].includes(options.identifier)
44
+ ) {
45
+ throw new Error('Identifier must be either "dev" or "stg" or "prd"')
46
+ }
47
+
48
+ const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
49
+ if (options.binaryVersion && !semverRegex.test(options.binaryVersion)) {
50
+ throw new Error('Binary version must be a valid semver format (x.y.z)')
51
+ }
52
+
53
+ const { setReleaseHistory, getBinaryVersionList, setBinaryVersionList } =
54
+ await findAndReadConfigFile(process.cwd(), options.config)
55
+
56
+ const app = options.app || (await getAppValue())
57
+
58
+ const platform =
59
+ options.platform ||
60
+ (app !== 'user' && 'android') ||
61
+ (await getPlatformValue(app))
62
+
63
+ const identifier = options.identifier || (await getIdentifierValue())
64
+
65
+ const binaryVersion =
66
+ options.binaryVersion ||
67
+ (await getBinaryVersionValueFromInput(
68
+ getBinaryVersionList,
69
+ app,
70
+ platform,
71
+ identifier
72
+ ))
36
73
 
37
74
  const answers = {
38
75
  app,
@@ -44,7 +81,7 @@ program
44
81
  await createReleaseHistory(
45
82
  answers.app,
46
83
  answers.binaryVersion,
47
- config.setReleaseHistory,
84
+ setReleaseHistory,
48
85
  answers.platform
49
86
  )
50
87
 
@@ -52,7 +89,7 @@ program
52
89
  answers.app,
53
90
  answers.binaryVersion,
54
91
  answers.platform,
55
- config.getBinaryVersionList,
56
- config.setBinaryVersionList
92
+ getBinaryVersionList,
93
+ setBinaryVersionList
57
94
  )
58
95
  })
@@ -1,5 +1,6 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs')
3
+ const { getTimestamp } = require('../../utils/datetime')
3
4
 
4
5
  async function addToPullRequestRelease(
5
6
  app,
@@ -32,6 +33,7 @@ async function addToPullRequestRelease(
32
33
  mandatory,
33
34
  downloadUrl: bundleDownloadUrl,
34
35
  packageHash,
36
+ createdAt: getTimestamp(),
35
37
  }
36
38
 
37
39
  try {
@@ -1,5 +1,6 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs')
3
+ const { getTimestamp } = require('../../utils/datetime')
3
4
 
4
5
  /**
5
6
  * @param app {"user" | "device"}
@@ -52,6 +53,8 @@ async function addToReleaseHistory(
52
53
  mandatory: mandatory,
53
54
  downloadUrl: bundleDownloadUrl,
54
55
  packageHash: packageHash,
56
+ createdAt: getTimestamp(),
57
+ updatedAt: '-',
55
58
  }
56
59
 
57
60
  try {
@@ -20,7 +20,7 @@ program
20
20
  .description(
21
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.'
22
22
  )
23
- .option('-a, --app <string>', 'target app (user/device)')
23
+ .option('-a, --app <string>', 'target app (user/device/b2c-device)')
24
24
  .option('-p, --platform <string>', 'target platform (ios/android)')
25
25
  .option('-i, --identifier <string>', 'target env identifier (dev/stg/prd)')
26
26
  .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
@@ -55,15 +55,18 @@ program
55
55
  OUTPUT_BUNDLE_DIR
56
56
  )
57
57
  .action(async (options) => {
58
- if (options.app && !['user', 'device'].includes(options.app)) {
59
- throw new Error('App must be either "user" or "device"')
58
+ if (
59
+ options.app &&
60
+ !['user', 'device', 'b2c-device'].includes(options.app)
61
+ ) {
62
+ throw new Error('App must be either "user" or "device" or "b2c-device"')
60
63
  }
61
64
 
62
65
  if (options.platform && !['ios', 'android'].includes(options.platform)) {
63
66
  throw new Error('Platform must be either "ios" or "android"')
64
67
  }
65
68
 
66
- if (options.app === 'device' && options.platform === 'ios') {
69
+ if (options.app !== 'user' && options.platform === 'ios') {
67
70
  throw new Error('Device app is not supported on iOS')
68
71
  }
69
72
 
@@ -83,7 +86,6 @@ program
83
86
  throw new Error('App version must be a valid semver format (x.y.z)')
84
87
  }
85
88
 
86
- let answers = {}
87
89
  const {
88
90
  bundleUploader,
89
91
  getReleaseHistory,
@@ -91,49 +93,39 @@ program
91
93
  getBinaryVersionList,
92
94
  } = await findAndReadConfigFile(process.cwd(), options.config)
93
95
 
94
- if (
95
- options.app &&
96
- options.identifier &&
97
- options.binaryVersion &&
98
- options.appVersion &&
99
- (options.app === 'device' || options.platform)
100
- ) {
101
- answers = {
102
- app: options.app,
103
- platform: options.platform || (options.app === 'device' && 'android'),
104
- identifier: options.identifier,
105
- binaryVersion: options.binaryVersion,
106
- appVersion: options.appVersion,
107
- }
108
- } else {
109
- // app
110
- const app = await getAppValue()
111
- // platform
112
- const platform = await getPlatformValue(app)
113
- // identifier
114
- const identifier = await getIdentifierValue()
115
- // binaryVersion
116
- const binaryVersion = await getBinaryVersionValueFromInput(
96
+ const app = options.app || (await getAppValue())
97
+
98
+ const platform =
99
+ options.platform ||
100
+ (app !== 'user' && 'android') ||
101
+ (await getPlatformValue(app))
102
+
103
+ const identifier = options.identifier || (await getIdentifierValue())
104
+
105
+ const binaryVersion =
106
+ options.binaryVersion ||
107
+ (await getBinaryVersionValueFromInput(
117
108
  getBinaryVersionList,
118
109
  app,
119
110
  platform,
120
111
  identifier
121
- )
122
- // appVersion
123
- const appVersion = await getAppVersionValueFromInput(
112
+ ))
113
+
114
+ const appVersion =
115
+ options.appVersion ||
116
+ (await getAppVersionValueFromInput(
124
117
  getReleaseHistory,
125
118
  binaryVersion,
126
119
  app,
127
120
  platform
128
- )
121
+ ))
129
122
 
130
- answers = {
131
- app,
132
- platform,
133
- identifier,
134
- binaryVersion,
135
- appVersion,
136
- }
123
+ const answers = {
124
+ app,
125
+ platform,
126
+ identifier,
127
+ binaryVersion,
128
+ appVersion,
137
129
  }
138
130
 
139
131
  await release(
@@ -13,26 +13,63 @@ program
13
13
  .description(
14
14
  'Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.'
15
15
  )
16
+ .option('-a, --app <string>', 'target app (user/device/b2c-device)')
17
+ .option('-p, --platform <string>', 'target platform (ios/android)')
18
+ .option('-i, --identifier <string>', 'target env identifier (dev/stg/prd)')
19
+ .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
16
20
  .option(
17
21
  '-c, --config <path>',
18
22
  'configuration file name (JS/TS)',
19
23
  COMPILED_CONFIG_FILE_NAME
20
24
  )
21
25
  .action(async (options) => {
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 getBinaryVersionValueFromList(
31
- config.getBinaryVersionList,
32
- app,
33
- platform,
34
- identifier
35
- )
26
+ if (
27
+ options.app &&
28
+ !['user', 'device', 'b2c-device'].includes(options.app)
29
+ ) {
30
+ throw new Error('App must be either "user" or "device" or "b2c-device"')
31
+ }
32
+
33
+ if (options.platform && !['ios', 'android'].includes(options.platform)) {
34
+ throw new Error('Platform must be either "ios" or "android"')
35
+ }
36
+
37
+ if (options.app !== 'user' && options.platform === 'ios') {
38
+ throw new Error('Device app is not supported on iOS')
39
+ }
40
+
41
+ if (
42
+ options.identifier &&
43
+ !['dev', 'stg', 'prd'].includes(options.identifier)
44
+ ) {
45
+ throw new Error('Identifier must be either "dev" or "stg" or "prd"')
46
+ }
47
+
48
+ const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
49
+ if (options.binaryVersion && !semverRegex.test(options.binaryVersion)) {
50
+ throw new Error('Binary version must be a valid semver format (x.y.z)')
51
+ }
52
+
53
+ const { getBinaryVersionList, getReleaseHistory } =
54
+ await findAndReadConfigFile(process.cwd(), options.config)
55
+
56
+ const app = options.app || (await getAppValue())
57
+
58
+ const platform =
59
+ options.platform ||
60
+ (app !== 'user' && 'android') ||
61
+ (await getPlatformValue(app))
62
+
63
+ const identifier = options.identifier || (await getIdentifierValue())
64
+
65
+ const binaryVersion =
66
+ options.binaryVersion ||
67
+ (await getBinaryVersionValueFromList(
68
+ getBinaryVersionList,
69
+ app,
70
+ platform,
71
+ identifier
72
+ ))
36
73
 
37
74
  const answers = {
38
75
  app,
@@ -41,7 +78,7 @@ program
41
78
  binaryVersion,
42
79
  }
43
80
 
44
- const releaseHistory = await config.getReleaseHistory(
81
+ const releaseHistory = await getReleaseHistory(
45
82
  answers.app,
46
83
  answers.binaryVersion,
47
84
  answers.platform
@@ -15,6 +15,11 @@ program
15
15
  .description(
16
16
  'Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.'
17
17
  )
18
+ .option('-a, --app <string>', 'target app (user/device/b2c-device)')
19
+ .option('-p, --platform <string>', 'target platform (ios/android)')
20
+ .option('-i, --identifier <string>', 'target env identifier (dev/stg/prd)')
21
+ .option('-b, --binary-version <string>', 'target binary version (x.y.z)')
22
+ .option('-v, --app-version <string>', 'target codepush version (x.y.z)')
18
23
  .option(
19
24
  '-c, --config <path>',
20
25
  'set config file name (JS/TS)',
@@ -28,27 +33,66 @@ program
28
33
  )
29
34
  .option('--no-enable', 'make the release to be disabled')
30
35
  .action(async (options) => {
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 getBinaryVersionValueFromList(
40
- config.getBinaryVersionList,
41
- app,
42
- platform,
43
- identifier
44
- )
45
- // appVersion
46
- const appVersion = await getAppVersionValueFromList(
47
- config.getReleaseHistory,
48
- binaryVersion,
49
- app,
50
- platform
51
- )
36
+ if (
37
+ options.app &&
38
+ !['user', 'device', 'b2c-device'].includes(options.app)
39
+ ) {
40
+ throw new Error('App must be either "user" or "device" or "b2c-device"')
41
+ }
42
+
43
+ if (options.platform && !['ios', 'android'].includes(options.platform)) {
44
+ throw new Error('Platform must be either "ios" or "android"')
45
+ }
46
+
47
+ if (options.app !== 'user' && options.platform === 'ios') {
48
+ throw new Error('Device app is not supported on iOS')
49
+ }
50
+
51
+ if (
52
+ options.identifier &&
53
+ !['dev', 'stg', 'prd'].includes(options.identifier)
54
+ ) {
55
+ throw new Error('Identifier must be either "dev" or "stg" or "prd"')
56
+ }
57
+
58
+ const semverRegex = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/
59
+ if (options.binaryVersion && !semverRegex.test(options.binaryVersion)) {
60
+ throw new Error('Binary version must be a valid semver format (x.y.z)')
61
+ }
62
+
63
+ if (options.appVersion && !semverRegex.test(options.appVersion)) {
64
+ throw new Error('App version must be a valid semver format (x.y.z)')
65
+ }
66
+
67
+ const { getBinaryVersionList, getReleaseHistory, setReleaseHistory } =
68
+ await findAndReadConfigFile(process.cwd(), options.config)
69
+
70
+ const app = options.app || (await getAppValue())
71
+
72
+ const platform =
73
+ options.platform ||
74
+ (app !== 'user' && 'android') ||
75
+ (await getPlatformValue(app))
76
+
77
+ const identifier = options.identifier || (await getIdentifierValue())
78
+
79
+ const binaryVersion =
80
+ options.binaryVersion ||
81
+ (await getBinaryVersionValueFromList(
82
+ getBinaryVersionList,
83
+ app,
84
+ platform,
85
+ identifier
86
+ ))
87
+
88
+ const appVersion =
89
+ options.appVersion ||
90
+ (await getAppVersionValueFromList(
91
+ getReleaseHistory,
92
+ binaryVersion,
93
+ app,
94
+ platform
95
+ ))
52
96
 
53
97
  const answers = {
54
98
  app,
@@ -70,8 +114,8 @@ program
70
114
  answers.app,
71
115
  answers.appVersion,
72
116
  answers.binaryVersion,
73
- config.getReleaseHistory,
74
- config.setReleaseHistory,
117
+ getReleaseHistory,
118
+ setReleaseHistory,
75
119
  answers.platform,
76
120
  options.mandatory,
77
121
  options.enable
@@ -1,6 +1,6 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
-
3
+ const { getTimestamp } = require('../../utils/datetime')
4
4
  /**
5
5
  * @param app {"user" | "device"}
6
6
  * @param appVersion {string}
@@ -35,10 +35,11 @@ async function updateReleaseHistory(
35
35
  const releaseHistory = await getReleaseHistory(app, binaryVersion, platform)
36
36
 
37
37
  const updateInfo = releaseHistory[appVersion]
38
- if (!updateInfo) throw new Error(`v${appVersion} is not released`)
38
+ if (!updateInfo) throw new Error(`${appVersion} is not released`)
39
39
 
40
40
  if (typeof mandatory === 'boolean') updateInfo.mandatory = mandatory
41
41
  if (typeof enable === 'boolean') updateInfo.enabled = enable
42
+ updateInfo.updatedAt = getTimestamp()
42
43
 
43
44
  try {
44
45
  const JSON_FILE_NAME = `${binaryVersion}.json`
@@ -0,0 +1,22 @@
1
+ const getTimestamp = () => {
2
+ const date = new Date()
3
+ const year = date.getFullYear()
4
+ const month = padWithZero(date.getMonth() + 1)
5
+ const day = padWithZero(date.getDate())
6
+ const hour = padWithZero(date.getHours())
7
+ const minute = padWithZero(date.getMinutes())
8
+ const second = padWithZero(date.getSeconds())
9
+
10
+ return `${year}-${month}-${day} ${hour}:${minute}:${second}`
11
+ }
12
+
13
+ const padWithZero = (value) => {
14
+ if (value < 10) {
15
+ return `0${value}`
16
+ }
17
+ return value
18
+ }
19
+
20
+ module.exports = {
21
+ getTimestamp,
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@algocare/react-native-code-push",
3
- "version": "12.1.1",
3
+ "version": "12.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",