@bravemobile/react-native-code-push 12.0.2 → 12.1.1

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.
Files changed (99) hide show
  1. package/README.md +1 -1
  2. package/android/app/src/debug/AndroidManifest.xml +9 -0
  3. package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +1 -52
  4. package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +4 -43
  5. package/bin/code-push.js +6 -0
  6. package/cli/commands/bundleCommand/{bundleCodePush.js → bundleCodePush.ts} +16 -24
  7. package/cli/commands/bundleCommand/{index.js → index.ts} +13 -14
  8. package/cli/commands/createHistoryCommand/{createReleaseHistory.js → createReleaseHistory.ts} +11 -28
  9. package/cli/commands/createHistoryCommand/{index.js → index.ts} +12 -13
  10. package/cli/commands/initCommand/{index.js → index.ts} +3 -3
  11. package/cli/commands/initCommand/{initAndroid.js → initAndroid.ts} +6 -11
  12. package/cli/commands/initCommand/initIos.ts +123 -0
  13. package/cli/commands/initCommand/test/initAndroid.test.ts +86 -0
  14. package/cli/commands/initCommand/test/initIos.test.ts +99 -0
  15. package/cli/commands/releaseCommand/{addToReleaseHistory.js → addToReleaseHistory.ts} +17 -45
  16. package/cli/commands/releaseCommand/{index.js → index.ts} +24 -25
  17. package/cli/commands/releaseCommand/release.ts +72 -0
  18. package/cli/commands/showHistoryCommand/{index.js → index.ts} +11 -12
  19. package/cli/commands/updateHistoryCommand/{index.js → index.ts} +17 -18
  20. package/cli/commands/updateHistoryCommand/{updateReleaseHistory.js → updateReleaseHistory.ts} +15 -41
  21. package/cli/constant.ts +4 -0
  22. package/cli/dist/commands/bundleCommand/bundleCodePush.js +34 -0
  23. package/cli/dist/commands/bundleCommand/index.js +14 -0
  24. package/cli/dist/commands/createHistoryCommand/createReleaseHistory.js +25 -0
  25. package/cli/dist/commands/createHistoryCommand/index.js +14 -0
  26. package/cli/dist/commands/initCommand/index.js +12 -0
  27. package/cli/dist/commands/initCommand/initAndroid.js +37 -0
  28. package/cli/{commands → dist/commands}/initCommand/initIos.js +13 -33
  29. package/cli/dist/commands/initCommand/test/initAndroid.test.js +75 -0
  30. package/cli/dist/commands/initCommand/test/initIos.test.js +95 -0
  31. package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +32 -0
  32. package/cli/dist/commands/releaseCommand/index.js +38 -0
  33. package/cli/dist/commands/releaseCommand/release.js +36 -0
  34. package/cli/dist/commands/showHistoryCommand/index.js +14 -0
  35. package/cli/dist/commands/updateHistoryCommand/index.js +30 -0
  36. package/cli/dist/commands/updateHistoryCommand/updateReleaseHistory.js +26 -0
  37. package/cli/dist/constant.js +4 -0
  38. package/cli/dist/functions/getReactTempDir.js +10 -0
  39. package/cli/{functions → dist/functions}/makeCodePushBundle.js +5 -11
  40. package/cli/{functions → dist/functions}/prepareToBundleJS.js +2 -5
  41. package/cli/{functions → dist/functions}/runExpoBundleCommand.js +3 -21
  42. package/cli/{functions → dist/functions}/runHermesEmitBinaryCommand.js +12 -68
  43. package/cli/{functions → dist/functions}/runReactNativeBundleCommand.js +3 -23
  44. package/cli/dist/index.js +38 -0
  45. package/cli/dist/utils/file-utils.js +19 -0
  46. package/cli/dist/utils/fsUtils.js +37 -0
  47. package/cli/{utils → dist/utils}/hash-utils.js +19 -127
  48. package/cli/{utils → dist/utils}/promisfied-fs.js +5 -16
  49. package/cli/dist/utils/showLogo.js +21 -0
  50. package/cli/{utils → dist/utils}/zip.js +15 -51
  51. package/cli/functions/{getReactTempDir.js → getReactTempDir.ts} +2 -6
  52. package/cli/functions/makeCodePushBundle.ts +26 -0
  53. package/cli/functions/prepareToBundleJS.ts +10 -0
  54. package/cli/functions/runExpoBundleCommand.ts +45 -0
  55. package/cli/functions/runHermesEmitBinaryCommand.ts +186 -0
  56. package/cli/functions/runReactNativeBundleCommand.ts +51 -0
  57. package/cli/index.ts +48 -0
  58. package/cli/package.json +33 -0
  59. package/cli/utils/{file-utils.js → file-utils.ts} +4 -21
  60. package/cli/utils/{fsUtils.js → fsUtils.ts} +12 -19
  61. package/cli/utils/hash-utils.ts +146 -0
  62. package/cli/utils/promisfied-fs.ts +19 -0
  63. package/cli/utils/{showLogo.js → showLogo.ts} +1 -3
  64. package/cli/utils/zip.ts +65 -0
  65. package/package.json +42 -12
  66. package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
  67. package/AGENTS.md +0 -32
  68. package/CONTRIBUTING.md +0 -134
  69. package/SECURITY.md +0 -41
  70. package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +0 -17
  71. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  72. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  73. package/android/gradlew +0 -164
  74. package/android/gradlew.bat +0 -90
  75. package/babel.config.js +0 -3
  76. package/cli/commands/releaseCommand/release.js +0 -114
  77. package/cli/constant.js +0 -6
  78. package/cli/index.js +0 -49
  79. package/docs/api-android.md +0 -83
  80. package/docs/api-ios.md +0 -31
  81. package/docs/api-js.md +0 -592
  82. package/docs/multi-deployment-testing-android.md +0 -148
  83. package/docs/multi-deployment-testing-ios.md +0 -59
  84. package/eslint.config.mjs +0 -32
  85. package/scripts/generateBundledResourcesHash.js +0 -125
  86. package/scripts/getFilesInFolder.js +0 -19
  87. package/scripts/recordFilesBeforeBundleCommand.js +0 -41
  88. package/tsconfig.json +0 -18
  89. package/tslint.json +0 -32
  90. /package/{CodePush.js → src/CodePush.js} +0 -0
  91. /package/{logging.js → src/logging.js} +0 -0
  92. /package/{package-mixins.js → src/package-mixins.js} +0 -0
  93. /package/{versioning → src/versioning}/BaseVersioning.js +0 -0
  94. /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
  95. /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
  96. /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
  97. /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
  98. /package/{versioning → src/versioning}/SemverVersioning.test.js +0 -0
  99. /package/{versioning → src/versioning}/index.js +0 -0
