@bravemobile/react-native-code-push 12.0.1 → 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.
- package/README.md +1 -1
- 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.js → initAndroid.test.ts} +5 -4
- package/cli/commands/initCommand/test/{initIos.test.js → initIos.test.ts} +2 -1
- 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/expo/plugin/withCodePush.js +1 -2
- package/package.json +42 -12
- package/{AlertAdapter.js → src/AlertAdapter.js} +5 -5
- 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/app.plugin.js +0 -1
- 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
|
@@ -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();
|
package/cli/package.json
ADDED
|
@@ -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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
40
|
-
return config;
|
|
36
|
+
return requireConfig(configPath);
|
|
41
37
|
}
|
|
42
38
|
dir = path.dirname(dir);
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
return null;
|
|
41
|
+
throw new Error(`${configFileName} not found.`);
|
|
47
42
|
}
|
|
48
|
-
|
|
49
|
-
module.exports = { findAndReadConfigFile };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code based on appcenter-cli
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* NOTE!!! This utility file is duplicated for use by the CodePush service (for server-driven hashing/
|
|
7
|
+
* integrity checks) and Management SDK (for end-to-end code signing), please keep them in sync.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import crypto from "crypto";
|
|
11
|
+
import fs from "fs";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { isDirectory } from "./file-utils.js";
|
|
14
|
+
import { walk } from "./promisfied-fs.js";
|
|
15
|
+
|
|
16
|
+
// Do not throw an exception if either of these modules are missing, as they may not be needed by the
|
|
17
|
+
// consumer of this file.
|
|
18
|
+
const HASH_ALGORITHM = 'sha256';
|
|
19
|
+
class PackageManifest {
|
|
20
|
+
private _map: Map<string, string>;
|
|
21
|
+
|
|
22
|
+
constructor(map?: Map<string, string>) {
|
|
23
|
+
if (map == null) {
|
|
24
|
+
map = new Map();
|
|
25
|
+
}
|
|
26
|
+
this._map = map;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
toMap(): Map<string, string> {
|
|
30
|
+
return this._map;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
computePackageHash(): string {
|
|
34
|
+
let entries: string[] = [];
|
|
35
|
+
this._map.forEach((hash, name) => {
|
|
36
|
+
entries.push(name + ':' + hash);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Make sure this list is alphabetically ordered so that other clients
|
|
40
|
+
// can also compute this hash easily given the update contents.
|
|
41
|
+
entries = entries.sort();
|
|
42
|
+
|
|
43
|
+
return crypto.createHash(HASH_ALGORITHM).update(JSON.stringify(entries)).digest('hex');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
serialize(): string {
|
|
47
|
+
const obj: Record<string, string> = {};
|
|
48
|
+
|
|
49
|
+
this._map.forEach(function (value, key) {
|
|
50
|
+
obj[key] = value;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
return JSON.stringify(obj);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static normalizePath(filePath: string): string {
|
|
57
|
+
//replace all backslashes coming from cli running on windows machines by slashes
|
|
58
|
+
return filePath.replace(/\\/g, '/');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static isIgnored(relativeFilePath: string): boolean {
|
|
62
|
+
const __MACOSX = '__MACOSX/';
|
|
63
|
+
const DS_STORE = '.DS_Store';
|
|
64
|
+
const CODEPUSH_METADATA = '.codepushrelease';
|
|
65
|
+
return (
|
|
66
|
+
relativeFilePath.startsWith(__MACOSX) ||
|
|
67
|
+
relativeFilePath === DS_STORE ||
|
|
68
|
+
relativeFilePath.endsWith('/' + DS_STORE) ||
|
|
69
|
+
relativeFilePath === CODEPUSH_METADATA ||
|
|
70
|
+
relativeFilePath.endsWith('/' + CODEPUSH_METADATA)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function generatePackageHashFromDirectory(directoryPath: string, basePath: string) {
|
|
76
|
+
try {
|
|
77
|
+
if (!isDirectory(directoryPath)) {
|
|
78
|
+
throw new Error('Not a directory. Please either create a directory, or use hashFile().');
|
|
79
|
+
}
|
|
80
|
+
} catch (error) {
|
|
81
|
+
throw new Error('Directory does not exist. Please either create a directory, or use hashFile().');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @type {PackageManifest}
|
|
86
|
+
*/
|
|
87
|
+
const manifest = await generatePackageManifestFromDirectory(directoryPath, basePath);
|
|
88
|
+
return manifest.computePackageHash();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function generatePackageManifestFromDirectory(directoryPath: string, basePath: string): Promise<PackageManifest> {
|
|
92
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
93
|
+
return new Promise(async (resolve, reject) => {
|
|
94
|
+
const fileHashesMap = new Map<string, string>();
|
|
95
|
+
|
|
96
|
+
const files: string[] = await walk(directoryPath);
|
|
97
|
+
|
|
98
|
+
if (!files || files.length === 0) {
|
|
99
|
+
reject('Error: Cannot sign the release because no files were found.');
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Hash the files sequentially, because streaming them in parallel is not necessarily faster
|
|
104
|
+
const generateManifestPromise = files.reduce<Promise<unknown>>((soFar, filePath) => {
|
|
105
|
+
return soFar.then(() => {
|
|
106
|
+
const relativePath: string = PackageManifest.normalizePath(path.relative(basePath, filePath));
|
|
107
|
+
if (!PackageManifest.isIgnored(relativePath)) {
|
|
108
|
+
return hashFile(filePath).then((hash) => {
|
|
109
|
+
fileHashesMap.set(relativePath, hash);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}, Promise.resolve(null));
|
|
114
|
+
|
|
115
|
+
generateManifestPromise.then(() => {
|
|
116
|
+
resolve(new PackageManifest(fileHashesMap));
|
|
117
|
+
}, reject);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function hashFile(filePath: string): Promise<string> {
|
|
122
|
+
const readStream: fs.ReadStream = fs.createReadStream(filePath);
|
|
123
|
+
return hashStream(readStream);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function hashStream(readStream: fs.ReadStream): Promise<string> {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
const _hashStream = crypto.createHash(HASH_ALGORITHM)
|
|
129
|
+
|
|
130
|
+
readStream
|
|
131
|
+
.on('error', (error) => {
|
|
132
|
+
_hashStream.end();
|
|
133
|
+
reject(error);
|
|
134
|
+
})
|
|
135
|
+
.on('end', () => {
|
|
136
|
+
_hashStream.end();
|
|
137
|
+
|
|
138
|
+
const buffer = _hashStream.read();
|
|
139
|
+
const hash: string = buffer.toString('hex');
|
|
140
|
+
|
|
141
|
+
resolve(hash);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
readStream.pipe(_hashStream);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code based on appcenter-cli
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { promises as fs } from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
|
|
8
|
+
export async function walk(dir: string): Promise<string[]> {
|
|
9
|
+
const stats = await fs.stat(dir);
|
|
10
|
+
if (stats.isDirectory()) {
|
|
11
|
+
let files: string[] = [];
|
|
12
|
+
for (const file of await fs.readdir(dir)) {
|
|
13
|
+
files = files.concat(await walk(path.join(dir, file)));
|
|
14
|
+
}
|
|
15
|
+
return files;
|
|
16
|
+
} else {
|
|
17
|
+
return [dir];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function showLogo() {
|
|
1
|
+
export function showLogo() {
|
|
2
2
|
const logo = `
|
|
3
3
|
|
|
4
4
|
+------------------------------------------------------------------+
|
|
@@ -19,5 +19,3 @@ Please refer to help command for more information.
|
|
|
19
19
|
`;
|
|
20
20
|
console.log(logo);
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
module.exports = { showLogo };
|
package/cli/utils/zip.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* code based on appcenter-cli
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import yazl from "yazl";
|
|
8
|
+
import { generateRandomFilename, normalizePath, isDirectory } from "./file-utils.js";
|
|
9
|
+
import { walk } from "./promisfied-fs.js";
|
|
10
|
+
|
|
11
|
+
type ReleaseFile = { sourceLocation: string, targetLocation: string };
|
|
12
|
+
|
|
13
|
+
export function zip(updateContentsPath: string): Promise<string> {
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
16
|
+
return new Promise(async (resolve, reject) => {
|
|
17
|
+
const releaseFiles: ReleaseFile[] = [];
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
if (!isDirectory(updateContentsPath)) {
|
|
21
|
+
releaseFiles.push({
|
|
22
|
+
sourceLocation: updateContentsPath,
|
|
23
|
+
targetLocation: normalizePath(path.basename(updateContentsPath)), // Put the file in the root
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
} catch (error: unknown) {
|
|
27
|
+
if (error instanceof Error) {
|
|
28
|
+
error.message = error.message + " Make sure you have added the platform you are making a release to.`.";
|
|
29
|
+
}
|
|
30
|
+
reject(error);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const directoryPath = updateContentsPath;
|
|
34
|
+
const baseDirectoryPath = path.join(directoryPath, '..'); // For legacy reasons, put the root directory in the zip
|
|
35
|
+
|
|
36
|
+
const files: string[] = await walk(updateContentsPath);
|
|
37
|
+
|
|
38
|
+
files.forEach((filePath) => {
|
|
39
|
+
const relativePath = path.relative(baseDirectoryPath, filePath);
|
|
40
|
+
releaseFiles.push({
|
|
41
|
+
sourceLocation: filePath,
|
|
42
|
+
targetLocation: normalizePath(relativePath),
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const packagePath = path.join(process.cwd(), generateRandomFilename(15) + '.zip');
|
|
47
|
+
const zipFile = new yazl.ZipFile();
|
|
48
|
+
const writeStream = fs.createWriteStream(packagePath);
|
|
49
|
+
|
|
50
|
+
zipFile.outputStream
|
|
51
|
+
.pipe(writeStream)
|
|
52
|
+
.on('error', (error: unknown) => {
|
|
53
|
+
reject(error);
|
|
54
|
+
})
|
|
55
|
+
.on('close', () => {
|
|
56
|
+
resolve(packagePath);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
releaseFiles.forEach((releaseFile) => {
|
|
60
|
+
zipFile.addFile(releaseFile.sourceLocation, releaseFile.targetLocation);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
zipFile.end();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const { createRunOncePlugin } = require('expo/config-plugins');
|
|
2
|
-
const {
|
|
2
|
+
const { withAndroidMainApplicationDependency } = require('./withCodePushAndroid');
|
|
3
3
|
const { withIosBridgingHeader, withIosAppDelegateDependency } = require('./withCodePushIos');
|
|
4
4
|
const pkg = require('../../package.json');
|
|
5
5
|
|
|
6
6
|
const withCodePush = (config) => {
|
|
7
|
-
config = withAndroidBuildScriptDependency(config);
|
|
8
7
|
config = withAndroidMainApplicationDependency(config);
|
|
9
8
|
config = withIosBridgingHeader(config);
|
|
10
9
|
config = withIosAppDelegateDependency(config);
|