@sevenvip666/rop 0.0.8 → 0.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/dist/bin/index.mjs +1318 -0
- package/dist/cjs/index.js +523 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.js +370 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/types/flutter/index.d.ts +6 -0
- package/dist/types/ionic/index.d.ts +6 -0
- package/dist/types/types.d.ts +69 -6
- package/dist/types/{upload.d.ts → uploadApi.d.ts} +1 -2
- package/dist/types/utils.d.ts +14 -134
- package/package.json +7 -12
- package/dist/bin/rop.mjs +0 -767
- package/dist/cjs/upload.js +0 -223
- package/dist/cjs/upload.js.map +0 -1
- package/dist/esm/upload.js +0 -166
- package/dist/esm/upload.js.map +0 -1
|
@@ -0,0 +1,1318 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import fs, { readFileSync, existsSync } from 'fs';
|
|
4
|
+
import fetch$1 from 'node-fetch';
|
|
5
|
+
import FormData from 'form-data';
|
|
6
|
+
import cliProgress from 'cli-progress';
|
|
7
|
+
import colors from 'ansi-colors';
|
|
8
|
+
import path$1, { resolve, join, sep, normalize } from 'path';
|
|
9
|
+
import { exec } from 'child_process';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import fs$1 from 'node:fs';
|
|
12
|
+
import { parse } from '@iarna/toml';
|
|
13
|
+
import { globbySync } from 'globby';
|
|
14
|
+
import JSON5 from 'json5';
|
|
15
|
+
import yaml from 'js-yaml';
|
|
16
|
+
import { confirm, select, input, password } from '@inquirer/prompts';
|
|
17
|
+
import * as os from 'node:os';
|
|
18
|
+
|
|
19
|
+
/******************************************************************************
|
|
20
|
+
Copyright (c) Microsoft Corporation.
|
|
21
|
+
|
|
22
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
23
|
+
purpose with or without fee is hereby granted.
|
|
24
|
+
|
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
26
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
27
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
28
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
29
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
30
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
31
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
32
|
+
***************************************************************************** */
|
|
33
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var __assign = function() {
|
|
37
|
+
__assign = Object.assign || function __assign(t) {
|
|
38
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
39
|
+
s = arguments[i];
|
|
40
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
41
|
+
}
|
|
42
|
+
return t;
|
|
43
|
+
};
|
|
44
|
+
return __assign.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function __rest(s, e) {
|
|
48
|
+
var t = {};
|
|
49
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
50
|
+
t[p] = s[p];
|
|
51
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
52
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
53
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
54
|
+
t[p[i]] = s[p[i]];
|
|
55
|
+
}
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
60
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
61
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
62
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
63
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
64
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
65
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function __generator(thisArg, body) {
|
|
70
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
71
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
72
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
73
|
+
function step(op) {
|
|
74
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
75
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
76
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
77
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
78
|
+
switch (op[0]) {
|
|
79
|
+
case 0: case 1: t = op; break;
|
|
80
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
81
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
82
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
83
|
+
default:
|
|
84
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
85
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
86
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
87
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
88
|
+
if (t[2]) _.ops.pop();
|
|
89
|
+
_.trys.pop(); continue;
|
|
90
|
+
}
|
|
91
|
+
op = body.call(thisArg, _);
|
|
92
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
93
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
98
|
+
var e = new Error(message);
|
|
99
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
var frameworkList = ['tauri', 'ionic', 'flutter'];
|
|
103
|
+
var Framework;
|
|
104
|
+
(function (Framework) {
|
|
105
|
+
Framework["TAURI"] = "tauri";
|
|
106
|
+
Framework["IONIC"] = "ionic";
|
|
107
|
+
Framework["FLUTTER"] = "flutter";
|
|
108
|
+
})(Framework || (Framework = {}));
|
|
109
|
+
|
|
110
|
+
function getWorkspaceDir(dir) {
|
|
111
|
+
var _a;
|
|
112
|
+
var rootPath = dir;
|
|
113
|
+
while (dir.length && dir[dir.length - 1] !== sep) {
|
|
114
|
+
var manifestPath = join(dir, 'Cargo.toml');
|
|
115
|
+
if (existsSync(manifestPath)) {
|
|
116
|
+
var toml = parse(readFileSync(manifestPath).toString());
|
|
117
|
+
if ((_a = toml.workspace) === null || _a === void 0 ? void 0 : _a.members) {
|
|
118
|
+
var ignore = ['**/target', '**/node_modules'];
|
|
119
|
+
if (toml.workspace.exclude)
|
|
120
|
+
ignore.push.apply(ignore, toml.workspace.exclude);
|
|
121
|
+
var memberPaths = globbySync(toml.workspace.members, {
|
|
122
|
+
cwd: dir,
|
|
123
|
+
ignore: ignore,
|
|
124
|
+
expandDirectories: false,
|
|
125
|
+
onlyFiles: false,
|
|
126
|
+
});
|
|
127
|
+
if (memberPaths.some(function (m) { return resolve(dir, m) === rootPath; })) {
|
|
128
|
+
return dir;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
dir = normalize(join(dir, '..'));
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
function getTauriDir(root) {
|
|
137
|
+
var tauriConfPaths = globbySync(['**/tauri.conf.json', '**/tauri.conf.json5', '**/Tauri.toml'], {
|
|
138
|
+
gitignore: true,
|
|
139
|
+
cwd: root,
|
|
140
|
+
// Forcefully ignore target and node_modules dirs
|
|
141
|
+
ignore: ['**/target', '**/node_modules'],
|
|
142
|
+
});
|
|
143
|
+
if (tauriConfPaths.length === 0) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return resolve(root, tauriConfPaths[0], '..');
|
|
147
|
+
}
|
|
148
|
+
function getCargoManifest(dir) {
|
|
149
|
+
var _a, _b, _c, _d;
|
|
150
|
+
var manifestPath = join(dir, 'Cargo.toml');
|
|
151
|
+
var cargoManifest = parse(readFileSync(manifestPath).toString());
|
|
152
|
+
var name = cargoManifest.package.name;
|
|
153
|
+
var version = cargoManifest.package.version;
|
|
154
|
+
// if the version or name is an object, it means it is a workspace package and we need to traverse up
|
|
155
|
+
if (typeof cargoManifest.package.version == 'object' || typeof cargoManifest.package.name == 'object') {
|
|
156
|
+
var workspaceDir = getWorkspaceDir(dir);
|
|
157
|
+
if (!workspaceDir) {
|
|
158
|
+
throw new Error('Could not find workspace directory, but version and/or name specifies to use workspace package');
|
|
159
|
+
}
|
|
160
|
+
var manifestPath_1 = join(workspaceDir, 'Cargo.toml');
|
|
161
|
+
var workspaceManifest = parse(readFileSync(manifestPath_1).toString());
|
|
162
|
+
if (typeof name === 'object' && ((_b = (_a = workspaceManifest === null || workspaceManifest === void 0 ? void 0 : workspaceManifest.workspace) === null || _a === void 0 ? void 0 : _a.package) === null || _b === void 0 ? void 0 : _b.name) !== undefined) {
|
|
163
|
+
name = workspaceManifest.workspace.package.name;
|
|
164
|
+
}
|
|
165
|
+
if (typeof version === 'object' && ((_d = (_c = workspaceManifest === null || workspaceManifest === void 0 ? void 0 : workspaceManifest.workspace) === null || _c === void 0 ? void 0 : _c.package) === null || _d === void 0 ? void 0 : _d.version) !== undefined) {
|
|
166
|
+
version = workspaceManifest.workspace.package.version;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return __assign(__assign({}, cargoManifest), { package: __assign(__assign({}, cargoManifest.package), { name: name, version: version }) });
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function _tryParseJsonConfig(contents) {
|
|
173
|
+
try {
|
|
174
|
+
var config = JSON.parse(contents);
|
|
175
|
+
return config;
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
var msg = e.message;
|
|
180
|
+
console.error("Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: \"".concat(msg, "\""));
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function _tryParseJson5Config(contents) {
|
|
185
|
+
try {
|
|
186
|
+
var config = JSON5.parse(contents);
|
|
187
|
+
return config;
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
var msg = e.message;
|
|
192
|
+
console.error("Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: \"".concat(msg, "\""));
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function _tryParseTomlConfig(contents) {
|
|
197
|
+
try {
|
|
198
|
+
var config = parse(contents);
|
|
199
|
+
return config;
|
|
200
|
+
}
|
|
201
|
+
catch (e) {
|
|
202
|
+
// @ts-ignore
|
|
203
|
+
var msg = e.message;
|
|
204
|
+
console.error("Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: \"".concat(msg, "\""));
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
var TauriConfig = /** @class */ (function () {
|
|
209
|
+
function TauriConfig(identifier) {
|
|
210
|
+
this.identifier = identifier;
|
|
211
|
+
}
|
|
212
|
+
TauriConfig.fromBaseConfig = function (tauriDir) {
|
|
213
|
+
console.log(tauriDir);
|
|
214
|
+
if (existsSync(join(tauriDir, 'tauri.conf.json'))) {
|
|
215
|
+
var contents = readFileSync(join(tauriDir, 'tauri.conf.json')).toString();
|
|
216
|
+
var config = _tryParseJsonConfig(contents);
|
|
217
|
+
if (config) {
|
|
218
|
+
if ('identifier' in config) {
|
|
219
|
+
return this.fromV2Base(config);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
return this.fromV1Base(config);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
console.error("Found tauri.conf.json file but couldn't parse it as JSON.");
|
|
226
|
+
}
|
|
227
|
+
if (existsSync(join(tauriDir, 'tauri.conf.json5'))) {
|
|
228
|
+
var contents = readFileSync(join(tauriDir, 'tauri.conf.json5')).toString();
|
|
229
|
+
var config = _tryParseJson5Config(contents);
|
|
230
|
+
if (config) {
|
|
231
|
+
if ('identifier' in config) {
|
|
232
|
+
return this.fromV2Base(config);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
return this.fromV1Base(config);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
console.error("Found tauri.conf.json5 file but couldn't parse it as JSON5.");
|
|
239
|
+
}
|
|
240
|
+
if (existsSync(join(tauriDir, 'Tauri.toml'))) {
|
|
241
|
+
var contents = readFileSync(join(tauriDir, 'Tauri.toml')).toString();
|
|
242
|
+
var config = _tryParseTomlConfig(contents);
|
|
243
|
+
if (config) {
|
|
244
|
+
if ('identifier' in config) {
|
|
245
|
+
return this.fromV2Base(config);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
return this.fromV1Base(config);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
console.error("Found Tauri.toml file but couldn't parse it as TOML.");
|
|
252
|
+
}
|
|
253
|
+
throw new Error("Couldn't locate or parse tauri config.");
|
|
254
|
+
};
|
|
255
|
+
TauriConfig.fromV1Base = function (config) {
|
|
256
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
257
|
+
if (!((_b = (_a = config.tauri) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.identifier)) {
|
|
258
|
+
throw Error('base config has no bundle identifier.');
|
|
259
|
+
}
|
|
260
|
+
var c = new TauriConfig((_d = (_c = config.tauri) === null || _c === void 0 ? void 0 : _c.bundle) === null || _d === void 0 ? void 0 : _d.identifier);
|
|
261
|
+
c.productName = (_e = config.package) === null || _e === void 0 ? void 0 : _e.productName;
|
|
262
|
+
c.version = (_f = config.package) === null || _f === void 0 ? void 0 : _f.version;
|
|
263
|
+
c.frontendDist = (_g = config.build) === null || _g === void 0 ? void 0 : _g.distDir;
|
|
264
|
+
c.beforeBuildCommand = (_h = config.build) === null || _h === void 0 ? void 0 : _h.beforeBuildCommand;
|
|
265
|
+
c.rpmRelease = (_j = config.tauri.bundle.rpm) === null || _j === void 0 ? void 0 : _j.release;
|
|
266
|
+
c.wixLanguage = (_l = (_k = config.tauri.bundle.windows) === null || _k === void 0 ? void 0 : _k.wix) === null || _l === void 0 ? void 0 : _l.language;
|
|
267
|
+
return c;
|
|
268
|
+
};
|
|
269
|
+
TauriConfig.fromV2Base = function (config) {
|
|
270
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
271
|
+
if (!config.identifier) {
|
|
272
|
+
throw Error('base config has no bundle identifier.');
|
|
273
|
+
}
|
|
274
|
+
var c = new TauriConfig(config.identifier);
|
|
275
|
+
c.productName = config.productName;
|
|
276
|
+
c.version = config.version;
|
|
277
|
+
c.frontendDist = (_a = config.build) === null || _a === void 0 ? void 0 : _a.frontendDist;
|
|
278
|
+
c.beforeBuildCommand = (_b = config.build) === null || _b === void 0 ? void 0 : _b.beforeBuildCommand;
|
|
279
|
+
c.rpmRelease = (_e = (_d = (_c = config.bundle) === null || _c === void 0 ? void 0 : _c.linux) === null || _d === void 0 ? void 0 : _d.rpm) === null || _e === void 0 ? void 0 : _e.release;
|
|
280
|
+
c.wixLanguage = (_h = (_g = (_f = config.bundle) === null || _f === void 0 ? void 0 : _f.windows) === null || _g === void 0 ? void 0 : _g.wix) === null || _h === void 0 ? void 0 : _h.language;
|
|
281
|
+
return c;
|
|
282
|
+
};
|
|
283
|
+
return TauriConfig;
|
|
284
|
+
}());
|
|
285
|
+
|
|
286
|
+
var getTauriEnv = function (projectPath) {
|
|
287
|
+
var _a;
|
|
288
|
+
var tauriDir = getTauriDir(projectPath !== null && projectPath !== void 0 ? projectPath : '.');
|
|
289
|
+
if (tauriDir !== null) {
|
|
290
|
+
var name_1;
|
|
291
|
+
var version = void 0;
|
|
292
|
+
var wixLanguage = 'en-US';
|
|
293
|
+
var rpmRelease = '1';
|
|
294
|
+
var config = TauriConfig.fromBaseConfig(tauriDir);
|
|
295
|
+
name_1 = config === null || config === void 0 ? void 0 : config.productName;
|
|
296
|
+
if ((_a = config.version) === null || _a === void 0 ? void 0 : _a.endsWith('.json')) {
|
|
297
|
+
var packageJsonPath = join(tauriDir, config === null || config === void 0 ? void 0 : config.version);
|
|
298
|
+
var contents = readFileSync(packageJsonPath).toString();
|
|
299
|
+
version = JSON.parse(contents).version;
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
version = config === null || config === void 0 ? void 0 : config.version;
|
|
303
|
+
}
|
|
304
|
+
if (!(name_1 && version)) {
|
|
305
|
+
var cargoManifest = getCargoManifest(tauriDir);
|
|
306
|
+
name_1 = name_1 !== null && name_1 !== void 0 ? name_1 : cargoManifest.package.name;
|
|
307
|
+
version = version !== null && version !== void 0 ? version : cargoManifest.package.version;
|
|
308
|
+
}
|
|
309
|
+
if (!(name_1 && version)) {
|
|
310
|
+
console.error('Could not determine package name and version.');
|
|
311
|
+
process.exit(1);
|
|
312
|
+
}
|
|
313
|
+
var wixAppVersion = version.replace(/[-+]/g, '.');
|
|
314
|
+
if (config.wixLanguage) {
|
|
315
|
+
wixLanguage = config.wixLanguage;
|
|
316
|
+
}
|
|
317
|
+
if (config.rpmRelease) {
|
|
318
|
+
rpmRelease = config.rpmRelease;
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
basePath: tauriDir + '/target',
|
|
322
|
+
appName: name_1,
|
|
323
|
+
version: version,
|
|
324
|
+
wixLanguage: wixLanguage,
|
|
325
|
+
wixAppVersion: wixAppVersion,
|
|
326
|
+
rpmRelease: rpmRelease,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
// This should not actually happen.
|
|
331
|
+
throw Error("Couldn't detect Tauri dir");
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
var tauri = {
|
|
336
|
+
macos: [
|
|
337
|
+
{
|
|
338
|
+
arch: "x64",
|
|
339
|
+
artifacts: {
|
|
340
|
+
target: {
|
|
341
|
+
path: "${basePath}/x86_64-apple-darwin/release/bundle/dmg/${appName}_${version}_${arch}.dmg"
|
|
342
|
+
},
|
|
343
|
+
update: {
|
|
344
|
+
path: "${basePath}/x86_64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
|
|
345
|
+
name: "${appName}_${version}_${arch}.app.tar.gz"
|
|
346
|
+
},
|
|
347
|
+
sig: {
|
|
348
|
+
path: "${basePath}/x86_64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
arch: "arm64",
|
|
354
|
+
artifacts: {
|
|
355
|
+
target: {
|
|
356
|
+
path: "${basePath}/aarch64-apple-darwin/release/bundle/dmg/${appName}_${version}_aarch64.dmg",
|
|
357
|
+
name: "${appName}_${version}_${arch}.dmg"
|
|
358
|
+
},
|
|
359
|
+
update: {
|
|
360
|
+
path: "${basePath}/aarch64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
|
|
361
|
+
name: "${appName}_${version}_${arch}.app.tar.gz"
|
|
362
|
+
},
|
|
363
|
+
sig: {
|
|
364
|
+
path: "${basePath}/aarch64-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
arch: "universal",
|
|
370
|
+
artifacts: {
|
|
371
|
+
target: {
|
|
372
|
+
path: "${basePath}/universal-apple-darwin/release/bundle/dmg/${appName}_${version}_${arch}.dmg"
|
|
373
|
+
},
|
|
374
|
+
update: {
|
|
375
|
+
path: "${basePath}/universal-apple-darwin/release/bundle/macos/${appName}.app.tar.gz",
|
|
376
|
+
name: "${appName}_${version}_${arch}.app.tar.gz"
|
|
377
|
+
},
|
|
378
|
+
sig: {
|
|
379
|
+
path: "${basePath}/universal-apple-darwin/release/bundle/macos/${appName}.app.tar.gz.sig"
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
],
|
|
384
|
+
windows: [
|
|
385
|
+
{
|
|
386
|
+
arch: "x64",
|
|
387
|
+
installerType: "nsis",
|
|
388
|
+
artifacts: {
|
|
389
|
+
target: {
|
|
390
|
+
path: "${basePath}/release/bundle/nsis/${appName}_${version}_${arch}-setup.exe"
|
|
391
|
+
},
|
|
392
|
+
update: {
|
|
393
|
+
path: "${basePath}/release/bundle/nsis/${appName}_${version}_${arch}-setup.nsis.zip",
|
|
394
|
+
name: "${appName}_${version}_${arch}.msi"
|
|
395
|
+
},
|
|
396
|
+
sig: {
|
|
397
|
+
path: "${basePath}/release/bundle/nsis/${appName}_${version}_${arch}-setup.nsis.zip.sig"
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
};
|
|
403
|
+
var flutter = {
|
|
404
|
+
ios: [
|
|
405
|
+
{
|
|
406
|
+
arch: "universal",
|
|
407
|
+
artifacts: {
|
|
408
|
+
target: {
|
|
409
|
+
path: "build/ios/ipa/${appName}.ipa",
|
|
410
|
+
name: "${appName}_${version}.ipa"
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
],
|
|
415
|
+
android: [
|
|
416
|
+
{
|
|
417
|
+
arch: "universal",
|
|
418
|
+
artifacts: {
|
|
419
|
+
target: {
|
|
420
|
+
path: "build/app/outputs/flutter-apk/app-release.apk",
|
|
421
|
+
name: "${appName}_${version}.apk"
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
],
|
|
426
|
+
macos: [
|
|
427
|
+
{
|
|
428
|
+
arch: "universal",
|
|
429
|
+
artifacts: {
|
|
430
|
+
target: {
|
|
431
|
+
path: "build/${appName}.dmg",
|
|
432
|
+
name: "${appName}_${version}.dmg"
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
]
|
|
437
|
+
};
|
|
438
|
+
var ionic = {
|
|
439
|
+
};
|
|
440
|
+
var platformDefaultConfigMap = {
|
|
441
|
+
tauri: tauri,
|
|
442
|
+
flutter: flutter,
|
|
443
|
+
ionic: ionic
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
var getFlutterEnv = function (projectPath) {
|
|
447
|
+
var dir = getDir$1(projectPath !== null && projectPath !== void 0 ? projectPath : '.');
|
|
448
|
+
if (dir !== null) {
|
|
449
|
+
if (existsSync(join(dir, 'pubspec.yaml'))) {
|
|
450
|
+
var doc = yaml.load(fs.readFileSync(join(dir, 'pubspec.yaml'), 'utf8'));
|
|
451
|
+
return {
|
|
452
|
+
basePath: dir + '/build',
|
|
453
|
+
appName: doc.name,
|
|
454
|
+
version: doc.version.split('+')[0],
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
throw Error("Couldn't detect Flutter pubspec.yaml");
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
// This should not actually happen.
|
|
463
|
+
throw Error("Couldn't detect Flutter dir");
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
function getDir$1(root) {
|
|
467
|
+
var confPaths = globbySync(['**/pubspec.yaml'], {
|
|
468
|
+
gitignore: true,
|
|
469
|
+
cwd: root,
|
|
470
|
+
// Forcefully ignore target and node_modules dirs
|
|
471
|
+
ignore: ['**/build', '**/ios', '**/android', '**/windows', '**/macos', '**/linux'],
|
|
472
|
+
});
|
|
473
|
+
if (confPaths.length === 0) {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
return resolve(root, confPaths[0], '..');
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
var getIonicEnv = function (projectPath) {
|
|
480
|
+
var dir = getDir(projectPath !== null && projectPath !== void 0 ? projectPath : '.');
|
|
481
|
+
if (dir !== null) {
|
|
482
|
+
if (existsSync(join(dir, 'package.json'))) {
|
|
483
|
+
var config = readFileSync(join(dir, 'capacitor.config.ts'), 'utf8').toString();
|
|
484
|
+
var json = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8').toString());
|
|
485
|
+
// 使用正则表达式来找到 appName 的值
|
|
486
|
+
var appNameRegex = /appName:\s*['"]([^'"]*)['"]/;
|
|
487
|
+
var match = appNameRegex.exec(config);
|
|
488
|
+
return {
|
|
489
|
+
basePath: dir,
|
|
490
|
+
appName: match === null || match === void 0 ? void 0 : match[1],
|
|
491
|
+
version: json.version,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
throw Error("Couldn't detect Flutter pubspec.yaml");
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
// This should not actually happen.
|
|
500
|
+
throw Error("Couldn't detect Flutter dir");
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
function getDir(root) {
|
|
504
|
+
var confPaths = globbySync(['**/package.json', '**/capacitor.config.ts'], {
|
|
505
|
+
gitignore: true,
|
|
506
|
+
cwd: root,
|
|
507
|
+
// Forcefully ignore target and node_modules dirs
|
|
508
|
+
ignore: ['**/build', '**/ios', '**/android', '**/windows', '**/macos', '**/linux'],
|
|
509
|
+
});
|
|
510
|
+
if (confPaths.length === 0) {
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
return resolve(root, confPaths[0], '..');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
var getBranch = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
517
|
+
return __generator(this, function (_a) {
|
|
518
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
519
|
+
return exec('git rev-parse --abbrev-ref HEAD', function (err, stdout, stderr) {
|
|
520
|
+
if (err) {
|
|
521
|
+
console.log("getBranch Error: ".concat(err));
|
|
522
|
+
}
|
|
523
|
+
else if (stdout) {
|
|
524
|
+
resolve(stdout.trim());
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
resolve('none');
|
|
528
|
+
});
|
|
529
|
+
})];
|
|
530
|
+
});
|
|
531
|
+
}); };
|
|
532
|
+
// 读取 JSON 文件并替换模版变量
|
|
533
|
+
function loadJsonWithEnv(_a) {
|
|
534
|
+
var _b, _c, _d, _e, _f;
|
|
535
|
+
var platform = _a.platform, arch = _a.arch;
|
|
536
|
+
var configFilePath = path.join('.', 'rop.json');
|
|
537
|
+
var configData = fs$1.readFileSync(configFilePath, 'utf8');
|
|
538
|
+
var inputConfig = JSON.parse(configData);
|
|
539
|
+
var _arch = arch !== null && arch !== void 0 ? arch : 'universal';
|
|
540
|
+
if (arch == 'x86_64') {
|
|
541
|
+
_arch = 'x64';
|
|
542
|
+
}
|
|
543
|
+
else if (arch == 'i386' || arch == 'i686') {
|
|
544
|
+
_arch = 'x86';
|
|
545
|
+
}
|
|
546
|
+
else if (arch == 'aarch64') {
|
|
547
|
+
_arch = 'arm64';
|
|
548
|
+
}
|
|
549
|
+
var env = {
|
|
550
|
+
arch: _arch,
|
|
551
|
+
};
|
|
552
|
+
var config;
|
|
553
|
+
if (!inputConfig.platforms && ((_b = inputConfig.framework) === null || _b === void 0 ? void 0 : _b.name) && frameworkList.includes((_c = inputConfig.framework) === null || _c === void 0 ? void 0 : _c.name)) {
|
|
554
|
+
var framework = inputConfig.framework.name;
|
|
555
|
+
var defaultPlatformConfig = platformDefaultConfigMap[framework];
|
|
556
|
+
var _config = __assign(__assign({}, inputConfig), { platforms: defaultPlatformConfig });
|
|
557
|
+
config = _config;
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
config = inputConfig;
|
|
561
|
+
}
|
|
562
|
+
if (!config.platforms || Object.keys(config.platforms).length == 0) {
|
|
563
|
+
throw new Error('platforms is not null');
|
|
564
|
+
}
|
|
565
|
+
var _autoEnv = getAutoEnvByFramework((_d = config === null || config === void 0 ? void 0 : config.framework) === null || _d === void 0 ? void 0 : _d.name, config.projectPath);
|
|
566
|
+
env = __assign(__assign(__assign({}, env), (_autoEnv !== null && _autoEnv !== void 0 ? _autoEnv : {})), ((_f = (_e = config.framework) === null || _e === void 0 ? void 0 : _e.env) !== null && _f !== void 0 ? _f : {}));
|
|
567
|
+
// 确保配置文件中存在 host 属性
|
|
568
|
+
if (!env.version) {
|
|
569
|
+
throw new Error('Missing "version" property in the configuration file.');
|
|
570
|
+
}
|
|
571
|
+
// 递归函数来替换对象中的字符串值
|
|
572
|
+
function replaceEnvInObject(obj) {
|
|
573
|
+
Object.keys(obj).forEach(function (key) {
|
|
574
|
+
if (typeof obj[key] === 'string') {
|
|
575
|
+
// 使用正则表达式替换模版变量(这里假设模版变量是 ${VAR} 格式的)
|
|
576
|
+
// @ts-ignore
|
|
577
|
+
obj[key] = obj[key].replace(/\$\{(\w+)\}/g, function (_, envVar) { return env[envVar] || ''; });
|
|
578
|
+
}
|
|
579
|
+
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
580
|
+
replaceEnvInObject(obj[key]); // 递归处理嵌套对象
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
replaceEnvInObject(config);
|
|
585
|
+
var targetInfos = getTargetInfo(config.platforms, platform, _arch);
|
|
586
|
+
console.log('find target file:');
|
|
587
|
+
console.log(targetInfos);
|
|
588
|
+
return { config: config, targetInfos: targetInfos, version: env.version, arch: _arch };
|
|
589
|
+
}
|
|
590
|
+
var loadConfigJSON = function () {
|
|
591
|
+
var configFilePath = path.join('.rop', 'config.json');
|
|
592
|
+
if (!fs$1.existsSync(configFilePath)) {
|
|
593
|
+
return {
|
|
594
|
+
projectId: undefined,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
var configDataStr = fs$1.readFileSync(configFilePath, 'utf8');
|
|
598
|
+
var configData = JSON.parse(configDataStr);
|
|
599
|
+
return {
|
|
600
|
+
projectId: configData.projectId,
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
var getAutoEnvByFramework = function (framework, projectPath) {
|
|
604
|
+
if (!framework) {
|
|
605
|
+
return undefined;
|
|
606
|
+
}
|
|
607
|
+
switch (framework.toLowerCase()) {
|
|
608
|
+
case Framework.TAURI:
|
|
609
|
+
return getTauriEnv(projectPath);
|
|
610
|
+
case Framework.FLUTTER:
|
|
611
|
+
return getFlutterEnv(projectPath);
|
|
612
|
+
case Framework.IONIC:
|
|
613
|
+
return getIonicEnv(projectPath);
|
|
614
|
+
default:
|
|
615
|
+
return undefined;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
var getTargetInfo = function (platforms, platform, arch) {
|
|
619
|
+
console.log(platforms);
|
|
620
|
+
var list = platforms[platform];
|
|
621
|
+
console.log(list);
|
|
622
|
+
if (list && list.length > 0) {
|
|
623
|
+
var targetList = list.filter(function (item) { return item.arch == arch; });
|
|
624
|
+
if (targetList.length > 0) {
|
|
625
|
+
return targetList;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
throw new Error('Not find artifacts file');
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
var RopUploadApi = /** @class */ (function () {
|
|
632
|
+
function RopUploadApi(_a) {
|
|
633
|
+
var baseDomain = _a.baseDomain;
|
|
634
|
+
var _this = this;
|
|
635
|
+
this.checkParams = function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
636
|
+
var branch, _a;
|
|
637
|
+
var _b;
|
|
638
|
+
return __generator(this, function (_c) {
|
|
639
|
+
switch (_c.label) {
|
|
640
|
+
case 0:
|
|
641
|
+
if (!config.accessKey) {
|
|
642
|
+
if (!config.token || !config.projectId) {
|
|
643
|
+
throw new Error('accessKey, token, projectId cannot be empty at the same time');
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (!((_b = config.branch) !== null && _b !== void 0)) return [3 /*break*/, 1];
|
|
647
|
+
_a = _b;
|
|
648
|
+
return [3 /*break*/, 3];
|
|
649
|
+
case 1: return [4 /*yield*/, getBranch()];
|
|
650
|
+
case 2:
|
|
651
|
+
_a = (_c.sent());
|
|
652
|
+
_c.label = 3;
|
|
653
|
+
case 3:
|
|
654
|
+
branch = _a;
|
|
655
|
+
if (!branch) {
|
|
656
|
+
throw new Error('branch not null');
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
config.branch = branch;
|
|
660
|
+
}
|
|
661
|
+
if (!config.platform) {
|
|
662
|
+
throw new Error('platform not null');
|
|
663
|
+
}
|
|
664
|
+
if (!config.arch) {
|
|
665
|
+
throw new Error('arch not null');
|
|
666
|
+
}
|
|
667
|
+
if (!config.targetPath) {
|
|
668
|
+
throw new Error('target path not null');
|
|
669
|
+
}
|
|
670
|
+
if (!fs.existsSync(config.targetPath)) {
|
|
671
|
+
throw new Error("target file not found, file path: ".concat(config.targetPath));
|
|
672
|
+
}
|
|
673
|
+
if (config.updatePath && !fs.existsSync(config.updatePath)) {
|
|
674
|
+
throw new Error("update file not found\uFF0C file path: ".concat(config.updatePath));
|
|
675
|
+
}
|
|
676
|
+
if (!config.version) {
|
|
677
|
+
throw new Error('version not null');
|
|
678
|
+
}
|
|
679
|
+
return [2 /*return*/, config];
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
}); };
|
|
683
|
+
this.baseDomain = baseDomain;
|
|
684
|
+
}
|
|
685
|
+
RopUploadApi.prototype.upload = function (_config) {
|
|
686
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
687
|
+
var config, formData, fileStream, multibar, bar1, totalUploaded, updateFileStream, bar2_1, totalUpdateUploaded_1, res, body;
|
|
688
|
+
var _a, _b;
|
|
689
|
+
return __generator(this, function (_c) {
|
|
690
|
+
switch (_c.label) {
|
|
691
|
+
case 0: return [4 /*yield*/, this.checkParams(_config)];
|
|
692
|
+
case 1:
|
|
693
|
+
config = _c.sent();
|
|
694
|
+
formData = new FormData();
|
|
695
|
+
fileStream = fs.createReadStream(config.targetPath);
|
|
696
|
+
multibar = new cliProgress.MultiBar({
|
|
697
|
+
format: 'Upload Progress |' + colors.cyan('{bar}') + '| {percentage}% | {filename}',
|
|
698
|
+
barCompleteChar: '\u2588',
|
|
699
|
+
barIncompleteChar: '\u2591',
|
|
700
|
+
hideCursor: true,
|
|
701
|
+
});
|
|
702
|
+
bar1 = multibar.create(fs.statSync(config.targetPath).size, 0);
|
|
703
|
+
totalUploaded = 0;
|
|
704
|
+
fileStream.on('data', function (chunk) {
|
|
705
|
+
totalUploaded += chunk.length;
|
|
706
|
+
bar1.update(totalUploaded, { filename: path$1.basename(config.targetPath) });
|
|
707
|
+
});
|
|
708
|
+
formData.append('targetFile', fileStream, {
|
|
709
|
+
filename: (_a = config.targetName) !== null && _a !== void 0 ? _a : path$1.basename(config.targetPath),
|
|
710
|
+
});
|
|
711
|
+
if (config.updatePath) {
|
|
712
|
+
bar2_1 = multibar.create(fs.statSync(config.updatePath).size, 0);
|
|
713
|
+
updateFileStream = fs.createReadStream(config.updatePath);
|
|
714
|
+
totalUpdateUploaded_1 = 0;
|
|
715
|
+
updateFileStream.on('data', function (chunk) {
|
|
716
|
+
totalUpdateUploaded_1 += chunk.length;
|
|
717
|
+
bar2_1.update(totalUpdateUploaded_1, { filename: path$1.basename(config.updatePath) });
|
|
718
|
+
});
|
|
719
|
+
formData.append('updateFile', updateFileStream, {
|
|
720
|
+
filename: (_b = config.updateName) !== null && _b !== void 0 ? _b : path$1.basename(config.updatePath),
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
if (config.accessKey) {
|
|
724
|
+
formData.append('accessKey', config.accessKey);
|
|
725
|
+
}
|
|
726
|
+
if (config.projectId) {
|
|
727
|
+
formData.append('projectId', config.projectId);
|
|
728
|
+
}
|
|
729
|
+
if (config.token) {
|
|
730
|
+
formData.append('token', config.token);
|
|
731
|
+
}
|
|
732
|
+
formData.append('branch', config.branch);
|
|
733
|
+
formData.append('version', config.version);
|
|
734
|
+
formData.append('platform', config.platform);
|
|
735
|
+
formData.append('arch', config.arch);
|
|
736
|
+
if (config.signature) {
|
|
737
|
+
formData.append('signature', config.signature);
|
|
738
|
+
}
|
|
739
|
+
return [4 /*yield*/, fetch$1("".concat(this.baseDomain, "/api/upload"), {
|
|
740
|
+
method: 'POST',
|
|
741
|
+
headers: formData.getHeaders(),
|
|
742
|
+
body: formData,
|
|
743
|
+
})];
|
|
744
|
+
case 2:
|
|
745
|
+
res = _c.sent();
|
|
746
|
+
return [4 /*yield*/, res.json()];
|
|
747
|
+
case 3:
|
|
748
|
+
body = _c.sent();
|
|
749
|
+
if (!res.ok) {
|
|
750
|
+
console.log(res.status, res.statusText, body);
|
|
751
|
+
}
|
|
752
|
+
multibar.stop();
|
|
753
|
+
fileStream.destroy();
|
|
754
|
+
updateFileStream === null || updateFileStream === void 0 ? void 0 : updateFileStream.destroy();
|
|
755
|
+
return [2 /*return*/, { success: res.ok, body: body }];
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
};
|
|
760
|
+
return RopUploadApi;
|
|
761
|
+
}());
|
|
762
|
+
|
|
763
|
+
var InitApi = /** @class */ (function () {
|
|
764
|
+
function InitApi() {
|
|
765
|
+
}
|
|
766
|
+
InitApi.prototype.initProjectConfigJson = function (framework) {
|
|
767
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
768
|
+
var jsonConfigPath, jsonConfigData, str;
|
|
769
|
+
return __generator(this, function (_a) {
|
|
770
|
+
switch (_a.label) {
|
|
771
|
+
case 0:
|
|
772
|
+
jsonConfigPath = path.join('.', 'rop.json');
|
|
773
|
+
if (!fs$1.existsSync(jsonConfigPath)) return [3 /*break*/, 2];
|
|
774
|
+
return [4 /*yield*/, confirm({
|
|
775
|
+
message: "".concat(colors.cyan('rop.json'), " already exists, does it need to be overwritten?"),
|
|
776
|
+
})];
|
|
777
|
+
case 1:
|
|
778
|
+
_a.sent();
|
|
779
|
+
str = fs$1.readFileSync(jsonConfigPath, 'utf8');
|
|
780
|
+
jsonConfigData = JSON.parse(str);
|
|
781
|
+
if (!jsonConfigData.framework) {
|
|
782
|
+
jsonConfigData.framework = {
|
|
783
|
+
name: framework,
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
jsonConfigData.framework.name = framework;
|
|
788
|
+
}
|
|
789
|
+
return [3 /*break*/, 3];
|
|
790
|
+
case 2:
|
|
791
|
+
jsonConfigData = {
|
|
792
|
+
framework: {
|
|
793
|
+
name: framework,
|
|
794
|
+
},
|
|
795
|
+
};
|
|
796
|
+
_a.label = 3;
|
|
797
|
+
case 3:
|
|
798
|
+
fs$1.writeFileSync(jsonConfigPath, JSON.stringify(jsonConfigData, null, 2), 'utf8');
|
|
799
|
+
return [2 /*return*/];
|
|
800
|
+
}
|
|
801
|
+
});
|
|
802
|
+
});
|
|
803
|
+
};
|
|
804
|
+
InitApi.prototype.initRopConfig = function (projectId) {
|
|
805
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
806
|
+
var ropConfigDirPath, ropConfigPath, ropConfigData;
|
|
807
|
+
return __generator(this, function (_a) {
|
|
808
|
+
ropConfigDirPath = path.join('.', '.rop');
|
|
809
|
+
if (!fs$1.existsSync(ropConfigDirPath)) {
|
|
810
|
+
fs$1.mkdirSync(ropConfigDirPath);
|
|
811
|
+
}
|
|
812
|
+
ropConfigPath = path.join(ropConfigDirPath, 'config.json');
|
|
813
|
+
ropConfigData = {};
|
|
814
|
+
if (fs$1.existsSync(ropConfigPath)) {
|
|
815
|
+
ropConfigData = JSON.parse(fs$1.readFileSync(ropConfigPath, 'utf8'));
|
|
816
|
+
}
|
|
817
|
+
ropConfigData.projectId = projectId;
|
|
818
|
+
fs$1.writeFileSync(ropConfigPath, JSON.stringify(ropConfigData, null, 2), 'utf8');
|
|
819
|
+
return [2 /*return*/];
|
|
820
|
+
});
|
|
821
|
+
});
|
|
822
|
+
};
|
|
823
|
+
InitApi.prototype.initGitignore = function () {
|
|
824
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
825
|
+
var gitignorePath, gitignoreData;
|
|
826
|
+
return __generator(this, function (_a) {
|
|
827
|
+
gitignorePath = path.join('.', '.gitignore');
|
|
828
|
+
if (fs$1.existsSync(gitignorePath)) {
|
|
829
|
+
gitignoreData = fs$1.readFileSync(gitignorePath, 'utf8');
|
|
830
|
+
if (!gitignoreData.includes('.rop')) {
|
|
831
|
+
fs$1.appendFileSync(gitignorePath, "\n.rop", 'utf8');
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
fs$1.writeFileSync(gitignorePath, ".rop", 'utf8');
|
|
836
|
+
}
|
|
837
|
+
return [2 /*return*/];
|
|
838
|
+
});
|
|
839
|
+
});
|
|
840
|
+
};
|
|
841
|
+
return InitApi;
|
|
842
|
+
}());
|
|
843
|
+
|
|
844
|
+
var defaultHost = 'http://rop.coolcat.tech:8100';
|
|
845
|
+
|
|
846
|
+
var LOGIN_API = '/api/auth/login';
|
|
847
|
+
var REFRESH_TOKEN_API = '/api/auth/refresh';
|
|
848
|
+
var CHECK_AND_REFRESH_TOKEN_API = '/api/auth/checkAndRefresh';
|
|
849
|
+
var AuthApi = /** @class */ (function () {
|
|
850
|
+
function AuthApi(_a) {
|
|
851
|
+
var baseDomain = _a.baseDomain;
|
|
852
|
+
this.baseDomain = baseDomain !== null && baseDomain !== void 0 ? baseDomain : defaultHost;
|
|
853
|
+
}
|
|
854
|
+
AuthApi.prototype.login = function (req) {
|
|
855
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
856
|
+
var res, resBody, homedir, userFilePath;
|
|
857
|
+
return __generator(this, function (_a) {
|
|
858
|
+
switch (_a.label) {
|
|
859
|
+
case 0: return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(LOGIN_API), {
|
|
860
|
+
method: 'POST',
|
|
861
|
+
headers: {
|
|
862
|
+
'Content-Type': 'application/json;charset=utf-8',
|
|
863
|
+
},
|
|
864
|
+
body: JSON.stringify(req),
|
|
865
|
+
})];
|
|
866
|
+
case 1:
|
|
867
|
+
res = _a.sent();
|
|
868
|
+
return [4 /*yield*/, res.json()];
|
|
869
|
+
case 2:
|
|
870
|
+
resBody = _a.sent();
|
|
871
|
+
if (!res.ok || !resBody.data) {
|
|
872
|
+
if (!resBody.message || res.status != 400) {
|
|
873
|
+
console.log("Login failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
|
|
874
|
+
}
|
|
875
|
+
else {
|
|
876
|
+
console.log(JSON.stringify(resBody));
|
|
877
|
+
}
|
|
878
|
+
return [2 /*return*/];
|
|
879
|
+
}
|
|
880
|
+
homedir = path.join(os.homedir(), '.rop');
|
|
881
|
+
if (!fs.existsSync(homedir)) {
|
|
882
|
+
fs.mkdirSync(homedir);
|
|
883
|
+
}
|
|
884
|
+
userFilePath = path.join(homedir, 'user');
|
|
885
|
+
fs.writeFileSync(userFilePath, JSON.stringify(resBody.data, null, 2), 'utf8');
|
|
886
|
+
return [2 /*return*/];
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
});
|
|
890
|
+
};
|
|
891
|
+
AuthApi.prototype.refreshToken = function () {
|
|
892
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
893
|
+
var homedir, userFilePath, user, res, resBody;
|
|
894
|
+
return __generator(this, function (_a) {
|
|
895
|
+
switch (_a.label) {
|
|
896
|
+
case 0:
|
|
897
|
+
homedir = path.join(os.homedir(), '.rop');
|
|
898
|
+
userFilePath = path.join(homedir, 'user');
|
|
899
|
+
if (!fs.existsSync(userFilePath)) {
|
|
900
|
+
console.log('Unauthorized. Please execute the login command');
|
|
901
|
+
return [2 /*return*/];
|
|
902
|
+
}
|
|
903
|
+
user = JSON.parse(fs.readFileSync(userFilePath, 'utf8'));
|
|
904
|
+
return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(REFRESH_TOKEN_API), {
|
|
905
|
+
method: 'POST',
|
|
906
|
+
headers: {
|
|
907
|
+
'Content-Type': 'application/json;charset=utf-8',
|
|
908
|
+
},
|
|
909
|
+
body: JSON.stringify({ token: user.auth.refreshToken }),
|
|
910
|
+
})];
|
|
911
|
+
case 1:
|
|
912
|
+
res = _a.sent();
|
|
913
|
+
return [4 /*yield*/, res.json()];
|
|
914
|
+
case 2:
|
|
915
|
+
resBody = _a.sent();
|
|
916
|
+
if (!res.ok || !resBody.data) {
|
|
917
|
+
if (!resBody.message || res.status != 400) {
|
|
918
|
+
console.log("Refresh token failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
console.log('Authorization expired please execute the login command');
|
|
922
|
+
fs.rmSync(userFilePath);
|
|
923
|
+
}
|
|
924
|
+
throw new Error('Refresh token failed');
|
|
925
|
+
}
|
|
926
|
+
user.auth = resBody.data;
|
|
927
|
+
fs.writeFileSync(userFilePath, JSON.stringify(user), 'utf8');
|
|
928
|
+
return [2 /*return*/];
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
});
|
|
932
|
+
};
|
|
933
|
+
AuthApi.prototype.getToken = function () {
|
|
934
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
935
|
+
var homedir, userFilePath;
|
|
936
|
+
return __generator(this, function (_a) {
|
|
937
|
+
homedir = path.join(os.homedir(), '.rop');
|
|
938
|
+
userFilePath = path.join(homedir, 'user');
|
|
939
|
+
if (!fs.existsSync(userFilePath)) {
|
|
940
|
+
return [2 /*return*/, undefined];
|
|
941
|
+
}
|
|
942
|
+
return [2 /*return*/, JSON.parse(fs.readFileSync(userFilePath, 'utf8'))];
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
};
|
|
946
|
+
AuthApi.prototype.checkAndRefreshToken = function () {
|
|
947
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
948
|
+
var user, res, resBody, homedir, userFilePath;
|
|
949
|
+
return __generator(this, function (_a) {
|
|
950
|
+
switch (_a.label) {
|
|
951
|
+
case 0: return [4 /*yield*/, this.getToken()];
|
|
952
|
+
case 1:
|
|
953
|
+
user = _a.sent();
|
|
954
|
+
if (!user) {
|
|
955
|
+
return [2 /*return*/, undefined];
|
|
956
|
+
}
|
|
957
|
+
return [4 /*yield*/, fetch("".concat(this.baseDomain).concat(CHECK_AND_REFRESH_TOKEN_API), {
|
|
958
|
+
method: 'POST',
|
|
959
|
+
headers: {
|
|
960
|
+
'Content-Type': 'application/json;charset=utf-8',
|
|
961
|
+
},
|
|
962
|
+
body: JSON.stringify(user.auth),
|
|
963
|
+
})];
|
|
964
|
+
case 2:
|
|
965
|
+
res = _a.sent();
|
|
966
|
+
return [4 /*yield*/, res.json()];
|
|
967
|
+
case 3:
|
|
968
|
+
resBody = _a.sent();
|
|
969
|
+
if (!res.ok || !resBody.data) {
|
|
970
|
+
return [2 /*return*/, undefined];
|
|
971
|
+
}
|
|
972
|
+
homedir = path.join(os.homedir(), '.rop');
|
|
973
|
+
userFilePath = path.join(homedir, 'user');
|
|
974
|
+
user = JSON.parse(fs.readFileSync(userFilePath, 'utf8'));
|
|
975
|
+
user.auth = resBody.data;
|
|
976
|
+
fs.writeFileSync(userFilePath, JSON.stringify(user), 'utf8');
|
|
977
|
+
return [2 /*return*/, user];
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
};
|
|
982
|
+
AuthApi.prototype.request = function (req) {
|
|
983
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
984
|
+
var user, res, resBody, _a;
|
|
985
|
+
return __generator(this, function (_b) {
|
|
986
|
+
switch (_b.label) {
|
|
987
|
+
case 0: return [4 /*yield*/, this.getToken()];
|
|
988
|
+
case 1:
|
|
989
|
+
user = _b.sent();
|
|
990
|
+
if (!user) {
|
|
991
|
+
console.log('Unauthorized. Please execute the login command');
|
|
992
|
+
return [2 /*return*/, undefined];
|
|
993
|
+
}
|
|
994
|
+
return [4 /*yield*/, req(user.auth.accessToken)];
|
|
995
|
+
case 2:
|
|
996
|
+
res = _b.sent();
|
|
997
|
+
return [4 /*yield*/, res.json()];
|
|
998
|
+
case 3:
|
|
999
|
+
resBody = _b.sent();
|
|
1000
|
+
if (!(!res.ok || !resBody.data)) return [3 /*break*/, 10];
|
|
1001
|
+
_a = res.status;
|
|
1002
|
+
switch (_a) {
|
|
1003
|
+
case 400: return [3 /*break*/, 4];
|
|
1004
|
+
case 401: return [3 /*break*/, 5];
|
|
1005
|
+
}
|
|
1006
|
+
return [3 /*break*/, 8];
|
|
1007
|
+
case 4:
|
|
1008
|
+
console.log(JSON.stringify(resBody));
|
|
1009
|
+
return [3 /*break*/, 9];
|
|
1010
|
+
case 5: return [4 /*yield*/, this.refreshToken()];
|
|
1011
|
+
case 6:
|
|
1012
|
+
_b.sent();
|
|
1013
|
+
return [4 /*yield*/, this.request(req)];
|
|
1014
|
+
case 7: return [2 /*return*/, _b.sent()];
|
|
1015
|
+
case 8:
|
|
1016
|
+
console.log("request failed: status=".concat(res.status, ", statusText=").concat(res.statusText));
|
|
1017
|
+
_b.label = 9;
|
|
1018
|
+
case 9: return [2 /*return*/, undefined];
|
|
1019
|
+
case 10: return [2 /*return*/, resBody.data];
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
});
|
|
1023
|
+
};
|
|
1024
|
+
return AuthApi;
|
|
1025
|
+
}());
|
|
1026
|
+
|
|
1027
|
+
var init = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1028
|
+
var authApi, user, needLink, projectId, framework, projectName_1, project, projectName, body_1, project, init;
|
|
1029
|
+
return __generator(this, function (_a) {
|
|
1030
|
+
switch (_a.label) {
|
|
1031
|
+
case 0:
|
|
1032
|
+
authApi = new AuthApi({ baseDomain: defaultHost });
|
|
1033
|
+
return [4 /*yield*/, authApi.checkAndRefreshToken()];
|
|
1034
|
+
case 1:
|
|
1035
|
+
user = _a.sent();
|
|
1036
|
+
if (!user) {
|
|
1037
|
+
throw new Error('Unauthorized. Please execute the login command');
|
|
1038
|
+
}
|
|
1039
|
+
return [4 /*yield*/, confirm({
|
|
1040
|
+
message: "Link to existing project?",
|
|
1041
|
+
})];
|
|
1042
|
+
case 2:
|
|
1043
|
+
needLink = _a.sent();
|
|
1044
|
+
if (!needLink) return [3 /*break*/, 7];
|
|
1045
|
+
_a.label = 3;
|
|
1046
|
+
case 3:
|
|
1047
|
+
if (!!projectName_1) return [3 /*break*/, 5];
|
|
1048
|
+
return [4 /*yield*/, input({ message: "What\u2019s the name of your existing project?" })];
|
|
1049
|
+
case 4:
|
|
1050
|
+
projectName_1 = _a.sent();
|
|
1051
|
+
return [3 /*break*/, 3];
|
|
1052
|
+
case 5: return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1053
|
+
return __generator(this, function (_a) {
|
|
1054
|
+
return [2 /*return*/, fetch("".concat(defaultHost, "/api/project/").concat(projectName_1), {
|
|
1055
|
+
method: 'GET',
|
|
1056
|
+
headers: {
|
|
1057
|
+
Authorization: "Bearer ".concat(token),
|
|
1058
|
+
},
|
|
1059
|
+
})];
|
|
1060
|
+
});
|
|
1061
|
+
}); })];
|
|
1062
|
+
case 6:
|
|
1063
|
+
project = _a.sent();
|
|
1064
|
+
if (!project) {
|
|
1065
|
+
throw new Error('project not found');
|
|
1066
|
+
}
|
|
1067
|
+
projectId = project.id;
|
|
1068
|
+
framework = project.framework;
|
|
1069
|
+
return [3 /*break*/, 13];
|
|
1070
|
+
case 7:
|
|
1071
|
+
projectName = void 0;
|
|
1072
|
+
_a.label = 8;
|
|
1073
|
+
case 8:
|
|
1074
|
+
if (!!projectName) return [3 /*break*/, 10];
|
|
1075
|
+
return [4 /*yield*/, input({ message: "What\u2019s your project\u2019s name?" })];
|
|
1076
|
+
case 9:
|
|
1077
|
+
projectName = _a.sent();
|
|
1078
|
+
return [3 /*break*/, 8];
|
|
1079
|
+
case 10: return [4 /*yield*/, select({
|
|
1080
|
+
message: "Please Select ".concat(colors.cyan('framework')),
|
|
1081
|
+
choices: [
|
|
1082
|
+
{
|
|
1083
|
+
name: 'tauri',
|
|
1084
|
+
value: 'tauri',
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
name: 'ionic',
|
|
1088
|
+
value: 'ionic',
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
name: 'flutter',
|
|
1092
|
+
value: 'flutter',
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
name: 'other',
|
|
1096
|
+
value: 'other',
|
|
1097
|
+
},
|
|
1098
|
+
],
|
|
1099
|
+
})];
|
|
1100
|
+
case 11:
|
|
1101
|
+
framework = _a.sent();
|
|
1102
|
+
body_1 = {
|
|
1103
|
+
name: projectName,
|
|
1104
|
+
framework: framework,
|
|
1105
|
+
};
|
|
1106
|
+
return [4 /*yield*/, authApi.request(function (token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1107
|
+
return __generator(this, function (_a) {
|
|
1108
|
+
return [2 /*return*/, fetch("".concat(defaultHost, "/api/project"), {
|
|
1109
|
+
method: 'POST',
|
|
1110
|
+
headers: {
|
|
1111
|
+
Accept: 'application/json',
|
|
1112
|
+
'Content-Type': 'application/json;charset=utf-8',
|
|
1113
|
+
Authorization: "Bearer ".concat(token),
|
|
1114
|
+
},
|
|
1115
|
+
body: JSON.stringify(body_1),
|
|
1116
|
+
})];
|
|
1117
|
+
});
|
|
1118
|
+
}); })];
|
|
1119
|
+
case 12:
|
|
1120
|
+
project = _a.sent();
|
|
1121
|
+
if (!project) {
|
|
1122
|
+
throw new Error('project create failed');
|
|
1123
|
+
}
|
|
1124
|
+
projectId = project.id;
|
|
1125
|
+
framework = project.framework;
|
|
1126
|
+
_a.label = 13;
|
|
1127
|
+
case 13:
|
|
1128
|
+
init = new InitApi();
|
|
1129
|
+
return [4 /*yield*/, init.initProjectConfigJson(framework)];
|
|
1130
|
+
case 14:
|
|
1131
|
+
_a.sent();
|
|
1132
|
+
return [4 /*yield*/, init.initRopConfig(projectId)];
|
|
1133
|
+
case 15:
|
|
1134
|
+
_a.sent();
|
|
1135
|
+
return [4 /*yield*/, init.initGitignore()];
|
|
1136
|
+
case 16:
|
|
1137
|
+
_a.sent();
|
|
1138
|
+
console.log('Init successful');
|
|
1139
|
+
return [2 /*return*/, projectId];
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
}); };
|
|
1143
|
+
|
|
1144
|
+
var login = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1145
|
+
var username, password$1, loginReq, auth;
|
|
1146
|
+
return __generator(this, function (_a) {
|
|
1147
|
+
switch (_a.label) {
|
|
1148
|
+
case 0:
|
|
1149
|
+
username = options.username, password$1 = options.password;
|
|
1150
|
+
_a.label = 1;
|
|
1151
|
+
case 1:
|
|
1152
|
+
if (!!username) return [3 /*break*/, 6];
|
|
1153
|
+
_a.label = 2;
|
|
1154
|
+
case 2:
|
|
1155
|
+
_a.trys.push([2, 4, , 5]);
|
|
1156
|
+
return [4 /*yield*/, input({ message: "Please enter ".concat(colors.cyan('username')) })];
|
|
1157
|
+
case 3:
|
|
1158
|
+
username = _a.sent();
|
|
1159
|
+
return [3 /*break*/, 5];
|
|
1160
|
+
case 4:
|
|
1161
|
+
_a.sent();
|
|
1162
|
+
console.log('cancel');
|
|
1163
|
+
return [2 /*return*/];
|
|
1164
|
+
case 5: return [3 /*break*/, 1];
|
|
1165
|
+
case 6:
|
|
1166
|
+
if (!!password$1) return [3 /*break*/, 11];
|
|
1167
|
+
_a.label = 7;
|
|
1168
|
+
case 7:
|
|
1169
|
+
_a.trys.push([7, 9, , 10]);
|
|
1170
|
+
return [4 /*yield*/, password({ mask: true, message: "Please enter ".concat(colors.cyan('password')) })];
|
|
1171
|
+
case 8:
|
|
1172
|
+
password$1 = _a.sent();
|
|
1173
|
+
return [3 /*break*/, 10];
|
|
1174
|
+
case 9:
|
|
1175
|
+
_a.sent();
|
|
1176
|
+
console.log('cancel');
|
|
1177
|
+
return [2 /*return*/];
|
|
1178
|
+
case 10: return [3 /*break*/, 6];
|
|
1179
|
+
case 11:
|
|
1180
|
+
loginReq = {
|
|
1181
|
+
username: username,
|
|
1182
|
+
password: password$1,
|
|
1183
|
+
};
|
|
1184
|
+
auth = new AuthApi({ baseDomain: defaultHost });
|
|
1185
|
+
return [4 /*yield*/, auth.login(loginReq)];
|
|
1186
|
+
case 12:
|
|
1187
|
+
_a.sent();
|
|
1188
|
+
console.log('Login successful. Please use [rop init ]to create a project.');
|
|
1189
|
+
return [2 /*return*/];
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
}); };
|
|
1193
|
+
|
|
1194
|
+
var _upload = function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1195
|
+
var accessKey, projectId, token, artifact, arch, version, platform, signature, uploadClient;
|
|
1196
|
+
var _a, _b, _c, _d, _e;
|
|
1197
|
+
return __generator(this, function (_f) {
|
|
1198
|
+
switch (_f.label) {
|
|
1199
|
+
case 0:
|
|
1200
|
+
accessKey = config.accessKey, projectId = config.projectId, token = config.token, artifact = config.artifact, arch = config.arch, version = config.version, platform = config.platform, config.host;
|
|
1201
|
+
if ((_a = artifact.sig) === null || _a === void 0 ? void 0 : _a.path) {
|
|
1202
|
+
if (fs$1.existsSync(artifact.sig.path)) {
|
|
1203
|
+
signature = fs$1.readFileSync(artifact.sig.path, 'utf8');
|
|
1204
|
+
}
|
|
1205
|
+
else {
|
|
1206
|
+
console.warn('Warn sig file not found');
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
uploadClient = new RopUploadApi({ baseDomain: (_b = config.host) !== null && _b !== void 0 ? _b : defaultHost });
|
|
1210
|
+
return [4 /*yield*/, uploadClient.upload({
|
|
1211
|
+
accessKey: accessKey,
|
|
1212
|
+
projectId: projectId,
|
|
1213
|
+
token: token,
|
|
1214
|
+
arch: arch,
|
|
1215
|
+
platform: platform,
|
|
1216
|
+
version: version,
|
|
1217
|
+
targetPath: artifact.target.path,
|
|
1218
|
+
targetName: (_c = artifact.target) === null || _c === void 0 ? void 0 : _c.name,
|
|
1219
|
+
updatePath: (_d = artifact.update) === null || _d === void 0 ? void 0 : _d.path,
|
|
1220
|
+
updateName: (_e = artifact.update) === null || _e === void 0 ? void 0 : _e.name,
|
|
1221
|
+
signature: signature,
|
|
1222
|
+
})];
|
|
1223
|
+
case 1:
|
|
1224
|
+
_f.sent();
|
|
1225
|
+
return [2 /*return*/];
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
}); };
|
|
1229
|
+
var upload = function (platform, arch, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
1230
|
+
var configFilePath, data, projectId, token, jsonConfig, authApi, user, targetInfos, config, reset, _i, targetInfos_1, item;
|
|
1231
|
+
return __generator(this, function (_a) {
|
|
1232
|
+
switch (_a.label) {
|
|
1233
|
+
case 0:
|
|
1234
|
+
configFilePath = path.join('.', 'rop.json');
|
|
1235
|
+
if (!!fs$1.existsSync(configFilePath)) return [3 /*break*/, 2];
|
|
1236
|
+
return [4 /*yield*/, init()];
|
|
1237
|
+
case 1:
|
|
1238
|
+
_a.sent();
|
|
1239
|
+
_a.label = 2;
|
|
1240
|
+
case 2:
|
|
1241
|
+
data = loadJsonWithEnv({
|
|
1242
|
+
platform: platform,
|
|
1243
|
+
arch: arch,
|
|
1244
|
+
});
|
|
1245
|
+
if (!!options.accessKey) return [3 /*break*/, 7];
|
|
1246
|
+
jsonConfig = loadConfigJSON();
|
|
1247
|
+
if (!!jsonConfig.projectId) return [3 /*break*/, 4];
|
|
1248
|
+
return [4 /*yield*/, init()];
|
|
1249
|
+
case 3:
|
|
1250
|
+
projectId = _a.sent();
|
|
1251
|
+
return [3 /*break*/, 5];
|
|
1252
|
+
case 4:
|
|
1253
|
+
projectId = jsonConfig.projectId;
|
|
1254
|
+
_a.label = 5;
|
|
1255
|
+
case 5:
|
|
1256
|
+
authApi = new AuthApi({ baseDomain: defaultHost });
|
|
1257
|
+
return [4 /*yield*/, authApi.checkAndRefreshToken()];
|
|
1258
|
+
case 6:
|
|
1259
|
+
user = _a.sent();
|
|
1260
|
+
if (!user) {
|
|
1261
|
+
console.log('Unauthorized. Please execute the login command');
|
|
1262
|
+
return [2 /*return*/];
|
|
1263
|
+
}
|
|
1264
|
+
token = user.auth.accessToken;
|
|
1265
|
+
_a.label = 7;
|
|
1266
|
+
case 7:
|
|
1267
|
+
targetInfos = data.targetInfos, config = data.config, reset = __rest(data, ["targetInfos", "config"]);
|
|
1268
|
+
_i = 0, targetInfos_1 = targetInfos;
|
|
1269
|
+
_a.label = 8;
|
|
1270
|
+
case 8:
|
|
1271
|
+
if (!(_i < targetInfos_1.length)) return [3 /*break*/, 11];
|
|
1272
|
+
item = targetInfos_1[_i];
|
|
1273
|
+
return [4 /*yield*/, _upload(__assign(__assign({ accessKey: options.accessKey, projectId: projectId, token: token }, reset), { artifact: item.artifacts, host: config.host, platform: platform }))];
|
|
1274
|
+
case 9:
|
|
1275
|
+
_a.sent();
|
|
1276
|
+
_a.label = 10;
|
|
1277
|
+
case 10:
|
|
1278
|
+
_i++;
|
|
1279
|
+
return [3 /*break*/, 8];
|
|
1280
|
+
case 11: return [2 /*return*/];
|
|
1281
|
+
}
|
|
1282
|
+
});
|
|
1283
|
+
}); };
|
|
1284
|
+
|
|
1285
|
+
var program = new Command();
|
|
1286
|
+
program.name('rop').description('CLI to some JavaScript string utilities').version('0.1.0');
|
|
1287
|
+
program
|
|
1288
|
+
.command('login')
|
|
1289
|
+
.description('login')
|
|
1290
|
+
.option('-u --username <string>', 'username')
|
|
1291
|
+
.option('-p --password <string>', 'password')
|
|
1292
|
+
.action(login);
|
|
1293
|
+
program
|
|
1294
|
+
.command('init')
|
|
1295
|
+
.description('init rop')
|
|
1296
|
+
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
1297
|
+
return __generator(this, function (_a) {
|
|
1298
|
+
switch (_a.label) {
|
|
1299
|
+
case 0: return [4 /*yield*/, init()];
|
|
1300
|
+
case 1:
|
|
1301
|
+
_a.sent();
|
|
1302
|
+
return [2 /*return*/];
|
|
1303
|
+
}
|
|
1304
|
+
});
|
|
1305
|
+
}); });
|
|
1306
|
+
program
|
|
1307
|
+
.command('upload')
|
|
1308
|
+
.description('Upload some framework build')
|
|
1309
|
+
.argument('<string>', 'platform')
|
|
1310
|
+
.argument('[string]', 'arch')
|
|
1311
|
+
.option('-a, --accessKey <string>', 'accessKey path')
|
|
1312
|
+
.action(upload);
|
|
1313
|
+
// 解析命令行参数
|
|
1314
|
+
program.parse();
|
|
1315
|
+
// // // 如果没有指定任何命令,则显示帮助信息
|
|
1316
|
+
// if (process.argv.length <= 2) {
|
|
1317
|
+
// program.help();
|
|
1318
|
+
// }
|