@algocare/react-native-code-push 9.0.0-beta.4 → 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,29 +1,52 @@
1
- const { program, Option } = require("commander");
2
- const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
- const { CONFIG_FILE_NAME } = require('../../constant');
1
+ const { program, Option } = require('commander')
2
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
3
+ const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
4
4
 
5
- program.command('show-history')
6
- .description('Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.')
7
- .requiredOption('-b, --binary-version <string>', '(Required) The target binary version for retrieving the release history.')
8
- .addOption(new Option('-p, --platform <type>', 'platform').choices(['ios', 'android']).default('ios'))
9
- .option('-i, --identifier <string>', 'reserved characters to distinguish the release.')
10
- .option('-c, --config <path>', 'configuration file name (JS/TS)', CONFIG_FILE_NAME)
11
- /**
12
- * @param {Object} options
13
- * @param {string} options.binaryVersion
14
- * @param {string} options.platform
15
- * @param {string} options.identifier
16
- * @param {string} options.config
17
- * @return {void}
18
- */
19
- .action(async (options) => {
20
- const config = findAndReadConfigFile(process.cwd(), options.config);
5
+ program
6
+ .command('show-history')
7
+ .description(
8
+ 'Retrieves and prints the release history of a specific binary version.\n`getReleaseHistory` function should be implemented in the config file.'
9
+ )
10
+ .requiredOption(
11
+ '-a, --app <string>',
12
+ '(Required) The target app: user or device'
13
+ )
14
+ .requiredOption(
15
+ '-b, --binary-version <string>',
16
+ '(Required) The target binary version for retrieving the release history.'
17
+ )
18
+ .addOption(
19
+ new Option('-p, --platform <type>', 'platform')
20
+ .choices(['ios', 'android'])
21
+ .default('ios')
22
+ )
23
+ .option(
24
+ '-i, --identifier <string>',
25
+ 'reserved characters to distinguish the release.'
26
+ )
27
+ .option(
28
+ '-c, --config <path>',
29
+ 'configuration file name (JS/TS)',
30
+ COMPILED_CONFIG_FILE_NAME
31
+ )
32
+ /**
33
+ * @param {Object} options
34
+ * @param {string} options.app
35
+ * @param {string} options.binaryVersion
36
+ * @param {string} options.platform
37
+ * @param {string} options.identifier
38
+ * @param {string} options.config
39
+ * @return {void}
40
+ */
41
+ .action(async (options) => {
42
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
21
43
 
22
- const releaseHistory = await config.getReleaseHistory(
23
- options.binaryVersion,
24
- options.platform,
25
- options.identifier
26
- );
44
+ const releaseHistory = await config.getReleaseHistory(
45
+ options.app,
46
+ options.binaryVersion,
47
+ options.platform,
48
+ options.identifier
49
+ )
27
50
 
28
- console.log(JSON.stringify(releaseHistory, null, 2));
29
- });
51
+ console.log(JSON.stringify(releaseHistory, null, 2))
52
+ })
@@ -1,50 +1,89 @@
1
- const { program, Option } = require("commander");
2
- const { findAndReadConfigFile } = require("../../utils/fsUtils");
3
- const { updateReleaseHistory } = require("./updateReleaseHistory");
4
- const { CONFIG_FILE_NAME } = require('../../constant');
1
+ const { program, Option } = require('commander')
2
+ const { findAndReadConfigFile } = require('../../utils/fsUtils')
3
+ const { updateReleaseHistory } = require('./updateReleaseHistory')
4
+ const { COMPILED_CONFIG_FILE_NAME } = require('../../constant')
5
5
 
