@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
|
@@ -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
|
+
}
|
|
@@ -1,30 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* code based on appcenter-cli
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
}
|
|
36
|
-
|
|
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
|
-
|
|
76
|
-
|
|
43
|
+
reject(error);
|
|
44
|
+
})
|
|
77
45
|
.on('close', () => {
|
|
78
|
-
|
|
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
|
-
|
|
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
|
+
}
|