@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.
- package/README.md +1 -1
- package/android/app/src/debug/AndroidManifest.xml +9 -0
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePush.java +1 -52
- package/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java +4 -43
- package/bin/code-push.js +6 -0
- package/cli/commands/bundleCommand/{bundleCodePush.js → bundleCodePush.ts} +16 -24
- package/cli/commands/bundleCommand/{index.js → index.ts} +13 -14
- package/cli/commands/createHistoryCommand/{createReleaseHistory.js → createReleaseHistory.ts} +11 -28
- package/cli/commands/createHistoryCommand/{index.js → index.ts} +12 -13
- package/cli/commands/initCommand/{index.js → index.ts} +3 -3
- package/cli/commands/initCommand/{initAndroid.js → initAndroid.ts} +6 -11
- package/cli/commands/initCommand/initIos.ts +123 -0
- package/cli/commands/initCommand/test/initAndroid.test.ts +86 -0
- package/cli/commands/initCommand/test/initIos.test.ts +99 -0
- package/cli/commands/releaseCommand/{addToReleaseHistory.js → addToReleaseHistory.ts} +17 -45
- package/cli/commands/releaseCommand/{index.js → index.ts} +24 -25
- package/cli/commands/releaseCommand/release.ts +72 -0
- package/cli/commands/showHistoryCommand/{index.js → index.ts} +11 -12
- package/cli/commands/updateHistoryCommand/{index.js → index.ts} +17 -18
- package/cli/commands/updateHistoryCommand/{updateReleaseHistory.js → updateReleaseHistory.ts} +15 -41
- package/cli/constant.ts +4 -0
- package/cli/dist/commands/bundleCommand/bundleCodePush.js +34 -0
- package/cli/dist/commands/bundleCommand/index.js +14 -0
- package/cli/dist/commands/createHistoryCommand/createReleaseHistory.js +25 -0
- package/cli/dist/commands/createHistoryCommand/index.js +14 -0
- package/cli/dist/commands/initCommand/index.js +12 -0
- package/cli/dist/commands/initCommand/initAndroid.js +37 -0
- package/cli/{commands → dist/commands}/initCommand/initIos.js +13 -33
- package/cli/dist/commands/initCommand/test/initAndroid.test.js +75 -0
- package/cli/dist/commands/initCommand/test/initIos.test.js +95 -0
- package/cli/dist/commands/releaseCommand/addToReleaseHistory.js +32 -0
- package/cli/dist/commands/releaseCommand/index.js +38 -0
- package/cli/dist/commands/releaseCommand/release.js +36 -0
- package/cli/dist/commands/showHistoryCommand/index.js +14 -0
- package/cli/dist/commands/updateHistoryCommand/index.js +30 -0
- package/cli/dist/commands/updateHistoryCommand/updateReleaseHistory.js +26 -0
- package/cli/dist/constant.js +4 -0
- package/cli/dist/functions/getReactTempDir.js +10 -0
- package/cli/{functions → dist/functions}/makeCodePushBundle.js +5 -11
- package/cli/{functions → dist/functions}/prepareToBundleJS.js +2 -5
- package/cli/{functions → dist/functions}/runExpoBundleCommand.js +3 -21
- package/cli/{functions → dist/functions}/runHermesEmitBinaryCommand.js +12 -68
- package/cli/{functions → dist/functions}/runReactNativeBundleCommand.js +3 -23
- package/cli/dist/index.js +38 -0
- package/cli/dist/utils/file-utils.js +19 -0
- package/cli/dist/utils/fsUtils.js +37 -0
- package/cli/{utils → dist/utils}/hash-utils.js +19 -127
- package/cli/{utils → dist/utils}/promisfied-fs.js +5 -16
- package/cli/dist/utils/showLogo.js +21 -0
- package/cli/{utils → dist/utils}/zip.js +15 -51
- package/cli/functions/{getReactTempDir.js → getReactTempDir.ts} +2 -6
- package/cli/functions/makeCodePushBundle.ts +26 -0
- package/cli/functions/prepareToBundleJS.ts +10 -0
- package/cli/functions/runExpoBundleCommand.ts +45 -0
- package/cli/functions/runHermesEmitBinaryCommand.ts +186 -0
- package/cli/functions/runReactNativeBundleCommand.ts +51 -0
- package/cli/index.ts +48 -0
- package/cli/package.json +33 -0
- package/cli/utils/{file-utils.js → file-utils.ts} +4 -21
- package/cli/utils/{fsUtils.js → fsUtils.ts} +12 -19
- package/cli/utils/hash-utils.ts +146 -0
- package/cli/utils/promisfied-fs.ts +19 -0
- package/cli/utils/{showLogo.js → showLogo.ts} +1 -3
- package/cli/utils/zip.ts +65 -0
- package/package.json +42 -12
- package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
- package/AGENTS.md +0 -32
- package/CONTRIBUTING.md +0 -134
- package/SECURITY.md +0 -41
- package/android/app/src/main/java/com/microsoft/codepush/react/ReactInstanceHolder.java +0 -17
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/android/gradlew +0 -164
- package/android/gradlew.bat +0 -90
- package/babel.config.js +0 -3
- package/cli/commands/releaseCommand/release.js +0 -114
- package/cli/constant.js +0 -6
- package/cli/index.js +0 -49
- package/docs/api-android.md +0 -83
- package/docs/api-ios.md +0 -31
- package/docs/api-js.md +0 -592
- package/docs/multi-deployment-testing-android.md +0 -148
- package/docs/multi-deployment-testing-ios.md +0 -59
- package/eslint.config.mjs +0 -32
- package/scripts/generateBundledResourcesHash.js +0 -125
- package/scripts/getFilesInFolder.js +0 -19
- package/scripts/recordFilesBeforeBundleCommand.js +0 -41
- package/tsconfig.json +0 -18
- package/tslint.json +0 -32
- /package/{CodePush.js → src/CodePush.js} +0 -0
- /package/{logging.js → src/logging.js} +0 -0
- /package/{package-mixins.js → src/package-mixins.js} +0 -0
- /package/{versioning → src/versioning}/BaseVersioning.js +0 -0
- /package/{versioning → src/versioning}/BaseVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/IncrementalVersioning.js +0 -0
- /package/{versioning → src/versioning}/IncrementalVersioning.test.js +0 -0
- /package/{versioning → src/versioning}/SemverVersioning.js +0 -0
- /package/{versioning → src/versioning}/SemverVersioning.test.js +0 -0
- /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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
}
|
|
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
|
-
|
|
206
|
-
|
|
207
|
-
|
|
108
|
+
_hashStream.end();
|
|
109
|
+
reject(error);
|
|
110
|
+
})
|
|
208
111
|
.on('end', () => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
}
|
|
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
|
+
}
|