6
- program.command('update-history')
7
- .description('Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.')
8
- .requiredOption('-v, --app-version <string>', '(Required) The app version for which update information is to be modified.')
9
- .requiredOption('-b, --binary-version <string>', '(Required) The target binary version of the app for which update information is to be modified.')
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('-m, --mandatory <bool>', 'make the release to be mandatory', parseBoolean, undefined)
14
- .option('-e, --enable <bool>', 'make the release to be enabled', parseBoolean, undefined)
15
- /**
16
- * @param {Object} options
17
- * @param {string} options.appVersion
18
- * @param {string} options.binaryVersion
19
- * @param {string} options.platform
20
- * @param {string} options.identifier
21
- * @param {string} options.config
22
- * @param {string} options.mandatory
23
- * @param {string} options.enable
24
- * @return {void}
25
- */
26
- .action(async (options) => {
27
- const config = findAndReadConfigFile(process.cwd(), options.config);
6
+ program
7
+ .command('update-history')
8
+ .description(
9
+ 'Updates the release history for a specific binary version.\n`getReleaseHistory`, `setReleaseHistory` functions should be implemented in the config file.'
10
+ )
11
+ .requiredOption(
12
+ '-a, --app <string>',
13
+ '(Required) The target app: user or device'
14
+ )
15
+ .requiredOption(
16
+ '-v, --app-version <string>',
17
+ '(Required) The app version for which update information is to be modified.'
18
+ )
19
+ .requiredOption(
20
+ '-b, --binary-version <string>',
21
+ '(Required) The target binary version of the app for which update information is to be modified.'
22
+ )
23
+ .addOption(
24
+ new Option('-p, --platform <type>', 'platform')
25
+ .choices(['ios', 'android'])
26
+ .default('ios')
27
+ )
28
+ .option(
29
+ '-i, --identifier <string>',
30
+ 'reserved characters to distinguish the release.'
31
+ )
32
+ .option(
33
+ '-c, --config <path>',
34
+ 'set config file name (JS/TS)',
35
+ COMPILED_CONFIG_FILE_NAME
36
+ )
37
+ .option(
38
+ '-m, --mandatory <bool>',
39
+ 'make the release to be mandatory',
40
+ parseBoolean,
41
+ undefined
42
+ )
43
+ .option(
44
+ '-e, --enable <bool>',
45
+ 'make the release to be enabled',
46
+ parseBoolean,
47
+ undefined
48
+ )
49
+ /**
50
+ * @param {Object} options
51
+ * @param {string} options.app
52
+ * @param {string} options.appVersion
53
+ * @param {string} options.binaryVersion
54
+ * @param {string} options.platform
55
+ * @param {string} options.identifier
56
+ * @param {string} options.config
57
+ * @param {string} options.mandatory
58
+ * @param {string} options.enable
59
+ * @return {void}
60
+ */
61
+ .action(async (options) => {
62
+ const config = await findAndReadConfigFile(process.cwd(), options.config)
28
63
 
29
- if (typeof options.mandatory !== "boolean" && typeof options.enable !== "boolean") {
30
- console.error('No options specified. Exiting the program.')
31
- process.exit(1)
32
- }
64
+ if (
65
+ typeof options.mandatory !== 'boolean' &&
66
+ typeof options.enable !== 'boolean'
67
+ ) {
68
+ console.error('No options specified. Exiting the program.')
69
+ process.exit(1)
70
+ }
33
71
 
34
- await updateReleaseHistory(
35
- options.appVersion,
36
- options.binaryVersion,
37
- config.getReleaseHistory,
38
- config.setReleaseHistory,
39
- options.platform,
40
- options.identifier,
41
- options.mandatory,
42
- options.enable,
43
- )
44
- });
72
+ await updateReleaseHistory(
73
+ options.app,
74
+ options.appVersion,
75
+ options.binaryVersion,
76
+ config.getReleaseHistory,
77
+ config.setReleaseHistory,
78
+ options.platform,
79
+ options.identifier,
80
+ options.mandatory,
81
+ options.enable
82
+ )
83
+ })
45
84
 
46
85
  function parseBoolean(value) {
47
- if (value === 'true') return true;
48
- if (value === 'false') return false;
49
- else return undefined;
86
+ if (value === 'true') return true
87
+ if (value === 'false') return false
88
+ else return undefined
50
89
  }
@@ -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 appVersion {string}
7
7
  * @param binaryVersion {string}
