@bravemobile/react-native-code-push 12.0.2 → 12.1.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.
Files changed (100) 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/app.plugin.js +0 -1
  76. package/babel.config.js +0 -3
  77. package/cli/commands/releaseCommand/release.js +0 -114
  78. package/cli/constant.js +0 -6
  79. package/cli/index.js +0 -49
  80. package/docs/api-android.md +0 -83
  81. package/docs/api-ios.md +0 -31
  82. package/docs/api-js.md +0 -592
  83. package/docs/multi-deployment-testing-android.md +0 -148
  84. package/docs/multi-deployment-testing-ios.md +0 -59
  85. package/eslint.config.mjs +0 -32
  86. package/scripts/generateBundledResourcesHash.js +0 -125
  87. package/scripts/getFilesInFolder.js +0 -19
  88. package/scripts/recordFilesBeforeBundleCommand.js +0 -41
  89. package/tsconfig.json +0 -18
  90. package/tslint.json +0 -32
  91. /package/{CodePush.js → src/CodePush.js} +0 -0
  92. /package/{logging.js → src/logging.js} +0 -0
  93. /package/{package-mixins.js → src/package-mixins.js} +0 -0
  94. /package/{versioning → src/versioning}/BaseVersioning.js +0 -0
  95. /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
  96. /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
  97. /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
  98. /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
  99. /package/{versioning → src/versioning}/SemverVersioning.test.js +0 -0
  100. /package/{versioning → src/versioning}/index.js +0 -0
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * code based on appcenter-cli
3
3
  */
4
-
5
- const childProcess = require('child_process');
6
- const fs = require('fs');
7
- const path = require('path');
8
- const shell = require('shelljs');
9
-
4
+ import childProcess from "child_process";
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import shell from "shelljs";
10
8
  /**
11
9
  * Run Hermes compile CLI command
12
10
  *
@@ -16,15 +14,7 @@ const shell = require('shelljs');
16
14
  * @param extraHermesFlags {string[]} Additional options to pass to `hermesc` command
17
15
  * @return {Promise<void>}
18
16
  */