@@ -1,30 +1,15 @@
1
1
  /**
2
2
  * code based on appcenter-cli
3
3
  */
4
-
5
- const fs = require('fs');
6
- const path = require('path');
7
- const yazl = require('yazl');
8
- const { generateRandomFilename, normalizePath, isDirectory } = require('./file-utils');
9
- const { walk } = require('./promisfied-fs');
10
-
11
- /**
12
- * @typedef {{ sourceLocation: string, targetLocation: string }} ReleaseFile
13
- */
14
-
15
- /**
16
- * @param updateContentsPath {string}
17
- * @return {Promise<string>}
18
- */
19
- function zip(updateContentsPath) {
20
-
4
+ import fs from "fs";
5
+ import path from "path";
6
+ import yazl from "yazl";
7
+ import { generateRandomFilename, normalizePath, isDirectory } from "./file-utils.js";
8
+ import { walk } from "./promisfied-fs.js";
9
+ export function zip(updateContentsPath) {
21
10
  // eslint-disable-next-line no-async-promise-executor
22
11
  return new Promise(async (resolve, reject) => {
23
- /**
24
- * @type {ReleaseFile[]}
25
- */
26
12
  const releaseFiles = [];
27
-
28
13
  try {
29
14
  if (!isDirectory(updateContentsPath)) {
30
15
  releaseFiles.push({
@@ -32,58 +17,37 @@ function zip(updateContentsPath) {
32
17
  targetLocation: normalizePath(path.basename(updateContentsPath)), // Put the file in the root
33
18
  });
34
19
  }
35
- } catch (error) {
36
- error.message = error.message + ' Make sure you have added the platform you are making a release to.`.';
20
+ }
21
+ catch (error) {
22
+ if (error instanceof Error) {
23
+ error.message = error.message + " Make sure you have added the platform you are making a release to.`.";
24
+ }
37
25
  reject(error);
38
26
  }
39
-
40
- /**
41
- * @type {string}
42
- */
43
27
  const directoryPath = updateContentsPath;
44
28
  const baseDirectoryPath = path.join(directoryPath, '..'); // For legacy reasons, put the root directory in the zip
45
-
46
- /**
47
- * @type {string[]}
48
- */
49
29
  const files = await walk(updateContentsPath);
50
-
51
30
  files.forEach((filePath) => {
52
- /**
53
- * @type {string}
54
- */
55
31
  const relativePath = path.relative(baseDirectoryPath, filePath);
56
32
  releaseFiles.push({
57
33
  sourceLocation: filePath,
58
34
  targetLocation: normalizePath(relativePath),
59
35
  });
60
36
  });
61
-
62
- /**
63
- * @type {string}
64
- */
65
37
  const packagePath = path.join(process.cwd(), generateRandomFilename(15) + '.zip');
66
38
  const zipFile = new yazl.ZipFile();
67
- /**
68
- * @type {fs.WriteStream}
69
- */
70
39
  const writeStream = fs.createWriteStream(packagePath);
71
-
72
40
  zipFile.outputStream
73
41
  .pipe(writeStream)
74
42
  .on('error', (error) => {
75
- reject(error);
76
- })
43
+ reject(error);
44
+ })
77
45
  .on('close', () => {
78
- resolve(packagePath);
79
- });
80
-
46
+ resolve(packagePath);
47
+ });
81
48
  releaseFiles.forEach((releaseFile) => {
82
49
  zipFile.addFile(releaseFile.sourceLocation, releaseFile.targetLocation);
83
50
  });
84
-
85
51
  zipFile.end();
86
52
  });