8
8
  * @param getReleaseHistory {
@@ -26,37 +26,53 @@ const path = require('path');
26
26
  * @returns {Promise<void>}
27
27
  */
28
28
  async function updateReleaseHistory(
29
- appVersion,
29
+ app,
30
+ appVersion,
31
+ binaryVersion,
32
+ getReleaseHistory,
33
+ setReleaseHistory,
34
+ platform,
35
+ identifier,
36
+ mandatory,
37
+ enable
38
+ ) {
39
+ const releaseHistory = await getReleaseHistory(
40
+ app,
30
41
  binaryVersion,
31
- getReleaseHistory,
32
- setReleaseHistory,
33
42
  platform,
34
- identifier,
35
- mandatory,
36
- enable,
37
- ) {
38
- const releaseHistory = await getReleaseHistory(binaryVersion, platform, identifier);
43
+ identifier
44
+ )
39
45
 
40
- const updateInfo = releaseHistory[appVersion]
41
- if (!updateInfo) throw new Error(`v${appVersion} is not released`)
46
+ const updateInfo = releaseHistory[appVersion]
47
+ if (!updateInfo) throw new Error(`v${appVersion} is not released`)
42
48
 
43
- if (typeof mandatory === "boolean") updateInfo.mandatory = mandatory;
44
- if (typeof enable === "boolean") updateInfo.enabled = enable;
49
+ if (typeof mandatory === 'boolean') updateInfo.mandatory = mandatory
50
+ if (typeof enable === 'boolean') updateInfo.enabled = enable
45
51
 
46
- try {
47
- const JSON_FILE_NAME = `${binaryVersion}.json`;
48
- const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME);
52
+ try {
53
+ const JSON_FILE_NAME = `${binaryVersion}.json`
54
+ const JSON_FILE_PATH = path.resolve(process.cwd(), JSON_FILE_NAME)
49
55
 
50
- console.log(`log: creating JSON file... ("${JSON_FILE_NAME}")\n`, JSON.stringify(releaseHistory, null, 2));
51
- fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(releaseHistory));
56
+ console.log(
57
+ `log: creating JSON file... ("${JSON_FILE_NAME}")\n`,
58
+ JSON.stringify(releaseHistory, null, 2)
59
+ )
60
+ fs.writeFileSync(JSON_FILE_PATH, JSON.stringify(releaseHistory))
52
61
 
53
- await setReleaseHistory(binaryVersion, JSON_FILE_PATH, releaseHistory, platform, identifier)
62
+ await setReleaseHistory(
63
+ binaryVersion,
64
+ JSON_FILE_PATH,
65
+ releaseHistory,
66
+ app,
67
+ platform,
68
+ identifier
69
+ )
54
70
 
55
- fs.unlinkSync(JSON_FILE_PATH);
56
- } catch (error) {
57
- console.error('Error occurred while updating history:', error);
58
- process.exit(1)
59
- }
71
+ fs.unlinkSync(JSON_FILE_PATH)
72
+ } catch (error) {
73
+ console.error('Error occurred while updating history:', error)
74
+ process.exit(1)
75
+ }
60
76
  }
61
77
 
62
78
  module.exports = { updateReleaseHistory: updateReleaseHistory }
package/cli/constant.js CHANGED
@@ -1,6 +1,8 @@
1
1
  module.exports = {
2
- CONFIG_FILE_NAME: "code-push.config.ts",
3
- OUTPUT_BUNDLE_DIR: "bundleOutput",
4
- ROOT_OUTPUT_DIR: "build",
5
- ENTRY_FILE: "index.ts",
6
- };
2
+ CONFIG_FILE_NAME: 'code-push.config.ts',
3
+ OUTPUT_BUNDLE_DIR: 'bundleOutput',
4
+ ROOT_OUTPUT_DIR: 'build',
5
+ ENTRY_FILE: 'index.js',
6
+ COMPILED_CONFIG_FILE_NAME: 'code-push.config.js',
7
+ PACKAGE_PATH: '/node_modules/@algocare/react-native-code-push/',
8
+ }
@@ -1,28 +1,42 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const { PACKAGE_PATH } = require('../constant')
4
4
  /**
5
5
  * allows to require a config file with .ts extension
6
6
  * @param filePath {string}
7
7
  * @returns {*} FIXME type
8
8
  */