19
- async function runHermesEmitBinaryCommand(
20
- bundleName,
21
- outputPath,
22
- sourcemapOutput,
23
- extraHermesFlags = [],
24
- ) {
25
- /**
26
- * @type {string[]}
27
- */
17
+ export async function runHermesEmitBinaryCommand(bundleName, outputPath, sourcemapOutput, extraHermesFlags = []) {
28
18
  const hermesArgs = [
29
19
  '-emit-binary',
30
20
  '-out',
@@ -35,23 +25,20 @@ async function runHermesEmitBinaryCommand(
35
25
  if (sourcemapOutput) {
36
26
  hermesArgs.push('-output-source-map');
37
27
  }
38
-
39
28
  console.log('Converting JS bundle to byte code via Hermes, running command:\n');
40
-
41
29
  return new Promise((resolve, reject) => {
42
30
  try {
43
31
  const hermesCommand = getHermesCommand();
44
-
45
32
  const disableAllWarningsArg = '-w';
46
33
  shell.exec(`${hermesCommand} ${hermesArgs.join(' ')} ${disableAllWarningsArg}`);
47
-
48
34
  // Copy HBC bundle to overwrite JS bundle
49
35
  const source = path.join(outputPath, bundleName + '.hbc');
50
36
  const destination = path.join(outputPath, bundleName);
51
37
  shell.cp(source, destination);
52
38
  shell.rm(source);
53
39
  resolve();
54
- } catch (e) {
40
+ }
41
+ catch (e) {
55
42
  reject(e);
56
43
  }
57
44
  }).then(() => {
@@ -59,18 +46,15 @@ async function runHermesEmitBinaryCommand(
59
46
  // skip source map compose if source map is not enabled
60
47
  return;
61
48
  }
62
-
63
49
  // compose-source-maps.js file path
64
50
  const composeSourceMapsPath = getComposeSourceMapsPath();
65
51
  if (composeSourceMapsPath === null) {
66
52
  throw new Error('react-native compose-source-maps.js scripts is not found');
67
53
  }
68
-
69
54
  const jsCompilerSourceMapFile = path.join(outputPath, bundleName + '.hbc' + '.map');
70
55
  if (!fs.existsSync(jsCompilerSourceMapFile)) {
71
56
  throw new Error(`sourcemap file ${jsCompilerSourceMapFile} is not found`);
72
57
  }
73
-
74
58
  return new Promise((resolve, reject) => {
75
59
  const composeSourceMapsArgs = [
76
60
  composeSourceMapsPath,
@@ -81,65 +65,44 @@ async function runHermesEmitBinaryCommand(
81
65
  ];
82
66
  const composeSourceMapsProcess = childProcess.spawn('node', composeSourceMapsArgs);
83
67
  console.log(`${composeSourceMapsPath} ${composeSourceMapsArgs.join(' ')}`);
84
-
85
68
  composeSourceMapsProcess.stdout.on('data', (data) => {
86
69
  console.log(data.toString().trim());
87
70
  });
88
-
89
71
  composeSourceMapsProcess.stderr.on('data', (data) => {
90
72
  console.error(data.toString().trim());
91
73
  });
92
-
93
74
  composeSourceMapsProcess.on('close', (exitCode, signal) => {
94
75
  if (exitCode !== 0) {
95
76
  reject(new Error(`"compose-source-maps" command failed (exitCode=${exitCode}, signal=${signal}).`));
96
77
  }
97
-
98
78
  // Delete the HBC sourceMap, otherwise it will be included in 'code-push' bundle as well
99
79
  fs.unlink(jsCompilerSourceMapFile, (err) => {
100
80
  if (err != null) {
101
81
  console.error(err);
102
82
  reject(err);
103
83
  }
104
-
105
84
  resolve();
106
85
  });
107
86
  });
108
87
  });
109
88
  });
110
89
  }
111
-
112
- /**
113
- * @return {string}
114
- */
115
90
  function getHermesCommand() {
116
- /**
117
- * @type {(file: string) => boolean}
118
- */
119
91
  const fileExists = (file) => {
120
92
  try {
121
93
  return fs.statSync(file).isFile();
122
- } catch (e) {
94
+ }
95
+ catch (e) {
123
96
  return false;
124
97
  }
125
98
  };
126
99
  // Hermes is bundled with react-native since 0.69
127
- const bundledHermesEngine = path.join(
128
- getReactNativePackagePath(),
129
- 'sdks',
130
- 'hermesc',
131
- getHermesOSBin(),
132
- getHermesOSExe(),
133
- );
100
+ const bundledHermesEngine = path.join(getReactNativePackagePath(), 'sdks', 'hermesc', getHermesOSBin(), getHermesOSExe());
134
101
  if (fileExists(bundledHermesEngine)) {
135
102
  return bundledHermesEngine;
136
103
  }
137
104
  throw new Error('Hermes engine binary not found. Please upgrade to react-native 0.69 or later');
138
105
  }
139
-
140
- /**
141
- * @return {string}
142
- */
143
106
  function getHermesOSBin() {
144
107
  switch (process.platform) {
145
108
  case 'win32':
@@ -153,10 +116,6 @@ function getHermesOSBin() {
153
116
  return 'linux64-bin';
154
117
  }
155
118
  }
156
-
157
- /**
158
- * @return {string}
159
- */
160
119
  function getHermesOSExe() {
161
120
  const hermesExecutableName = 'hermesc';
162
121
  switch (process.platform) {
@@ -166,10 +125,6 @@ function getHermesOSExe() {
166
125
  return hermesExecutableName;
167
126
  }
168
127
  }
169
-
170
- /**
171
- * @return {string | null}
172
- */
173
128
  function getComposeSourceMapsPath() {
174
129
  // detect if compose-source-maps.js script exists
175
130
  const composeSourceMaps = path.join(getReactNativePackagePath(), 'scripts', 'compose-source-maps.js');
@@ -178,10 +133,6 @@ function getComposeSourceMapsPath() {
178
133
  }
179
134
  return null;
180
135
  }
181
-
182
- /**
183
- * @return {string}
184
- */
185
136
  function getReactNativePackagePath() {
186
137
  const result = childProcess.spawnSync('node', [
187
138
  '--print',
@@ -191,23 +142,16 @@ function getReactNativePackagePath() {
191
142
  if (result.status === 0 && directoryExistsSync(packagePath)) {
192
143
  return packagePath;
193
144
  }
194
-
195
145
  return path.join('node_modules', 'react-native');
196
146
  }
197
-
198
- /**
199
- * @param dirname {string}
200
- * @return {boolean}
201
- */
202
147
  function directoryExistsSync(dirname) {
203
148
  try {
204
149
  return fs.statSync(dirname).isDirectory();
205
- } catch (err) {
150
+ }
151
+ catch (err) {
206
152
  if (err.code !== 'ENOENT') {
207
153
  throw err;
208
154
  }
209
155
  }
210
156
  return false;
211
157
  }
212
-
213
- module.exports = { runHermesEmitBinaryCommand };
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  * code based on appcenter-cli
3
3
  */
4
-
5
- const path = require('path');
6
- const shell = require('shelljs');
7
-
4
+ import path from "path";
5
+ import shell from "shelljs";
8
6
  /**
9
7
  * Run `react-native bundle` CLI command
10
8
  *
@@ -16,24 +14,10 @@ const shell = require('shelljs');
16
14
  * @param extraBundlerOptions {string[]} Additional options to pass to `react-native bundle` command
17
15
  * @return {void}
18
16
  */
19
- function runReactNativeBundleCommand(
20
- bundleName,
21
- outputPath,
22
- platform,
23
- sourcemapOutput,
24
- entryFile,
25
- extraBundlerOptions = [],
26
- ) {
27
- /**
28
- * @return {string}
29
- */
17
+ export function runReactNativeBundleCommand(bundleName, outputPath, platform, sourcemapOutput, entryFile, extraBundlerOptions = []) {
30
18
  function getCliPath() {
31
19
  return path.join('node_modules', '.bin', 'react-native');
32
20
  }
33
-
34
- /**
35
- * @type {string[]}
36
- */
37
21
  const reactNativeBundleArgs = [
38
22
  'bundle',
39
23
  '--assets-dest',
@@ -50,10 +34,6 @@ function runReactNativeBundleCommand(
50
34
  sourcemapOutput,
51
35
  ...extraBundlerOptions,
52
36
  ];
53
-
54
37
  console.log('Running "react-native bundle" command:\n');
55
-
56
38
  shell.exec(`${getCliPath()} ${reactNativeBundleArgs.join(' ')}`);
57
39
  }
58
-
59
- module.exports = { runReactNativeBundleCommand };
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import shell from "shelljs";
4
+ import { showLogo } from "./utils/showLogo.js";
5
+ /**
6
+ * npx code-push bundle
7
+ */
8
+ import "./commands/bundleCommand/index.js";
9
+ /**
10
+ * npx code-push create-history
11
+ */
12
+ import "./commands/createHistoryCommand/index.js";
13
+ /**
14
+ * npx code-push update-history
15
+ */
16
+ import "./commands/updateHistoryCommand/index.js";
17
+ /**
18
+ * npx code-push release
19
+ */
20
+ import "./commands/releaseCommand/index.js";
21
+ /**
22
+ * npx code-push show-history
23
+ */
24
+ import "./commands/showHistoryCommand/index.js";
25
+ /**
26
+ * npx code-push init
27
+ */
28
+ import "./commands/initCommand/index.js";
29
+ shell.set("-e");
30
+ shell.set("+v");
31
+ program
32
+ .name("npx code-push")
33
+ .description("Command line interface for @bravemobile/react-native-code-push")
34
+ .version("1.0.0")
35
+ .action(() => {
36
+ showLogo();
37
+ });
38
+ program.parse();
@@ -0,0 +1,19 @@
1
+ /**
2
+ * code based on appcenter-cli
3
+ */
4
+ import fs from "fs";
5
+ export function isDirectory(path) {
6
+ return fs.statSync(path).isDirectory();
7
+ }
8
+ export function generateRandomFilename(length) {
9
+ let filename = '';
10
+ const validChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
11
+ for (let i = 0; i < length; i++) {
12
+ filename += validChar.charAt(Math.floor(Math.random() * validChar.length));
13
+ }
14
+ return filename;
15
+ }
16
+ export function normalizePath(filePath) {
17
+ //replace all backslashes coming from cli running on windows machines by slashes
18
+ return filePath.replace(/\\/g, '/');
19
+ }
@@ -0,0 +1,37 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { createRequire } from "module";
4
+ const nodeRequire = createRequire(import.meta.url);
5
+ /**
6
+ * allows to require a config file with .ts extension
7
+ */
8
+ function requireConfig(filePath) {
9
+ const ext = path.extname(filePath);
10
+ if (ext === '.ts') {
11
+ try {
12
+ nodeRequire('ts-node/register');
13
+ }
14
+ catch {
15
+ console.error('ts-node not found. Please install ts-node as a devDependency.');
16
+ process.exit(1);
17
+ }
18
+ }
19
+ else if (ext === '.js') {
20
+ // do nothing
21
+ }
22
+ else {
23
+ throw new Error(`Unsupported file extension: ${ext}`);
24
+ }
25
+ return nodeRequire(filePath);
26
+ }
27
+ export function findAndReadConfigFile(startDir, configFileName) {
28
+ let dir = startDir;
29
+ while (dir !== path.parse(dir).root) {
30
+ const configPath = path.join(dir, configFileName);
31
+ if (fs.existsSync(configPath)) {
32
+ return requireConfig(configPath);
33
+ }
34
+ dir = path.dirname(dir);
35
+ }
36
+ throw new Error(`${configFileName} not found.`);
37
+ }
@@ -1,165 +1,88 @@
1
1
  /**
2
2
  * code based on appcenter-cli
3
3
  */
4
-
5
4
  /**
6
5
  * NOTE!!! This utility file is duplicated for use by the CodePush service (for server-driven hashing/
7
6
  * integrity checks) and Management SDK (for end-to-end code signing), please keep them in sync.
8
7
  */
9
-
10
- const crypto = require('crypto');
11
- const fs = require('fs');
12
- const path = require('path');
13
- const { isDirectory } = require('./file-utils');
14
- const { walk } = require('./promisfied-fs');
15
-
8
+ import crypto from "crypto";
9
+ import fs from "fs";
10
+ import path from "path";
11
+ import { isDirectory } from "./file-utils.js";
12
+ import { walk } from "./promisfied-fs.js";
16
13
  // Do not throw an exception if either of these modules are missing, as they may not be needed by the
17
14
  // consumer of this file.
18
15
  const HASH_ALGORITHM = 'sha256';
19
16
  class PackageManifest {
20
- /**
21
- * @type {Map<string, string>}
22
- * @private
23
- */
24
17
  _map;
25
-
26
- /**
27
- * @param map {Map<string, string>?}
28
- * @public
29
- */
30
18
  constructor(map) {
31
19
  if (map == null) {
32
20
  map = new Map();
33
21
  }
34
22
  this._map = map;
35
23
  }
36
-
37
- /**
38
- * @return {Map<string, string>}
39
- * @public
40
- */
41
24
  toMap() {
42
25
  return this._map;
43
26
  }
44
-
45
- /**
46
- * @return {string}
47
- * @public
48
- */
49
27
  computePackageHash() {
50
- /**
51
- * @type {string[]}
52
- */
53
28
  let entries = [];
54
29
  this._map.forEach((hash, name) => {
55
30
  entries.push(name + ':' + hash);
56
31
  });
57
-
58
32
  // Make sure this list is alphabetically ordered so that other clients
59
33
  // can also compute this hash easily given the update contents.
60
34
  entries = entries.sort();
61
-
62
35
  return crypto.createHash(HASH_ALGORITHM).update(JSON.stringify(entries)).digest('hex');
63
36
  }
64
-
65
- /**
66
- * @return {string}
67
- * @public
68
- */
69
37
  serialize() {
70
38
  const obj = {};
71
-
72
39
  this._map.forEach(function (value, key) {
73
40
  obj[key] = value;
74
41
  });
75
-
76
42
  return JSON.stringify(obj);
77
43
  }
78
-
79
- /**
80
- * @param filePath {string}
81
- * @return {string}
82
- * @public
83
- */
84
44
  static normalizePath(filePath) {
85
45
  //replace all backslashes coming from cli running on windows machines by slashes
86
46
  return filePath.replace(/\\/g, '/');
87
47
  }
88
-
89
- /**
90
- * @param relativeFilePath {string}
91
- * @return {boolean}
92
- * @public
93
- */
94
48
  static isIgnored(relativeFilePath) {
95
49
  const __MACOSX = '__MACOSX/';
96
50
  const DS_STORE = '.DS_Store';
97
51
  const CODEPUSH_METADATA = '.codepushrelease';
98
- return (
99
- relativeFilePath.startsWith(__MACOSX) ||
52
+ return (relativeFilePath.startsWith(__MACOSX) ||
100
53
  relativeFilePath === DS_STORE ||
101
54
  relativeFilePath.endsWith('/' + DS_STORE) ||
102
55
  relativeFilePath === CODEPUSH_METADATA ||
103
- relativeFilePath.endsWith('/' + CODEPUSH_METADATA)
104
- );
56
+ relativeFilePath.endsWith('/' + CODEPUSH_METADATA));
105
57
  }
106
58
  }
107
-
108
- /**
109
- *
110
- * @param directoryPath {string}
111
- * @param basePath {string}
112
- * @return {Promise<string>}
113
- */
114
- async function generatePackageHashFromDirectory(directoryPath, basePath) {
59
+ export async function generatePackageHashFromDirectory(directoryPath, basePath) {
115
60
  try {
116
61
  if (!isDirectory(directoryPath)) {
117
62
  throw new Error('Not a directory. Please either create a directory, or use hashFile().');
118
63
  }
119
- } catch (error) {
64
+ }
65
+ catch (error) {
120
66
  throw new Error('Directory does not exist. Please either create a directory, or use hashFile().');
121
67
  }
122
-
123
68
  /**
124
69
  * @type {PackageManifest}
125
70
  */
126
71
  const manifest = await generatePackageManifestFromDirectory(directoryPath, basePath);
127
72
  return manifest.computePackageHash();
128
73
  }
129
-
130
- /**
131
- *
132
- * @param directoryPath {string}
133
- * @param basePath {string}
134
- * @return {Promise<PackageManifest>}
135
- */
136
74
  function generatePackageManifestFromDirectory(directoryPath, basePath) {
137
75
  // eslint-disable-next-line no-async-promise-executor
138
76
  return new Promise(async (resolve, reject) => {
139
- /**
140
- * @type {Map<string, string>}
141
- */
142
77
  const fileHashesMap = new Map();
143
-
144
- /**
145
- * @type {string[]}
146
- */
147
78
  const files = await walk(directoryPath);
148
-
149
79
  if (!files || files.length === 0) {
150
80
  reject('Error: Cannot sign the release because no files were found.');
151
81
  return;
152
82
  }
153
-
154
- /**
155
- * @type {Promise<void>}
156
- */
157
83
  // Hash the files sequentially, because streaming them in parallel is not necessarily faster
158
84
  const generateManifestPromise = files.reduce((soFar, filePath) => {
159
85
  return soFar.then(() => {
160
- /**
161
- * @type {string}
162
- */
163
86
  const relativePath = PackageManifest.normalizePath(path.relative(basePath, filePath));
164
87
  if (!PackageManifest.isIgnored(relativePath)) {
165
88
  return hashFile(filePath).then((hash) => {
@@ -168,60 +91,29 @@ function generatePackageManifestFromDirectory(directoryPath, basePath) {
168
91
  }
169
92
  });
170
93
  }, Promise.resolve(null));
171
-
172
94
  generateManifestPromise.then(() => {
173
95
  resolve(new PackageManifest(fileHashesMap));
174
96
  }, reject);
175
97
  });
176
98
  }
177
-
178
- /**
179
- *
180
- * @param filePath {string}
181
- * @return {Promise<string>}
182
- */
183
99
  function hashFile(filePath) {
184
- /**
185
- * @type {fs.ReadStream}
186
- */
187
100
  const readStream = fs.createReadStream(filePath);
188
101
  return hashStream(readStream);
189
102
  }
190
-
191
- /**
192
- *
193
- * @param readStream {stream.Readable}
194
- * @return {Promise<string>}
195
- */
196
103
  function hashStream(readStream) {
197
104
  return new Promise((resolve, reject) => {
198
- /**
199
- * @type {stream.Transform}
200
- */
201
- const _hashStream = crypto.createHash(HASH_ALGORITHM)
202
-
105
+ const _hashStream = crypto.createHash(HASH_ALGORITHM);
203
106
  readStream
204
107
  .on('error', (error) => {
205
- _hashStream.end();
206
- reject(error);
207
- })
108
+ _hashStream.end();
109
+ reject(error);
110
+ })
208
111
  .on('end', () => {
209
- _hashStream.end();
210
-
211
- /**
212
- * @type {Buffer}
213
- */
214
- const buffer = _hashStream.read();
215
- /**
216
- * @type {string}
217
- */
218
- const hash = buffer.toString('hex');
219
-
220
- resolve(hash);
221
- });
222
-
112
+ _hashStream.end();
113
+ const buffer = _hashStream.read();
114
+ const hash = buffer.toString('hex');
115
+ resolve(hash);
116
+ });
223
117
  readStream.pipe(_hashStream);
224
118
  });
225
119
  }
226
-
227
- module.exports = { generatePackageHashFromDirectory };
@@ -1,29 +1,18 @@
1
1
  /**
2
2
  * code based on appcenter-cli
3
3
  */
4
-
5
- const { promises: fs } = require('fs');
6
- const path = require('path');
7
-
8
- /**
9
- *
10
- * @param dir {string}
11
- * @return {Promise<string[]>}
12
- */
13
- async function walk(dir) {
4
+ import { promises as fs } from "fs";
5
+ import path from "path";
6
+ export async function walk(dir) {
14
7
  const stats = await fs.stat(dir);
15
8
  if (stats.isDirectory()) {
16
- /**
17
- * @type {string[]}
18
- */
19
9
  let files = [];
20
10
  for (const file of await fs.readdir(dir)) {
21
11
  files = files.concat(await walk(path.join(dir, file)));
22
12
  }
23
13
  return files;
24
- } else {
14
+ }
15
+ else {
25
16
  return [dir];
26
17
  }
27
18
  }
28
-
29
- module.exports = { walk };
@@ -0,0 +1,21 @@
1
+ export function showLogo() {
2
+ const logo = `
3
+
4
+ +------------------------------------------------------------------+
5
+ | |
6
+ | ______ __ ____ __ |
7
+ | / ____/___ ____/ /__ / __ \\__ _______/ /_ |
8
+ | / / / __ \\/ __ / _ \\/ /_/ / / / / ___/ __ \\ |
9
+ | / /___/ /_/ / /_/ / __/ ____/ /_/ (__ ) / / / |
10
+ | \\____/\\____/\\__,_/\\___/_/ \\__,_/____/_/ /_/ |
11
+ | |
12
+ | |
13
+ | 🚀 @bravemobile/react-native-code-push |
14
+ +------------------------------------------------------------------+
15
+
16
+ Please refer to help command for more information.
17
+
18
+ (interactive mode is not supported yet.)
19
+ `;
20
+ console.log(logo);
21
+ }