87
53
  }
88
-
89
- module.exports = zip;
@@ -2,15 +2,11 @@
2
2
  * code based on appcenter-cli
3
3
  */
4
4
 
5
- const os = require('os');
5
+ import os from "os";
6
6
 
7
7
  /**
8
8
  * Return the path of the temporary directory for react-native bundling
9
- *
10
- * @return {string}
11
9
  */
12
- function getReactTempDir() {
10
+ export function getReactTempDir(): string {
13
11
  return `${os.tmpdir()}/react-*`;
14
12
  }
15
-
16
- module.exports = { getReactTempDir };
@@ -0,0 +1,26 @@
1
+ import path from "path";
2
+ import shell from "shelljs";
3
+ import { zip } from "../utils/zip.js";
4
+ import { generatePackageHashFromDirectory } from "../utils/hash-utils.js";
5
+
6
+ /**
7
+ * Create a CodePush bundle file and return the information.
8
+ *
9
+ * @param contentsPath {string} The directory path containing the contents to be made into a CodePush bundle (usually the 'build/CodePush' directory))
10
+ * @param bundleDirectory {string} The directory path to save the CodePush bundle file
11
+ * @return {Promise<{ bundleFileName: string }>}
12
+ */
13
+ export async function makeCodePushBundle(contentsPath: string, bundleDirectory: string): Promise<{ bundleFileName: string }> {
14
+ const updateContentsZipPath = await zip(contentsPath);
15
+
16
+ const packageHash = await generatePackageHashFromDirectory(contentsPath, path.join(contentsPath, '..'));
17
+
18
+ shell.mkdir('-p', `./${bundleDirectory}`);
19
+ shell.mv(updateContentsZipPath, `./${bundleDirectory}/${packageHash}`);
20
+
21
+ return {
22
+ // To allow the "release" command to get the file and hash value from the result of the "bundle" command,
23
+ // use the hash value as the name of the file.
24
+ bundleFileName: packageHash,
25
+ };
26
+ }
@@ -0,0 +1,10 @@
1
+ import shell from "shelljs";
2
+
3
+ /**
4
+ * @param deleteDirs {string[]} Directories to delete
5
+ * @param makeDir {string} Directory path to create
6
+ */
7
+ export function prepareToBundleJS({ deleteDirs, makeDir }: { deleteDirs: string[], makeDir: string }) {
8
+ shell.rm('-rf', deleteDirs);
9
+ shell.mkdir('-p', makeDir);
10
+ }
@@ -0,0 +1,45 @@
1
+ import path from "path";
2
+ import shell from "shelljs";
3
+
4
+ /**
5
+ * Run `expo bundle` CLI command
6
+ *
7
+ * @param bundleName {string} JS bundle file name
8
+ * @param entryFile {string} App code entry file name (default: index.ts)
9
+ * @param outputPath {string} Path to output JS bundle file and assets
10
+ * @param platform {string} Platform (ios | android)
11
+ * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
12
+ * @return {void}
13
+ */
14
+ export function runExpoBundleCommand(
15
+ bundleName: string,
16
+ outputPath: string,
17
+ platform: string,
18
+ sourcemapOutput: string,
19
+ entryFile: string,
20
+ ): void {
21
+ function getCliPath(): string {
22
+ return path.join('node_modules', '.bin', 'expo');
23
+ }
24
+
25
+ const expoBundleArgs: string[] = [
26
+ 'export:embed',
27
+ '--assets-dest',
28
+ outputPath,
29
+ '--bundle-output',
30
+ path.join(outputPath, bundleName),
31
+ '--dev',
32
+ 'false',
33
+ '--entry-file',
34
+ entryFile,
35
+ '--platform',
36
+ platform,
37
+ '--sourcemap-output',
38
+ sourcemapOutput,
39
+ '--reset-cache',
40
+ ];
41
+
42
+ console.log('Running "expo export:embed" command:\n');
43
+
44
+ shell.exec(`${getCliPath()} ${expoBundleArgs.join(' ')}`);
45
+ }
@@ -0,0 +1,186 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ import childProcess from "child_process";
6
+ import fs from "fs";
7
+ import path from "path";
8
+ import shell from "shelljs";
9
+
10
+ /**
11
+ * Run Hermes compile CLI command
12
+ *
13
+ * @param bundleName {string} JS bundle file name
14
+ * @param outputPath {string} Path to output .hbc file
15
+ * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
16
+ * @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
17
+ * @return {Promise<void>}
18
+ */
19
+ export async function runHermesEmitBinaryCommand(
20
+ bundleName: string,
21
+ outputPath: string,
22
+ sourcemapOutput: string,
23
+ extraHermesFlags: string[] = [],
24
+ ): Promise<void> {
25
+ const hermesArgs: string[] = [
26
+ '-emit-binary',
27
+ '-out',
28
+ path.join(outputPath, bundleName + '.hbc'),
29
+ path.join(outputPath, bundleName),
30
+ ...extraHermesFlags,
31
+ ];
32
+ if (sourcemapOutput) {
33
+ hermesArgs.push('-output-source-map');
34
+ }
35
+
36
+ console.log('Converting JS bundle to byte code via Hermes, running command:\n');
37
+
38
+ return new Promise<void>((resolve, reject) => {
39
+ try {
40
+ const hermesCommand = getHermesCommand();
41
+
42
+ const disableAllWarningsArg = '-w';
43
+ shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
44
+
45
+ // Copy HBC bundle to overwrite JS bundle
46
+ const source = path.join(outputPath, bundleName + '.hbc');
47
+ const destination = path.join(outputPath, bundleName);
48
+ shell.cp(source, destination);
49
+ shell.rm(source);
50
+ resolve();
51
+ } catch (e) {
52
+ reject(e);
53
+ }
54
+ }).then(() => {
55
+ if (!sourcemapOutput) {
56
+ // skip source map compose if source map is not enabled
57
+ return;
58
+ }
59
+
60
+ // compose-source-maps.js file path
61
+ const composeSourceMapsPath = getComposeSourceMapsPath();
62
+ if (composeSourceMapsPath === null) {
63
+ throw new Error('react-native compose-source-maps.js scripts is not found');
64
+ }
65
+
66
+ const jsCompilerSourceMapFile = path.join(outputPath, bundleName + '.hbc' + '.map');
67
+ if (!fs.existsSync(jsCompilerSourceMapFile)) {
68
+ throw new Error(`sourcemap file ${jsCompilerSourceMapFile} is not found`);
69
+ }
70
+
71
+ return new Promise((resolve, reject) => {
72
+ const composeSourceMapsArgs = [
73
+ composeSourceMapsPath,
74
+ sourcemapOutput,
75
+ jsCompilerSourceMapFile,
76
+ '-o',
77
+ sourcemapOutput,
78
+ ];
79
+ const composeSourceMapsProcess = childProcess.spawn('node', composeSourceMapsArgs);
80
+ console.log(`${composeSourceMapsPath} ${composeSourceMapsArgs.join(' ')}`);
81
+
82
+ composeSourceMapsProcess.stdout.on('data', (data) => {
83
+ console.log(data.toString().trim());
84
+ });
85
+
86
+ composeSourceMapsProcess.stderr.on('data', (data) => {
87
+ console.error(data.toString().trim());
88
+ });
89
+
90
+ composeSourceMapsProcess.on('close', (exitCode, signal) => {
91
+ if (exitCode !== 0) {
92
+ reject(new Error(`"compose-source-maps" command failed (exitCode=${exitCode}, signal=${signal}).`));
93
+ }
94
+
95
+ // Delete the HBC sourceMap, otherwise it will be included in 'code-push' bundle as well
96
+ fs.unlink(jsCompilerSourceMapFile, (err) => {
97
+ if (err != null) {
98
+ console.error(err);
99
+ reject(err);
100
+ }
101
+
102
+ resolve();
103
+ });
104
+ });
105
+ });
106
+ });
107
+ }
108
+
109
+ function getHermesCommand(): string {
110
+ const fileExists = (file: string): boolean => {
111
+ try {
112
+ return fs.statSync(file).isFile();
113
+ } catch (e) {
114
+ return false;
115
+ }
116
+ };
117
+ // Hermes is bundled with react-native since 0.69
118
+ const bundledHermesEngine = path.join(
119
+ getReactNativePackagePath(),
120
+ 'sdks',
121
+ 'hermesc',
122
+ getHermesOSBin(),
123
+ getHermesOSExe(),
124
+ );
125
+ if (fileExists(bundledHermesEngine)) {
126
+ return bundledHermesEngine;
127
+ }
128
+ throw new Error('Hermes engine binary not found. Please upgrade to react-native 0.69 or later');
129
+ }
130
+
131
+ function getHermesOSBin() {
132
+ switch (process.platform) {
133
+ case 'win32':
134
+ return 'win64-bin';
135
+ case 'darwin':
136
+ return 'osx-bin';
137
+ case 'freebsd':
138
+ case 'linux':
139
+ case 'sunos':
140
+ default:
141
+ return 'linux64-bin';
142
+ }
143
+ }
144
+
145
+ function getHermesOSExe(): string {
146
+ const hermesExecutableName = 'hermesc';
147
+ switch (process.platform) {
148
+ case 'win32':
149
+ return hermesExecutableName + '.exe';
150
+ default:
151
+ return hermesExecutableName;
152
+ }
153
+ }
154
+
155
+ function getComposeSourceMapsPath(): string | null {
156
+ // detect if compose-source-maps.js script exists
157
+ const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
158
+ if (fs.existsSync(composeSourceMaps)) {
159
+ return composeSourceMaps;
160
+ }
161
+ return null;
162
+ }
163
+
164
+ function getReactNativePackagePath(): string {
165
+ const result = childProcess.spawnSync('node', [
166
+ '--print',
167
+ "require.resolve('react-native/package.json')",
168
+ ]);
169
+ const packagePath = path.dirname(result.stdout.toString());
170
+ if (result.status === 0 && directoryExistsSync(packagePath)) {
171
+ return packagePath;
172
+ }
173
+
174
+ return path.join('node_modules', 'react-native');
175
+ }
176
+
177
+ function directoryExistsSync(dirname: string): boolean {
178
+ try {
179
+ return fs.statSync(dirname).isDirectory();
180
+ } catch (err: unknown) {
181
+ if ((err as any).code !== 'ENOENT') {
182
+ throw err;
183
+ }
184
+ }
185
+ return false;
186
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+
5
+ import path from "path";
6
+ import shell from "shelljs";
7
+
8
+ /**
9
+ * Run `react-native bundle` CLI command
10
+ *
11
+ * @param bundleName {string} JS bundle file name
12
+ * @param entryFile {string} App code entry file name (default: index.ts)
13
+ * @param outputPath {string} Path to output JS bundle file and assets
14
+ * @param platform {string} Platform (ios | android)
15
+ * @param sourcemapOutput {string} Path to output sourcemap file (Warning: if sourcemapOutput points to the outputPath, the sourcemap will be included in the CodePush bundle and increase the deployment size)
16
+ * @param extraBundlerOptions {string[]} Additional options to pass to `react-native bundle` command
17
+ * @return {void}
18
+ */
19
+ export function runReactNativeBundleCommand(
20
+ bundleName: string,
21
+ outputPath: string,
22
+ platform: string,
23
+ sourcemapOutput: string,
24
+ entryFile: string,
25
+ extraBundlerOptions: string[] = [],
26
+ ): void {
27
+ function getCliPath(): string {
28
+ return path.join('node_modules', '.bin', 'react-native');
29
+ }
30
+
31
+ const reactNativeBundleArgs: string[] = [
32
+ 'bundle',
33
+ '--assets-dest',
34
+ outputPath,
35
+ '--bundle-output',
36
+ path.join(outputPath, bundleName),
37
+ '--dev',
38
+ 'false',
39
+ '--entry-file',
40
+ entryFile,
41
+ '--platform',
42
+ platform,
43
+ '--sourcemap-output',
44
+ sourcemapOutput,
45
+ ...extraBundlerOptions,
46
+ ];
47
+
48
+ console.log('Running "react-native bundle" command:\n');
49
+
50
+ shell.exec(`${getCliPath()} ${reactNativeBundleArgs.join(' ')}`);
51
+ }
package/cli/index.ts ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from "commander";
4
+ import shell from "shelljs";
5
+ import { showLogo } from "./utils/showLogo.js";
6
+
7
+ /**
8
+ * npx code-push bundle
9
+ */
10
+ import "./commands/bundleCommand/index.js";
11
+
12
+ /**
13
+ * npx code-push create-history
14
+ */
15
+ import "./commands/createHistoryCommand/index.js";
16
+
17
+ /**
18
+ * npx code-push update-history
19
+ */
20
+ import "./commands/updateHistoryCommand/index.js";
21
+
22
+ /**
23
+ * npx code-push release
24
+ */
25
+ import "./commands/releaseCommand/index.js";
26
+
27
+ /**
28
+ * npx code-push show-history
29
+ */
30
+ import "./commands/showHistoryCommand/index.js";
31
+
32
+ /**
33
+ * npx code-push init
34
+ */
35
+ import "./commands/initCommand/index.js";
36
+
37
+ shell.set("-e");
38
+ shell.set("+v");
39
+
40
+ program
41
+ .name("npx code-push")
42
+ .description("Command line interface for @bravemobile/react-native-code-push")
43
+ .version("1.0.0")
44
+ .action(() => {
45
+ showLogo();
46
+ });
47
+
48
+ program.parse();
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@bravemobile/code-push-cli",
3
+ "private": true,
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "scripts": {
8
+ "clean": "rm -rf dist",
9
+ "build": "tsc -p tsconfig.json",
10
+ "typecheck": "tsc -p tsconfig.json --noEmit",
11
+ "test": "jest"
12
+ },
13
+ "dependencies": {
14
+ "commander": "^12.1.0",
15
+ "shelljs": "^0.10.0",
16
+ "xcode": "^3.0.1",
17
+ "yazl": "^3.3.1"
18
+ },
19
+ "peerDependencies": {
20
+ "ts-node": ">=10"
21
+ },
22
+ "peerDependenciesMeta": {
23
+ "ts-node": {
24
+ "optional": true
25
+ }
26
+ },
27
+ "engines": {
28
+ "node": ">=18"
29
+ },
30
+ "devDependencies": {
31
+ "@types/yazl": "^3.3.0"
32
+ }
33
+ }
@@ -2,23 +2,13 @@
2
2
  * code based on appcenter-cli
3
3
  */
4
4
 
5
- const fs = require('fs');
5
+ import fs from "fs";
6
6
 
7
- /**
8
- *
9
- * @param path {string}
10
- * @return {boolean}
11
- */
12
- function isDirectory(path) {
7
+ export function isDirectory(path: string): boolean {
13
8
  return fs.statSync(path).isDirectory();
14
9
  }
15
10
 
16
- /**
17
- *
18
- * @param length {number}
19
- * @return {string}
20
- */
21
- function generateRandomFilename(length) {
11
+ export function generateRandomFilename(length: number): string {
22
12
  let filename = '';
23
13
  const validChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
24
14
 
@@ -29,14 +19,7 @@ function generateRandomFilename(length) {
29
19
  return filename;
30
20
  }
31
21
 
32
- /**
33
- *
34
- * @param filePath {string}
35
- * @return {string}
36
- */
37
- function normalizePath(filePath) {
22
+ export function normalizePath(filePath: string): string {
38
23
  //replace all backslashes coming from cli running on windows machines by slashes
39
24
  return filePath.replace(/\\/g, '/');
40
25
  }
41
-
42
- module.exports = { isDirectory, generateRandomFilename, normalizePath };
@@ -1,17 +1,19 @@
1
- const fs = require("fs");
2
- const path = require("path");
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { createRequire } from "module";
4
+ import type { CliConfigInterface } from "../../typings/react-native-code-push.d.ts";
5
+
6
+ const nodeRequire = createRequire(import.meta.url);
3
7
 
4
8
  /**
5
9
  * allows to require a config file with .ts extension
6
- * @param filePath {string}
7
- * @returns {*} FIXME type
8
10
  */
9
- function requireConfig(filePath) {
11
+ function requireConfig(filePath: string): CliConfigInterface {
10
12
  const ext = path.extname(filePath);
11
13
 
12
14
  if (ext === '.ts') {
13
15
  try {
14
- require('ts-node/register');
16
+ nodeRequire('ts-node/register');
15
17
  } catch {
16
18
  console.error('ts-node not found. Please install ts-node as a devDependency.');
17
19
  process.exit(1);
@@ -22,28 +24,19 @@ function requireConfig(filePath) {
22
24
  throw new Error(`Unsupported file extension: ${ext}`);
23
25
  }
24
26
 
25
- return require(filePath);
27
+ return nodeRequire(filePath) as CliConfigInterface;
26
28
  }
27
29
 
28
- /**
29
- * @param startDir {string}
30
- * @param configFileName {string}
31
- * @returns {*|null} FIXME type
32
- */
33
- function findAndReadConfigFile(startDir, configFileName) {
30
+ export function findAndReadConfigFile(startDir: string, configFileName: string): CliConfigInterface {
34
31
  let dir = startDir;
35
32
 
36
33
  while (dir !== path.parse(dir).root) {
37
34
  const configPath = path.join(dir, configFileName);
38
35
  if (fs.existsSync(configPath)) {
39
- const config = requireConfig(configPath);
40
- return config;
36
+ return requireConfig(configPath);
41
37
  }
42
38
  dir = path.dirname(dir);
43
39
  }
44
40
 
45
- console.error(`${configFileName} not found.`);
46
- return null;
41
+ throw new Error(`${configFileName} not found.`);
47
42
  }
48
-
49
- module.exports = { findAndReadConfigFile };