9
- function requireConfig(filePath) {
10
- const ext = path.extname(filePath);
9
+ async function requireConfig(filePath) {
10
+ const ext = path.extname(filePath)
11
11
 
12
12
  if (ext === '.ts') {
13
13
  try {
14
- require('ts-node/register');
14
+ require('ts-node').register({
15
+ transpileOnly: true,
16
+ compilerOptions: {
17
+ module: 'CommonJS',
18
+ esModuleInterop: true,
19
+ allowJs: true,
20
+ resolveJsonModule: true,
21
+ experimentalDecorators: true,
22
+ emitDecoratorMetadata: true,
23
+ },
24
+ })
25
+
26
+ const config = await import(filePath)
27
+ return config.default || config
15
28
  } catch {
16
- console.error('ts-node not found. Please install ts-node as a devDependency.');
17
- process.exit(1);
29
+ console.error(
30
+ 'ts-node not found. Please install ts-node as a devDependency.'
31
+ )
32
+ process.exit(1)
18
33
  }
19
34
  } else if (ext === '.js') {
20
35
  // do nothing
21
36
  } else {
22
- throw new Error(`Unsupported file extension: ${ext}`);
37
+ throw new Error(`Unsupported file extension: ${ext}`)
23
38
  }
24
-
25
- return require(filePath);
39
+ return require(filePath)
26
40
  }
27
41
 
28
42
  /**
@@ -30,20 +44,21 @@ function requireConfig(filePath) {
30
44
  * @param configFileName {string}
31
45
  * @returns {*|null} FIXME type
32
46
  */
33
- function findAndReadConfigFile(startDir, configFileName) {
34
- let dir = startDir;
47
+ async function findAndReadConfigFile(startDir, configFileName) {
48
+ let dir = `${startDir}${PACKAGE_PATH}`
35
49
 
36
50
  while (dir !== path.parse(dir).root) {
37
- const configPath = path.join(dir, configFileName);
51
+ const configPath = path.join(dir, configFileName)
52
+
38
53
  if (fs.existsSync(configPath)) {
39
- const config = requireConfig(configPath);
40
- return config;
54
+ const config = await requireConfig(configPath)
55
+ return config
41
56
  }
42
- dir = path.dirname(dir);
57
+ dir = path.dirname(dir)
43
58
  }
44
59
 
45
- console.error(`${configFileName} not found.`);
46
- return null;
60
+ console.error(`${configFileName} not found.`)
61
+ return null
47
62
  }
48
63
 
49
- module.exports = { findAndReadConfigFile };
64
+ module.exports = { findAndReadConfigFile }
@@ -2,113 +2,113 @@
2
2
  // @ts-nocheck
3
3
 
4
4
  import {
5
- CliConfigInterface,
6
- ReleaseHistoryInterface,
7
- } from '@algocare/react-native-code-push'
8
- import * as fs from 'fs'
9
- import axios from 'axios' // install as devDependency
10
- import * as SupabaseSDK from '@supabase/supabase-js' // install as devDependency
11
-
12
- const SUPABASE_URL = process.env.SUPABASE_URL
13
- const SUPABASE_KEY = process.env.SUPABASE_KEY
14
- const supabase = SupabaseSDK.createClient(SUPABASE_URL!, SUPABASE_KEY!)
15
- const BUCKET_NAME = 'codePush'
16
- const STORAGE_HOST = `${SUPABASE_URL}/storage/v1/object/public`
5
+ CliConfigInterface,
6
+ ReleaseHistoryInterface,
7
+ } from "@bravemobile/react-native-code-push";
8
+ import * as fs from "fs";
9
+ import axios from "axios"; // install as devDependency
10
+ import * as SupabaseSDK from "@supabase/supabase-js"; // install as devDependency
11
+
12
+ const SUPABASE_URL = process.env.SUPABASE_URL;
13
+ const SUPABASE_KEY = process.env.SUPABASE_KEY;
14
+ const supabase = SupabaseSDK.createClient(SUPABASE_URL!, SUPABASE_KEY!);
15
+ const BUCKET_NAME = "codePush";
16
+ const STORAGE_HOST = `${SUPABASE_URL}/storage/v1/object/public`;
17
17
 
18
18
  function historyJsonFileRemotePath(
19
- platform: 'ios' | 'android',
20
- identifier: string,
21
- binaryVersion: string
19
+ platform: "ios" | "android",
20
+ identifier: string,
21
+ binaryVersion: string,
22
22
  ) {
23
- return `histories/${platform}/${identifier}/${binaryVersion}.json`
23
+ return `histories/${platform}/${identifier}/${binaryVersion}.json`;
24
24
  }
25
25
 
26
26
  function bundleFileRemotePath(
27
- platform: 'ios' | 'android',
28
- identifier: string,
29
- fileName: string
27
+ platform: "ios" | "android",
28
+ identifier: string,
29
+ fileName: string,
30
30
  ) {
31
- return `bundles/${platform}/${identifier}/${fileName}`
31
+ return `bundles/${platform}/${identifier}/${fileName}`;
32
32
  }
33
33
 
34
34
  const Config: CliConfigInterface = {
35
- bundleUploader: async (
36
- source: string,
37
- platform: 'ios' | 'android',
38
- identifier = 'staging'
39
- ): Promise<{ downloadUrl: string }> => {
40
- const fileName = source.split('/').pop()
41
- const fileStream = fs.createReadStream(source)
42
- const remotePath = bundleFileRemotePath(platform, identifier, fileName!)
43
-
44
- const { data, error } = await supabase.storage
45
- .from(BUCKET_NAME)
46
- .upload(remotePath, fileStream, {
47
- contentType: 'application/zip',
48
- duplex: 'half',
49
- })
50
-
51
- if (error) {
52
- console.error('Error uploading file:', error.message)
53
- throw error
54
- }
55
-
56
- console.log('Bundle File uploaded:', `${STORAGE_HOST}/${data.fullPath}`)
57
-
58
- return {
59
- downloadUrl: `${STORAGE_HOST}/${data.fullPath}`,
60
- }
61
- },
62
-
63
- getReleaseHistory: async (
64
- targetBinaryVersion: string,
65
- platform: 'ios' | 'android',
66
- identifier = 'staging'
67
- ): Promise<ReleaseHistoryInterface> => {
68
- const remoteJsonPath = historyJsonFileRemotePath(
69
- platform,
70
- identifier,
71
- targetBinaryVersion
72
- )
73
- const { data } = await axios.get(
74
- `${STORAGE_HOST}/${BUCKET_NAME}/${remoteJsonPath}`
75
- )
76
- return data as ReleaseHistoryInterface
77
- },
78
-
79
- setReleaseHistory: async (
80
- targetBinaryVersion: string,
81
- jsonFilePath: string,
82
- releaseInfo: ReleaseHistoryInterface,
83
- platform: 'ios' | 'android',
84
- identifier = 'staging'
85
- ): Promise<void> => {
86
- // upload JSON file or call API using `releaseInfo` metadata.
87
-
88
- const fileContent = fs.readFileSync(jsonFilePath, 'utf8')
89
- const remoteJsonPath = historyJsonFileRemotePath(
90
- platform,
91
- identifier,
92
- targetBinaryVersion
93
- )
94
-
95
- const { data, error } = await supabase.storage
96
- .from(BUCKET_NAME)
97
- .upload(remoteJsonPath, Buffer.from(fileContent), {
98
- contentType: 'application/json',
99
- cacheControl: '5',
100
- })
101
-
102
- if (error) {
103
- console.error('Error uploading file:', error.message)
104
- throw error
105
- }
106
-
107
- console.log(
108
- 'Release history File uploaded:',
109
- `${STORAGE_HOST}/${data.fullPath}`
110
- )
111
- },
112
- }
113
-
114
- module.exports = Config
35
+ bundleUploader: async (
36
+ source: string,
37
+ platform: "ios" | "android",
38
+ identifier = "staging",
39
+ ): Promise<{downloadUrl: string}> => {
40
+ const fileName = source.split("/").pop();
41
+ const fileStream = fs.createReadStream(source);
42
+ const remotePath = bundleFileRemotePath(platform, identifier, fileName!);
43
+
44
+ const {data, error} = await supabase.storage
45
+ .from(BUCKET_NAME)
46
+ .upload(remotePath, fileStream, {
47
+ contentType: "application/zip",
48
+ duplex: "half",
49
+ });
50
+
51
+ if (error) {
52
+ console.error("Error uploading file:", error.message);
53
+ throw error;
54
+ }
55
+
56
+ console.log("Bundle File uploaded:", `${STORAGE_HOST}/${data.fullPath}`);
57
+
58
+ return {
59
+ downloadUrl: `${STORAGE_HOST}/${data.fullPath}`,
60
+ };
61
+ },
62
+
63
+ getReleaseHistory: async (
64
+ targetBinaryVersion: string,
65
+ platform: "ios" | "android",
66
+ identifier = "staging",
67
+ ): Promise<ReleaseHistoryInterface> => {
68
+ const remoteJsonPath = historyJsonFileRemotePath(
69
+ platform,
70
+ identifier,
71
+ targetBinaryVersion,
72
+ );
73
+ const {data} = await axios.get(
74
+ `${STORAGE_HOST}/${BUCKET_NAME}/${remoteJsonPath}`,
75
+ );
76
+ return data as ReleaseHistoryInterface;
77
+ },
78
+
79
+ setReleaseHistory: async (
80
+ targetBinaryVersion: string,
81
+ jsonFilePath: string,
82
+ releaseInfo: ReleaseHistoryInterface,
83
+ platform: "ios" | "android",
84
+ identifier = "staging",
85
+ ): Promise<void> => {
86
+ // upload JSON file or call API using `releaseInfo` metadata.
87
+
88
+ const fileContent = fs.readFileSync(jsonFilePath, "utf8");
89
+ const remoteJsonPath = historyJsonFileRemotePath(
90
+ platform,
91
+ identifier,
92
+ targetBinaryVersion,
93
+ );
94
+
95
+ const {data, error} = await supabase.storage
96
+ .from(BUCKET_NAME)
97
+ .upload(remoteJsonPath, Buffer.from(fileContent), {
98
+ contentType: "application/json",
99
+ cacheControl: "5",
100
+ });
101
+
102
+ if (error) {
103
+ console.error("Error uploading file:", error.message);
104
+ throw error;
105
+ }
106
+
107
+ console.log(
108
+ "Release history File uploaded:",
109
+ `${STORAGE_HOST}/${data.fullPath}`,
110
+ );
111
+ },
112
+ };
113
+
114
+ module.exports = Config;