@appcircle/codepush-cli 0.0.1-alpha.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/.eslintrc.json +17 -0
- package/.github/pre-push +30 -0
- package/.github/prepare-commit--msg +2 -0
- package/CONTRIBUTING.md +71 -0
- package/Dockerfile +9 -0
- package/Jenkinsfile +45 -0
- package/README.md +837 -0
- package/bin/script/acquisition-sdk.js +178 -0
- package/bin/script/cli.js +23 -0
- package/bin/script/command-executor.js +1292 -0
- package/bin/script/command-parser.js +1123 -0
- package/bin/script/commands/debug.js +125 -0
- package/bin/script/hash-utils.js +203 -0
- package/bin/script/index.js +5 -0
- package/bin/script/management-sdk.js +454 -0
- package/bin/script/react-native-utils.js +249 -0
- package/bin/script/sign.js +69 -0
- package/bin/script/types/cli.js +40 -0
- package/bin/script/types/rest-definitions.js +19 -0
- package/bin/script/types.js +4 -0
- package/bin/script/utils/file-utils.js +50 -0
- package/bin/test/acquisition-rest-mock.js +108 -0
- package/bin/test/acquisition-sdk.js +188 -0
- package/bin/test/cli.js +1342 -0
- package/bin/test/hash-utils.js +149 -0
- package/bin/test/management-sdk.js +338 -0
- package/package.json +74 -0
- package/prettier.config.js +7 -0
- package/script/acquisition-sdk.ts +273 -0
- package/script/cli.ts +27 -0
- package/script/command-executor.ts +1614 -0
- package/script/command-parser.ts +1340 -0
- package/script/commands/debug.ts +148 -0
- package/script/hash-utils.ts +241 -0
- package/script/index.ts +5 -0
- package/script/management-sdk.ts +627 -0
- package/script/react-native-utils.ts +283 -0
- package/script/sign.ts +80 -0
- package/script/types/cli.ts +234 -0
- package/script/types/rest-definitions.ts +152 -0
- package/script/types.ts +35 -0
- package/script/utils/check-package.mjs +11 -0
- package/script/utils/file-utils.ts +46 -0
- package/test/acquisition-rest-mock.ts +125 -0
- package/test/acquisition-sdk.ts +272 -0
- package/test/cli.ts +1692 -0
- package/test/hash-utils.ts +170 -0
- package/test/management-sdk.ts +438 -0
- package/test/resources/TestApp/android/app/build.gradle +56 -0
- package/test/resources/TestApp/iOS/TestApp/Info.plist +49 -0
- package/test/resources/TestApp/index.android.js +2 -0
- package/test/resources/TestApp/index.ios.js +2 -0
- package/test/resources/TestApp/index.windows.js +2 -0
- package/test/resources/TestApp/package.json +6 -0
- package/test/resources/TestApp/windows/TestApp/Package.appxmanifest +46 -0
- package/test/resources/ignoredMetadata.zip +0 -0
- package/test/resources/test.zip +0 -0
- package/test/superagent-mock-config.js +58 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getReactNativeVersion = exports.directoryExistsSync = exports.getiOSHermesEnabled = exports.getAndroidHermesEnabled = exports.runHermesEmitBinaryCommand = exports.isValidVersion = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const childProcess = require("child_process");
|
|
8
|
+
const semver_1 = require("semver");
|
|
9
|
+
const file_utils_1 = require("./utils/file-utils");
|
|
10
|
+
const g2js = require("gradle-to-js/lib/parser");
|
|
11
|
+
function isValidVersion(version) {
|
|
12
|
+
return !!(0, semver_1.valid)(version) || /^\d+\.\d+$/.test(version);
|
|
13
|
+
}
|
|
14
|
+
exports.isValidVersion = isValidVersion;
|
|
15
|
+
async function runHermesEmitBinaryCommand(bundleName, outputFolder, sourcemapOutput, extraHermesFlags, gradleFile) {
|
|
16
|
+
const hermesArgs = [];
|
|
17
|
+
const envNodeArgs = process.env.CODE_PUSH_NODE_ARGS;
|
|
18
|
+
if (typeof envNodeArgs !== "undefined") {
|
|
19
|
+
Array.prototype.push.apply(hermesArgs, envNodeArgs.trim().split(/\s+/));
|
|
20
|
+
}
|
|
21
|
+
Array.prototype.push.apply(hermesArgs, [
|
|
22
|
+
"-emit-binary",
|
|
23
|
+
"-out",
|
|
24
|
+
path.join(outputFolder, bundleName + ".hbc"),
|
|
25
|
+
path.join(outputFolder, bundleName),
|
|
26
|
+
...extraHermesFlags,
|
|
27
|
+
]);
|
|
28
|
+
if (sourcemapOutput) {
|
|
29
|
+
hermesArgs.push("-output-source-map");
|
|
30
|
+
}
|
|
31
|
+
console.log(chalk.cyan("Converting JS bundle to byte code via Hermes, running command:\n"));
|
|
32
|
+
const hermesCommand = await getHermesCommand(gradleFile);
|
|
33
|
+
const hermesProcess = childProcess.spawn(hermesCommand, hermesArgs);
|
|
34
|
+
console.log(`${hermesCommand} ${hermesArgs.join(" ")}`);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
hermesProcess.stdout.on("data", (data) => {
|
|
37
|
+
console.log(data.toString().trim());
|
|
38
|
+
});
|
|
39
|
+
hermesProcess.stderr.on("data", (data) => {
|
|
40
|
+
console.error(data.toString().trim());
|
|
41
|
+
});
|
|
42
|
+
hermesProcess.on("close", (exitCode, signal) => {
|
|
43
|
+
if (exitCode !== 0) {
|
|
44
|
+
reject(new Error(`"hermes" command failed (exitCode=${exitCode}, signal=${signal}).`));
|
|
45
|
+
}
|
|
46
|
+
// Copy HBC bundle to overwrite JS bundle
|
|
47
|
+
const source = path.join(outputFolder, bundleName + ".hbc");
|
|
48
|
+
const destination = path.join(outputFolder, bundleName);
|
|
49
|
+
fs.copyFile(source, destination, (err) => {
|
|
50
|
+
if (err) {
|
|
51
|
+
console.error(err);
|
|
52
|
+
reject(new Error(`Copying file ${source} to ${destination} failed. "hermes" previously exited with code ${exitCode}.`));
|
|
53
|
+
}
|
|
54
|
+
fs.unlink(source, (err) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
console.error(err);
|
|
57
|
+
reject(err);
|
|
58
|
+
}
|
|
59
|
+
resolve(null);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}).then(() => {
|
|
64
|
+
if (!sourcemapOutput) {
|
|
65
|
+
// skip source map compose if source map is not enabled
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const composeSourceMapsPath = getComposeSourceMapsPath();
|
|
69
|
+
if (!composeSourceMapsPath) {
|
|
70
|
+
throw new Error("react-native compose-source-maps.js scripts is not found");
|
|
71
|
+
}
|
|
72
|
+
const jsCompilerSourceMapFile = path.join(outputFolder, bundleName + ".hbc" + ".map");
|
|
73
|
+
if (!fs.existsSync(jsCompilerSourceMapFile)) {
|
|
74
|
+
throw new Error(`sourcemap file ${jsCompilerSourceMapFile} is not found`);
|
|
75
|
+
}
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const composeSourceMapsArgs = [composeSourceMapsPath, sourcemapOutput, jsCompilerSourceMapFile, "-o", sourcemapOutput];
|
|
78
|
+
// https://github.com/facebook/react-native/blob/master/react.gradle#L211
|
|
79
|
+
// https://github.com/facebook/react-native/blob/master/scripts/react-native-xcode.sh#L178
|
|
80
|
+
// packager.sourcemap.map + hbc.sourcemap.map = sourcemap.map
|
|
81
|
+
const composeSourceMapsProcess = childProcess.spawn("node", composeSourceMapsArgs);
|
|
82
|
+
console.log(`${composeSourceMapsPath} ${composeSourceMapsArgs.join(" ")}`);
|
|
83
|
+
composeSourceMapsProcess.stdout.on("data", (data) => {
|
|
84
|
+
console.log(data.toString().trim());
|
|
85
|
+
});
|
|
86
|
+
composeSourceMapsProcess.stderr.on("data", (data) => {
|
|
87
|
+
console.error(data.toString().trim());
|
|
88
|
+
});
|
|
89
|
+
composeSourceMapsProcess.on("close", (exitCode, signal) => {
|
|
90
|
+
if (exitCode !== 0) {
|
|
91
|
+
reject(new Error(`"compose-source-maps" command failed (exitCode=${exitCode}, signal=${signal}).`));
|
|
92
|
+
}
|
|
93
|
+
// Delete the HBC sourceMap, otherwise it will be included in 'code-push' bundle as well
|
|
94
|
+
fs.unlink(jsCompilerSourceMapFile, (err) => {
|
|
95
|
+
if (err) {
|
|
96
|
+
console.error(err);
|
|
97
|
+
reject(err);
|
|
98
|
+
}
|
|
99
|
+
resolve(null);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
exports.runHermesEmitBinaryCommand = runHermesEmitBinaryCommand;
|
|
106
|
+
function parseBuildGradleFile(gradleFile) {
|
|
107
|
+
let buildGradlePath = path.join("android", "app");
|
|
108
|
+
if (gradleFile) {
|
|
109
|
+
buildGradlePath = gradleFile;
|
|
110
|
+
}
|
|
111
|
+
if (fs.lstatSync(buildGradlePath).isDirectory()) {
|
|
112
|
+
buildGradlePath = path.join(buildGradlePath, "build.gradle");
|
|
113
|
+
}
|
|
114
|
+
if ((0, file_utils_1.fileDoesNotExistOrIsDirectory)(buildGradlePath)) {
|
|
115
|
+
throw new Error(`Unable to find gradle file "${buildGradlePath}".`);
|
|
116
|
+
}
|
|
117
|
+
return g2js.parseFile(buildGradlePath).catch(() => {
|
|
118
|
+
throw new Error(`Unable to parse the "${buildGradlePath}" file. Please ensure it is a well-formed Gradle file.`);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
async function getHermesCommandFromGradle(gradleFile) {
|
|
122
|
+
const buildGradle = await parseBuildGradleFile(gradleFile);
|
|
123
|
+
const hermesCommandProperty = Array.from(buildGradle["project.ext.react"] || []).find((prop) => prop.trim().startsWith("hermesCommand:"));
|
|
124
|
+
if (hermesCommandProperty) {
|
|
125
|
+
return hermesCommandProperty.replace("hermesCommand:", "").trim().slice(1, -1);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return "";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function getAndroidHermesEnabled(gradleFile) {
|
|
132
|
+
return parseBuildGradleFile(gradleFile).then((buildGradle) => {
|
|
133
|
+
return Array.from(buildGradle["project.ext.react"] || []).some((line) => /^enableHermes\s{0,}:\s{0,}true/.test(line));
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.getAndroidHermesEnabled = getAndroidHermesEnabled;
|
|
137
|
+
function getiOSHermesEnabled(podFile) {
|
|
138
|
+
let podPath = path.join("ios", "Podfile");
|
|
139
|
+
if (podFile) {
|
|
140
|
+
podPath = podFile;
|
|
141
|
+
}
|
|
142
|
+
if ((0, file_utils_1.fileDoesNotExistOrIsDirectory)(podPath)) {
|
|
143
|
+
throw new Error(`Unable to find Podfile file "${podPath}".`);
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const podFileContents = fs.readFileSync(podPath).toString();
|
|
147
|
+
return /([^#\n]*:?hermes_enabled(\s+|\n+)?(=>|:)(\s+|\n+)?true)/.test(podFileContents);
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.getiOSHermesEnabled = getiOSHermesEnabled;
|
|
154
|
+
function getHermesOSBin() {
|
|
155
|
+
switch (process.platform) {
|
|
156
|
+
case "win32":
|
|
157
|
+
return "win64-bin";
|
|
158
|
+
case "darwin":
|
|
159
|
+
return "osx-bin";
|
|
160
|
+
case "freebsd":
|
|
161
|
+
case "linux":
|
|
162
|
+
case "sunos":
|
|
163
|
+
default:
|
|
164
|
+
return "linux64-bin";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function getHermesOSExe() {
|
|
168
|
+
const react63orAbove = (0, semver_1.compare)((0, semver_1.coerce)(getReactNativeVersion()).version, "0.63.0") !== -1;
|
|
169
|
+
const hermesExecutableName = react63orAbove ? "hermesc" : "hermes";
|
|
170
|
+
switch (process.platform) {
|
|
171
|
+
case "win32":
|
|
172
|
+
return hermesExecutableName + ".exe";
|
|
173
|
+
default:
|
|
174
|
+
return hermesExecutableName;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function getHermesCommand(gradleFile) {
|
|
178
|
+
const fileExists = (file) => {
|
|
179
|
+
try {
|
|
180
|
+
return fs.statSync(file).isFile();
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
// Hermes is bundled with react-native since 0.69
|
|
187
|
+
const bundledHermesEngine = path.join(getReactNativePackagePath(), "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
188
|
+
if (fileExists(bundledHermesEngine)) {
|
|
189
|
+
return bundledHermesEngine;
|
|
190
|
+
}
|
|
191
|
+
const gradleHermesCommand = await getHermesCommandFromGradle(gradleFile);
|
|
192
|
+
if (gradleHermesCommand) {
|
|
193
|
+
return path.join("android", "app", gradleHermesCommand.replace("%OS-BIN%", getHermesOSBin()));
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// assume if hermes-engine exists it should be used instead of hermesvm
|
|
197
|
+
const hermesEngine = path.join("node_modules", "hermes-engine", getHermesOSBin(), getHermesOSExe());
|
|
198
|
+
if (fileExists(hermesEngine)) {
|
|
199
|
+
return hermesEngine;
|
|
200
|
+
}
|
|
201
|
+
return path.join("node_modules", "hermesvm", getHermesOSBin(), "hermes");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function getComposeSourceMapsPath() {
|
|
205
|
+
// detect if compose-source-maps.js script exists
|
|
206
|
+
const composeSourceMaps = path.join(getReactNativePackagePath(), "scripts", "compose-source-maps.js");
|
|
207
|
+
if (fs.existsSync(composeSourceMaps)) {
|
|
208
|
+
return composeSourceMaps;
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
function getReactNativePackagePath() {
|
|
213
|
+
const result = childProcess.spawnSync("node", ["--print", "require.resolve('react-native/package.json')"]);
|
|
214
|
+
const packagePath = path.dirname(result.stdout.toString());
|
|
215
|
+
if (result.status === 0 && directoryExistsSync(packagePath)) {
|
|
216
|
+
return packagePath;
|
|
217
|
+
}
|
|
218
|
+
return path.join("node_modules", "react-native");
|
|
219
|
+
}
|
|
220
|
+
function directoryExistsSync(dirname) {
|
|
221
|
+
try {
|
|
222
|
+
return fs.statSync(dirname).isDirectory();
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
if (err.code !== "ENOENT") {
|
|
226
|
+
throw err;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
exports.directoryExistsSync = directoryExistsSync;
|
|
232
|
+
function getReactNativeVersion() {
|
|
233
|
+
let packageJsonFilename;
|
|
234
|
+
let projectPackageJson;
|
|
235
|
+
try {
|
|
236
|
+
packageJsonFilename = path.join(process.cwd(), "package.json");
|
|
237
|
+
projectPackageJson = JSON.parse(fs.readFileSync(packageJsonFilename, "utf-8"));
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
throw new Error(`Unable to find or read "package.json" in the CWD. The "release-react" command must be executed in a React Native project folder.`);
|
|
241
|
+
}
|
|
242
|
+
const projectName = projectPackageJson.name;
|
|
243
|
+
if (!projectName) {
|
|
244
|
+
throw new Error(`The "package.json" file in the CWD does not have the "name" field set.`);
|
|
245
|
+
}
|
|
246
|
+
return ((projectPackageJson.dependencies && projectPackageJson.dependencies["react-native"]) ||
|
|
247
|
+
(projectPackageJson.devDependencies && projectPackageJson.devDependencies["react-native"]));
|
|
248
|
+
}
|
|
249
|
+
exports.getReactNativeVersion = getReactNativeVersion;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs = require("fs/promises");
|
|
4
|
+
const hashUtils = require("./hash-utils");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const jwt = require("jsonwebtoken");
|
|
7
|
+
const file_utils_1 = require("./utils/file-utils");
|
|
8
|
+
const CURRENT_CLAIM_VERSION = "1.0.0";
|
|
9
|
+
const METADATA_FILE_NAME = ".codepushrelease";
|
|
10
|
+
async function sign(privateKeyPath, updateContentsPath) {
|
|
11
|
+
if (!privateKeyPath) {
|
|
12
|
+
return Promise.resolve(null);
|
|
13
|
+
}
|
|
14
|
+
let privateKey;
|
|
15
|
+
try {
|
|
16
|
+
privateKey = await fs.readFile(privateKeyPath);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
return Promise.reject(new Error(`The path specified for the signing key ("${privateKeyPath}") was not valid.`));
|
|
20
|
+
}
|
|
21
|
+
// If releasing a single file, copy the file to a temporary 'CodePush' directory in which to publish the release
|
|
22
|
+
try {
|
|
23
|
+
if (!(0, file_utils_1.isDirectory)(updateContentsPath)) {
|
|
24
|
+
updateContentsPath = (0, file_utils_1.copyFileToTmpDir)(updateContentsPath);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
Promise.reject(error);
|
|
29
|
+
}
|
|
30
|
+
const signatureFilePath = path.join(updateContentsPath, METADATA_FILE_NAME);
|
|
31
|
+
let prevSignatureExists = true;
|
|
32
|
+
try {
|
|
33
|
+
await fs.access(signatureFilePath, fs.constants.F_OK);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err.code === "ENOENT") {
|
|
37
|
+
prevSignatureExists = false;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return Promise.reject(new Error(`Could not delete previous release signature at ${signatureFilePath}.
|
|
41
|
+
Please, check your access rights.`));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (prevSignatureExists) {
|
|
45
|
+
console.log(`Deleting previous release signature at ${signatureFilePath}`);
|
|
46
|
+
await fs.rmdir(signatureFilePath);
|
|
47
|
+
}
|
|
48
|
+
const hash = await hashUtils.generatePackageHashFromDirectory(updateContentsPath, path.join(updateContentsPath, ".."));
|
|
49
|
+
const claims = {
|
|
50
|
+
claimVersion: CURRENT_CLAIM_VERSION,
|
|
51
|
+
contentHash: hash,
|
|
52
|
+
};
|
|
53
|
+
return new Promise((resolve, reject) => {
|
|
54
|
+
jwt.sign(claims, privateKey, { algorithm: "RS256" }, async (err, signedJwt) => {
|
|
55
|
+
if (err) {
|
|
56
|
+
reject(new Error("The specified signing key file was not valid"));
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
await fs.writeFile(signatureFilePath, signedJwt);
|
|
60
|
+
console.log(`Generated a release signature and wrote it to ${signatureFilePath}`);
|
|
61
|
+
resolve(null);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
exports.default = sign;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CommandType = void 0;
|
|
6
|
+
var CommandType;
|
|
7
|
+
(function (CommandType) {
|
|
8
|
+
CommandType[CommandType["accessKeyAdd"] = 0] = "accessKeyAdd";
|
|
9
|
+
CommandType[CommandType["accessKeyPatch"] = 1] = "accessKeyPatch";
|
|
10
|
+
CommandType[CommandType["accessKeyList"] = 2] = "accessKeyList";
|
|
11
|
+
CommandType[CommandType["accessKeyRemove"] = 3] = "accessKeyRemove";
|
|
12
|
+
CommandType[CommandType["appAdd"] = 4] = "appAdd";
|
|
13
|
+
CommandType[CommandType["appList"] = 5] = "appList";
|
|
14
|
+
CommandType[CommandType["appRemove"] = 6] = "appRemove";
|
|
15
|
+
CommandType[CommandType["appRename"] = 7] = "appRename";
|
|
16
|
+
CommandType[CommandType["appTransfer"] = 8] = "appTransfer";
|
|
17
|
+
CommandType[CommandType["collaboratorAdd"] = 9] = "collaboratorAdd";
|
|
18
|
+
CommandType[CommandType["collaboratorList"] = 10] = "collaboratorList";
|
|
19
|
+
CommandType[CommandType["collaboratorRemove"] = 11] = "collaboratorRemove";
|
|
20
|
+
CommandType[CommandType["debug"] = 12] = "debug";
|
|
21
|
+
CommandType[CommandType["deploymentAdd"] = 13] = "deploymentAdd";
|
|
22
|
+
CommandType[CommandType["deploymentHistory"] = 14] = "deploymentHistory";
|
|
23
|
+
CommandType[CommandType["deploymentHistoryClear"] = 15] = "deploymentHistoryClear";
|
|
24
|
+
CommandType[CommandType["deploymentList"] = 16] = "deploymentList";
|
|
25
|
+
CommandType[CommandType["deploymentMetrics"] = 17] = "deploymentMetrics";
|
|
26
|
+
CommandType[CommandType["deploymentRemove"] = 18] = "deploymentRemove";
|
|
27
|
+
CommandType[CommandType["deploymentRename"] = 19] = "deploymentRename";
|
|
28
|
+
CommandType[CommandType["link"] = 20] = "link";
|
|
29
|
+
CommandType[CommandType["login"] = 21] = "login";
|
|
30
|
+
CommandType[CommandType["logout"] = 22] = "logout";
|
|
31
|
+
CommandType[CommandType["patch"] = 23] = "patch";
|
|
32
|
+
CommandType[CommandType["promote"] = 24] = "promote";
|
|
33
|
+
CommandType[CommandType["register"] = 25] = "register";
|
|
34
|
+
CommandType[CommandType["release"] = 26] = "release";
|
|
35
|
+
CommandType[CommandType["releaseReact"] = 27] = "releaseReact";
|
|
36
|
+
CommandType[CommandType["rollback"] = 28] = "rollback";
|
|
37
|
+
CommandType[CommandType["sessionList"] = 29] = "sessionList";
|
|
38
|
+
CommandType[CommandType["sessionRemove"] = 30] = "sessionRemove";
|
|
39
|
+
CommandType[CommandType["whoami"] = 31] = "whoami";
|
|
40
|
+
})(CommandType || (exports.CommandType = CommandType = {}));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
__exportStar(require("./rest-definitions"), exports);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizePath = exports.fileDoesNotExistOrIsDirectory = exports.copyFileToTmpDir = exports.fileExists = exports.isDirectory = exports.isBinaryOrZip = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const rimraf = require("rimraf");
|
|
7
|
+
const temp = require("temp");
|
|
8
|
+
function isBinaryOrZip(path) {
|
|
9
|
+
return path.search(/\.zip$/i) !== -1 || path.search(/\.apk$/i) !== -1 || path.search(/\.ipa$/i) !== -1;
|
|
10
|
+
}
|
|
11
|
+
exports.isBinaryOrZip = isBinaryOrZip;
|
|
12
|
+
function isDirectory(path) {
|
|
13
|
+
return fs.statSync(path).isDirectory();
|
|
14
|
+
}
|
|
15
|
+
exports.isDirectory = isDirectory;
|
|
16
|
+
function fileExists(file) {
|
|
17
|
+
try {
|
|
18
|
+
return fs.statSync(file).isFile();
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.fileExists = fileExists;
|
|
25
|
+
;
|
|
26
|
+
function copyFileToTmpDir(filePath) {
|
|
27
|
+
if (!isDirectory(filePath)) {
|
|
28
|
+
const outputFolderPath = temp.mkdirSync("code-push");
|
|
29
|
+
rimraf.sync(outputFolderPath);
|
|
30
|
+
fs.mkdirSync(outputFolderPath);
|
|
31
|
+
const outputFilePath = path.join(outputFolderPath, path.basename(filePath));
|
|
32
|
+
fs.writeFileSync(outputFilePath, fs.readFileSync(filePath));
|
|
33
|
+
return outputFolderPath;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.copyFileToTmpDir = copyFileToTmpDir;
|
|
37
|
+
function fileDoesNotExistOrIsDirectory(path) {
|
|
38
|
+
try {
|
|
39
|
+
return isDirectory(path);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.fileDoesNotExistOrIsDirectory = fileDoesNotExistOrIsDirectory;
|
|
46
|
+
function normalizePath(filePath) {
|
|
47
|
+
//replace all backslashes coming from cli running on windows machines by slashes
|
|
48
|
+
return filePath.replace(/\\/g, "/");
|
|
49
|
+
}
|
|
50
|
+
exports.normalizePath = normalizePath;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation.
|
|
3
|
+
// Licensed under the MIT License.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CustomResponseHttpRequester = exports.HttpRequester = exports.serverUrl = exports.latestPackage = exports.validDeploymentKey = void 0;
|
|
6
|
+
const querystring = require("querystring");
|
|
7
|
+
exports.validDeploymentKey = "asdfasdfawerqw";
|
|
8
|
+
exports.latestPackage = {
|
|
9
|
+
downloadURL: "http://www.windowsazure.com/blobs/awperoiuqpweru",
|
|
10
|
+
description: "Angry flappy birds",
|
|
11
|
+
appVersion: "1.5.0",
|
|
12
|
+
label: "2.4.0",
|
|
13
|
+
isMandatory: false,
|
|
14
|
+
isAvailable: true,
|
|
15
|
+
updateAppVersion: false,
|
|
16
|
+
packageHash: "hash240",
|
|
17
|
+
packageSize: 1024,
|
|
18
|
+
};
|
|
19
|
+
exports.serverUrl = "http://myurl.com";
|
|
20
|
+
var reportStatusDeployUrl = exports.serverUrl + "/reportStatus/deploy";
|
|
21
|
+
var reportStatusDownloadUrl = exports.serverUrl + "/reportStatus/download";
|
|
22
|
+
var updateCheckUrl = exports.serverUrl + "/updateCheck?";
|
|
23
|
+
class HttpRequester {
|
|
24
|
+
request(verb, url, requestBodyOrCallback, callback) {
|
|
25
|
+
if (!callback && typeof requestBodyOrCallback === "function") {
|
|
26
|
+
callback = requestBodyOrCallback;
|
|
27
|
+
}
|
|
28
|
+
if (verb === 0 /* acquisitionSdk.Http.Verb.GET */ && url.indexOf(updateCheckUrl) === 0) {
|
|
29
|
+
var params = querystring.parse(url.substring(updateCheckUrl.length));
|
|
30
|
+
Server.onUpdateCheck(params, callback);
|
|
31
|
+
}
|
|
32
|
+
else if (verb === 2 /* acquisitionSdk.Http.Verb.POST */ && url === reportStatusDeployUrl) {
|
|
33
|
+
Server.onReportStatus(callback);
|
|
34
|
+
}
|
|
35
|
+
else if (verb === 2 /* acquisitionSdk.Http.Verb.POST */ && url === reportStatusDownloadUrl) {
|
|
36
|
+
Server.onReportStatus(callback);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
throw new Error("Unexpected call");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.HttpRequester = HttpRequester;
|
|
44
|
+
class CustomResponseHttpRequester {
|
|
45
|
+
response;
|
|
46
|
+
constructor(response) {
|
|
47
|
+
this.response = response;
|
|
48
|
+
}
|
|
49
|
+
request(verb, url, requestBodyOrCallback, callback) {
|
|
50
|
+
if (typeof requestBodyOrCallback !== "function") {
|
|
51
|
+
throw new Error("Unexpected request body");
|
|
52
|
+
}
|
|
53
|
+
callback = requestBodyOrCallback;
|
|
54
|
+
callback(null, this.response);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.CustomResponseHttpRequester = CustomResponseHttpRequester;
|
|
58
|
+
class Server {
|
|
59
|
+
static onAcquire(params, callback) {
|
|
60
|
+
if (params.deploymentKey !== exports.validDeploymentKey) {
|
|
61
|
+
callback(/*error=*/ null, {
|
|
62
|
+
statusCode: 200,
|
|
63
|
+
body: JSON.stringify({ updateInfo: { isAvailable: false } }),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
callback(/*error=*/ null, {
|
|
68
|
+
statusCode: 200,
|
|
69
|
+
body: JSON.stringify({ updateInfo: exports.latestPackage }),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
static onUpdateCheck(params, callback) {
|
|
74
|
+
var updateRequest = {
|
|
75
|
+
deploymentKey: params.deploymentKey,
|
|
76
|
+
appVersion: params.appVersion,
|
|
77
|
+
packageHash: params.packageHash,
|
|
78
|
+
isCompanion: !!params.isCompanion,
|
|
79
|
+
label: params.label,
|
|
80
|
+
};
|
|
81
|
+
if (!updateRequest.deploymentKey || !updateRequest.appVersion) {
|
|
82
|
+
callback(/*error=*/ null, { statusCode: 400 });
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
var updateInfo = { isAvailable: false };
|
|
86
|
+
if (updateRequest.deploymentKey === exports.validDeploymentKey) {
|
|
87
|
+
if (updateRequest.isCompanion || updateRequest.appVersion === exports.latestPackage.appVersion) {
|
|
88
|
+
if (updateRequest.packageHash !== exports.latestPackage.packageHash) {
|
|
89
|
+
updateInfo = exports.latestPackage;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (updateRequest.appVersion < exports.latestPackage.appVersion) {
|
|
93
|
+
updateInfo = {
|
|
94
|
+
updateAppVersion: true,
|
|
95
|
+
appVersion: exports.latestPackage.appVersion,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
callback(/*error=*/ null, {
|
|
100
|
+
statusCode: 200,
|
|
101
|
+
body: JSON.stringify({ updateInfo: updateInfo }),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
static onReportStatus(callback) {
|
|
106
|
+
callback(/*error*/ null, /*response*/ { statusCode: 200 });
|
|
107
|
+
}
|
|
108
|
+
}
|