@sevenvip666/rop 0.0.6 → 0.0.8
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/rop.mjs +767 -0
- package/dist/cjs/upload.js +223 -0
- package/dist/cjs/upload.js.map +1 -0
- package/dist/esm/upload.js +166 -0
- package/dist/esm/upload.js.map +1 -0
- package/dist/types/tauri/config.d.ts +15 -0
- package/dist/types/tauri/index.d.ts +10 -0
- package/dist/types/tauri/utils.d.ts +4 -0
- package/dist/types/types.d.ts +22 -0
- package/dist/types/upload.d.ts +13 -0
- package/dist/types/utils.d.ts +149 -0
- package/package.json +19 -14
- package/dist/index.d.ts +0 -44
- package/dist/rop.js +0 -585
package/dist/bin/rop.mjs
ADDED
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import * as os from 'os';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import fs__default, { readFileSync, existsSync } from 'fs';
|
|
6
|
+
import { confirm, input } from '@inquirer/prompts';
|
|
7
|
+
import colors from 'ansi-colors';
|
|
8
|
+
import path, { resolve, join, sep, normalize } from 'path';
|
|
9
|
+
import * as yaml from 'js-yaml';
|
|
10
|
+
import { exec } from 'child_process';
|
|
11
|
+
import { parse } from '@iarna/toml';
|
|
12
|
+
import { globbySync } from 'globby';
|
|
13
|
+
import JSON5 from 'json5';
|
|
14
|
+
import fetch from 'node-fetch';
|
|
15
|
+
import FormData from 'form-data';
|
|
16
|
+
import cliProgress from 'cli-progress';
|
|
17
|
+
|
|
18
|
+
/******************************************************************************
|
|
19
|
+
Copyright (c) Microsoft Corporation.
|
|
20
|
+
|
|
21
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
22
|
+
purpose with or without fee is hereby granted.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
25
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
26
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
27
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
28
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
29
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
30
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
31
|
+
***************************************************************************** */
|
|
32
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
var __assign = function() {
|
|
36
|
+
__assign = Object.assign || function __assign(t) {
|
|
37
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
38
|
+
s = arguments[i];
|
|
39
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
40
|
+
}
|
|
41
|
+
return t;
|
|
42
|
+
};
|
|
43
|
+
return __assign.apply(this, arguments);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
47
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
48
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
49
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
50
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
51
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
52
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function __generator(thisArg, body) {
|
|
57
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
58
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
59
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
60
|
+
function step(op) {
|
|
61
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
63
|
+
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;
|
|
64
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
65
|
+
switch (op[0]) {
|
|
66
|
+
case 0: case 1: t = op; break;
|
|
67
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
68
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
69
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
70
|
+
default:
|
|
71
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
72
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
73
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
74
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
75
|
+
if (t[2]) _.ops.pop();
|
|
76
|
+
_.trys.pop(); continue;
|
|
77
|
+
}
|
|
78
|
+
op = body.call(thisArg, _);
|
|
79
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
80
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
85
|
+
var e = new Error(message);
|
|
86
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var Init = /** @class */ (function () {
|
|
90
|
+
function Init() {
|
|
91
|
+
}
|
|
92
|
+
Init.prototype.initYaml = function (accessKey) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var __dirname, projectName, ymlConfigPath, ymlConfigJson, flag, ymlContent, yamlData;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
switch (_a.label) {
|
|
97
|
+
case 0:
|
|
98
|
+
__dirname = path.resolve();
|
|
99
|
+
projectName = path.basename(__dirname);
|
|
100
|
+
ymlConfigPath = path.join('.', 'rop.yml');
|
|
101
|
+
ymlConfigJson = {};
|
|
102
|
+
if (!fs__default.existsSync(ymlConfigPath)) return [3 /*break*/, 5];
|
|
103
|
+
flag = false;
|
|
104
|
+
_a.label = 1;
|
|
105
|
+
case 1:
|
|
106
|
+
_a.trys.push([1, 3, , 4]);
|
|
107
|
+
return [4 /*yield*/, confirm({
|
|
108
|
+
message: "".concat(colors.cyan('rop.yml'), " already exists, does it need to be overwritten?"),
|
|
109
|
+
})];
|
|
110
|
+
case 2:
|
|
111
|
+
flag = _a.sent();
|
|
112
|
+
return [3 /*break*/, 4];
|
|
113
|
+
case 3:
|
|
114
|
+
_a.sent();
|
|
115
|
+
console.log('cancel');
|
|
116
|
+
return [2 /*return*/, false];
|
|
117
|
+
case 4:
|
|
118
|
+
if (!flag) {
|
|
119
|
+
console.log('cancel');
|
|
120
|
+
return [2 /*return*/, false];
|
|
121
|
+
}
|
|
122
|
+
ymlContent = fs__default.readFileSync(ymlConfigPath, 'utf8');
|
|
123
|
+
ymlConfigJson = yaml.load(ymlContent);
|
|
124
|
+
_a.label = 5;
|
|
125
|
+
case 5:
|
|
126
|
+
if (!ymlConfigJson.access) {
|
|
127
|
+
ymlConfigJson.access = {
|
|
128
|
+
name: projectName,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
ymlConfigJson.access.name = projectName;
|
|
133
|
+
}
|
|
134
|
+
yamlData = yaml.dump(ymlConfigJson, {
|
|
135
|
+
lineWidth: 500,
|
|
136
|
+
});
|
|
137
|
+
fs__default.writeFileSync(ymlConfigPath, yamlData, 'utf8');
|
|
138
|
+
return [2 /*return*/, true];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
Init.prototype.initRopConfig = function (accessKey) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
145
|
+
var ropConfigDirPath, ropConfigPath, ropConfigData;
|
|
146
|
+
return __generator(this, function (_a) {
|
|
147
|
+
ropConfigDirPath = path.join('.', '.rop');
|
|
148
|
+
if (!fs__default.existsSync(ropConfigDirPath)) {
|
|
149
|
+
fs__default.mkdirSync(ropConfigDirPath);
|
|
150
|
+
}
|
|
151
|
+
ropConfigPath = path.join(ropConfigDirPath, 'config.json');
|
|
152
|
+
ropConfigData = {};
|
|
153
|
+
if (fs__default.existsSync(ropConfigPath)) {
|
|
154
|
+
ropConfigData = JSON.parse(fs__default.readFileSync(ropConfigPath, 'utf8'));
|
|
155
|
+
}
|
|
156
|
+
ropConfigData.accessKey = accessKey;
|
|
157
|
+
fs__default.writeFileSync(ropConfigPath, JSON.stringify(ropConfigData, null, 2), 'utf8');
|
|
158
|
+
return [2 /*return*/];
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
};
|
|
162
|
+
Init.prototype.initGitignore = function () {
|
|
163
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
164
|
+
var gitignorePath, gitignoreData;
|
|
165
|
+
return __generator(this, function (_a) {
|
|
166
|
+
gitignorePath = path.join('.', '.gitignore');
|
|
167
|
+
if (fs__default.existsSync(gitignorePath)) {
|
|
168
|
+
gitignoreData = fs__default.readFileSync(gitignorePath, 'utf8');
|
|
169
|
+
if (!gitignoreData.includes('.rop')) {
|
|
170
|
+
fs__default.appendFileSync(gitignorePath, "\n.rop", 'utf8');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
fs__default.writeFileSync(gitignorePath, ".rop", 'utf8');
|
|
175
|
+
}
|
|
176
|
+
return [2 /*return*/];
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
return Init;
|
|
181
|
+
}());
|
|
182
|
+
|
|
183
|
+
var Framework;
|
|
184
|
+
(function (Framework) {
|
|
185
|
+
Framework["TAURI"] = "TAURI";
|
|
186
|
+
Framework["IONIC"] = "IONIC";
|
|
187
|
+
Framework["FLUTTER"] = "FLUTTER";
|
|
188
|
+
})(Framework || (Framework = {}));
|
|
189
|
+
|
|
190
|
+
function getWorkspaceDir(dir) {
|
|
191
|
+
var _a;
|
|
192
|
+
var rootPath = dir;
|
|
193
|
+
while (dir.length && dir[dir.length - 1] !== sep) {
|
|
194
|
+
var manifestPath = join(dir, 'Cargo.toml');
|
|
195
|
+
if (existsSync(manifestPath)) {
|
|
196
|
+
var toml = parse(readFileSync(manifestPath).toString());
|
|
197
|
+
if ((_a = toml.workspace) === null || _a === void 0 ? void 0 : _a.members) {
|
|
198
|
+
var ignore = ['**/target', '**/node_modules'];
|
|
199
|
+
if (toml.workspace.exclude)
|
|
200
|
+
ignore.push.apply(ignore, toml.workspace.exclude);
|
|
201
|
+
var memberPaths = globbySync(toml.workspace.members, {
|
|
202
|
+
cwd: dir,
|
|
203
|
+
ignore: ignore,
|
|
204
|
+
expandDirectories: false,
|
|
205
|
+
onlyFiles: false,
|
|
206
|
+
});
|
|
207
|
+
if (memberPaths.some(function (m) { return resolve(dir, m) === rootPath; })) {
|
|
208
|
+
return dir;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
dir = normalize(join(dir, '..'));
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
function getTauriDir(root) {
|
|
217
|
+
var tauriConfPaths = globbySync(['**/tauri.conf.json', '**/tauri.conf.json5', '**/Tauri.toml'], {
|
|
218
|
+
gitignore: true,
|
|
219
|
+
cwd: root,
|
|
220
|
+
// Forcefully ignore target and node_modules dirs
|
|
221
|
+
ignore: ['**/target', '**/node_modules'],
|
|
222
|
+
});
|
|
223
|
+
if (tauriConfPaths.length === 0) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
return resolve(root, tauriConfPaths[0], '..');
|
|
227
|
+
}
|
|
228
|
+
function getCargoManifest(dir) {
|
|
229
|
+
var _a, _b, _c, _d;
|
|
230
|
+
var manifestPath = join(dir, 'Cargo.toml');
|
|
231
|
+
var cargoManifest = parse(readFileSync(manifestPath).toString());
|
|
232
|
+
var name = cargoManifest.package.name;
|
|
233
|
+
var version = cargoManifest.package.version;
|
|
234
|
+
// if the version or name is an object, it means it is a workspace package and we need to traverse up
|
|
235
|
+
if (typeof cargoManifest.package.version == 'object' || typeof cargoManifest.package.name == 'object') {
|
|
236
|
+
var workspaceDir = getWorkspaceDir(dir);
|
|
237
|
+
if (!workspaceDir) {
|
|
238
|
+
throw new Error('Could not find workspace directory, but version and/or name specifies to use workspace package');
|
|
239
|
+
}
|
|
240
|
+
var manifestPath_1 = join(workspaceDir, 'Cargo.toml');
|
|
241
|
+
var workspaceManifest = parse(readFileSync(manifestPath_1).toString());
|
|
242
|
+
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) {
|
|
243
|
+
name = workspaceManifest.workspace.package.name;
|
|
244
|
+
}
|
|
245
|
+
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) {
|
|
246
|
+
version = workspaceManifest.workspace.package.version;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return __assign(__assign({}, cargoManifest), { package: __assign(__assign({}, cargoManifest.package), { name: name, version: version }) });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function _tryParseJsonConfig(contents) {
|
|
253
|
+
try {
|
|
254
|
+
var config = JSON.parse(contents);
|
|
255
|
+
return config;
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
// @ts-ignore
|
|
259
|
+
var msg = e.message;
|
|
260
|
+
console.error("Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: \"".concat(msg, "\""));
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function _tryParseJson5Config(contents) {
|
|
265
|
+
try {
|
|
266
|
+
var config = JSON5.parse(contents);
|
|
267
|
+
return config;
|
|
268
|
+
}
|
|
269
|
+
catch (e) {
|
|
270
|
+
// @ts-ignore
|
|
271
|
+
var msg = e.message;
|
|
272
|
+
console.error("Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: \"".concat(msg, "\""));
|
|
273
|
+
return null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function _tryParseTomlConfig(contents) {
|
|
277
|
+
try {
|
|
278
|
+
var config = parse(contents);
|
|
279
|
+
return config;
|
|
280
|
+
}
|
|
281
|
+
catch (e) {
|
|
282
|
+
// @ts-ignore
|
|
283
|
+
var msg = e.message;
|
|
284
|
+
console.error("Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: \"".concat(msg, "\""));
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
var TauriConfig = /** @class */ (function () {
|
|
289
|
+
function TauriConfig(identifier) {
|
|
290
|
+
this.identifier = identifier;
|
|
291
|
+
}
|
|
292
|
+
TauriConfig.fromBaseConfig = function (tauriDir) {
|
|
293
|
+
console.log(tauriDir);
|
|
294
|
+
if (existsSync(join(tauriDir, 'tauri.conf.json'))) {
|
|
295
|
+
var contents = readFileSync(join(tauriDir, 'tauri.conf.json')).toString();
|
|
296
|
+
var config = _tryParseJsonConfig(contents);
|
|
297
|
+
if (config) {
|
|
298
|
+
if ('identifier' in config) {
|
|
299
|
+
return this.fromV2Base(config);
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
return this.fromV1Base(config);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
console.error("Found tauri.conf.json file but couldn't parse it as JSON.");
|
|
306
|
+
}
|
|
307
|
+
if (existsSync(join(tauriDir, 'tauri.conf.json5'))) {
|
|
308
|
+
var contents = readFileSync(join(tauriDir, 'tauri.conf.json5')).toString();
|
|
309
|
+
var config = _tryParseJson5Config(contents);
|
|
310
|
+
if (config) {
|
|
311
|
+
if ('identifier' in config) {
|
|
312
|
+
return this.fromV2Base(config);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
return this.fromV1Base(config);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
console.error("Found tauri.conf.json5 file but couldn't parse it as JSON5.");
|
|
319
|
+
}
|
|
320
|
+
if (existsSync(join(tauriDir, 'Tauri.toml'))) {
|
|
321
|
+
var contents = readFileSync(join(tauriDir, 'Tauri.toml')).toString();
|
|
322
|
+
var config = _tryParseTomlConfig(contents);
|
|
323
|
+
if (config) {
|
|
324
|
+
if ('identifier' in config) {
|
|
325
|
+
return this.fromV2Base(config);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
return this.fromV1Base(config);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
console.error("Found Tauri.toml file but couldn't parse it as TOML.");
|
|
332
|
+
}
|
|
333
|
+
throw new Error("Couldn't locate or parse tauri config.");
|
|
334
|
+
};
|
|
335
|
+
TauriConfig.fromV1Base = function (config) {
|
|
336
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
337
|
+
if (!((_b = (_a = config.tauri) === null || _a === void 0 ? void 0 : _a.bundle) === null || _b === void 0 ? void 0 : _b.identifier)) {
|
|
338
|
+
throw Error('base config has no bundle identifier.');
|
|
339
|
+
}
|
|
340
|
+
var c = new TauriConfig((_d = (_c = config.tauri) === null || _c === void 0 ? void 0 : _c.bundle) === null || _d === void 0 ? void 0 : _d.identifier);
|
|
341
|
+
c.productName = (_e = config.package) === null || _e === void 0 ? void 0 : _e.productName;
|
|
342
|
+
c.version = (_f = config.package) === null || _f === void 0 ? void 0 : _f.version;
|
|
343
|
+
c.frontendDist = (_g = config.build) === null || _g === void 0 ? void 0 : _g.distDir;
|
|
344
|
+
c.beforeBuildCommand = (_h = config.build) === null || _h === void 0 ? void 0 : _h.beforeBuildCommand;
|
|
345
|
+
c.rpmRelease = (_j = config.tauri.bundle.rpm) === null || _j === void 0 ? void 0 : _j.release;
|
|
346
|
+
c.wixLanguage = (_l = (_k = config.tauri.bundle.windows) === null || _k === void 0 ? void 0 : _k.wix) === null || _l === void 0 ? void 0 : _l.language;
|
|
347
|
+
return c;
|
|
348
|
+
};
|
|
349
|
+
TauriConfig.fromV2Base = function (config) {
|
|
350
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
351
|
+
if (!config.identifier) {
|
|
352
|
+
throw Error('base config has no bundle identifier.');
|
|
353
|
+
}
|
|
354
|
+
var c = new TauriConfig(config.identifier);
|
|
355
|
+
c.productName = config.productName;
|
|
356
|
+
c.version = config.version;
|
|
357
|
+
c.frontendDist = (_a = config.build) === null || _a === void 0 ? void 0 : _a.frontendDist;
|
|
358
|
+
c.beforeBuildCommand = (_b = config.build) === null || _b === void 0 ? void 0 : _b.beforeBuildCommand;
|
|
359
|
+
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;
|
|
360
|
+
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;
|
|
361
|
+
return c;
|
|
362
|
+
};
|
|
363
|
+
return TauriConfig;
|
|
364
|
+
}());
|
|
365
|
+
|
|
366
|
+
var getTauriEnv = function (projectPath) {
|
|
367
|
+
var _a;
|
|
368
|
+
var tauriDir = getTauriDir(projectPath !== null && projectPath !== void 0 ? projectPath : '.');
|
|
369
|
+
if (tauriDir !== null) {
|
|
370
|
+
var name_1;
|
|
371
|
+
var version = void 0;
|
|
372
|
+
var wixLanguage = 'en-US';
|
|
373
|
+
var rpmRelease = '1';
|
|
374
|
+
var config = TauriConfig.fromBaseConfig(tauriDir);
|
|
375
|
+
name_1 = config === null || config === void 0 ? void 0 : config.productName;
|
|
376
|
+
if ((_a = config.version) === null || _a === void 0 ? void 0 : _a.endsWith('.json')) {
|
|
377
|
+
var packageJsonPath = join(tauriDir, config === null || config === void 0 ? void 0 : config.version);
|
|
378
|
+
var contents = readFileSync(packageJsonPath).toString();
|
|
379
|
+
version = JSON.parse(contents).version;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
version = config === null || config === void 0 ? void 0 : config.version;
|
|
383
|
+
}
|
|
384
|
+
if (!(name_1 && version)) {
|
|
385
|
+
var cargoManifest = getCargoManifest(tauriDir);
|
|
386
|
+
name_1 = name_1 !== null && name_1 !== void 0 ? name_1 : cargoManifest.package.name;
|
|
387
|
+
version = version !== null && version !== void 0 ? version : cargoManifest.package.version;
|
|
388
|
+
}
|
|
389
|
+
if (!(name_1 && version)) {
|
|
390
|
+
console.error('Could not determine package name and version.');
|
|
391
|
+
process.exit(1);
|
|
392
|
+
}
|
|
393
|
+
var wixAppVersion = version.replace(/[-+]/g, '.');
|
|
394
|
+
if (config.wixLanguage) {
|
|
395
|
+
wixLanguage = config.wixLanguage;
|
|
396
|
+
}
|
|
397
|
+
if (config.rpmRelease) {
|
|
398
|
+
rpmRelease = config.rpmRelease;
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
basePath: tauriDir + '/target',
|
|
402
|
+
appName: name_1,
|
|
403
|
+
version: version,
|
|
404
|
+
wixLanguage: wixLanguage,
|
|
405
|
+
wixAppVersion: wixAppVersion,
|
|
406
|
+
rpmRelease: rpmRelease,
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
// This should not actually happen.
|
|
411
|
+
throw Error("Couldn't detect Tauri dir");
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
var getBranch = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
416
|
+
return __generator(this, function (_a) {
|
|
417
|
+
return [2 /*return*/, new Promise(function (resolve) {
|
|
418
|
+
return exec('git rev-parse --abbrev-ref HEAD', function (err, stdout, stderr) {
|
|
419
|
+
if (err) {
|
|
420
|
+
console.log("getBranch Error: ".concat(err));
|
|
421
|
+
}
|
|
422
|
+
else if (stdout) {
|
|
423
|
+
resolve(stdout.trim());
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
resolve(undefined);
|
|
427
|
+
});
|
|
428
|
+
})];
|
|
429
|
+
});
|
|
430
|
+
}); };
|
|
431
|
+
// 读取 YAML 文件并替换模版变量
|
|
432
|
+
function loadYamlWithEnv(_a) {
|
|
433
|
+
var _b;
|
|
434
|
+
var platform = _a.platform, arch = _a.arch, optionAccessKey = _a.optionAccessKey;
|
|
435
|
+
var configFilePath = path.join('.', 'rop.yml');
|
|
436
|
+
var configData = fs__default.readFileSync(configFilePath, 'utf8');
|
|
437
|
+
var config = yaml.load(configData);
|
|
438
|
+
var _arch;
|
|
439
|
+
if (arch == 'x86_64') {
|
|
440
|
+
_arch = 'x64';
|
|
441
|
+
}
|
|
442
|
+
else if (arch) {
|
|
443
|
+
_arch = arch;
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
_arch = 'x64';
|
|
447
|
+
}
|
|
448
|
+
var env = {
|
|
449
|
+
arch: _arch,
|
|
450
|
+
};
|
|
451
|
+
// 确保配置文件中存在 framework 属性
|
|
452
|
+
if (!config.framework.name) {
|
|
453
|
+
throw new Error('Missing "framework.name" property in the configuration file.');
|
|
454
|
+
}
|
|
455
|
+
var _autoEnv = getAutoEnvByFramework(config.framework.name, config.projectPath);
|
|
456
|
+
if (!_autoEnv && !config.framework.env) {
|
|
457
|
+
throw new Error("The [".concat(config.framework.name, "] framework is not supported, please specify the [framework.env] attribute."));
|
|
458
|
+
}
|
|
459
|
+
env = __assign(__assign(__assign({}, env), _autoEnv), ((_b = config.framework.env) !== null && _b !== void 0 ? _b : {}));
|
|
460
|
+
// 确保配置文件中存在 host 属性
|
|
461
|
+
if (!env.appName) {
|
|
462
|
+
throw new Error('Missing "appName" property in the configuration file.');
|
|
463
|
+
}
|
|
464
|
+
// 确保配置文件中存在 host 属性
|
|
465
|
+
if (!env.version) {
|
|
466
|
+
throw new Error('Missing "version" property in the configuration file.');
|
|
467
|
+
}
|
|
468
|
+
// 递归函数来替换对象中的字符串值
|
|
469
|
+
function replaceEnvInObject(obj) {
|
|
470
|
+
Object.keys(obj).forEach(function (key) {
|
|
471
|
+
if (typeof obj[key] === 'string') {
|
|
472
|
+
// 使用正则表达式替换模版变量(这里假设模版变量是 ${VAR} 格式的)
|
|
473
|
+
// @ts-ignore
|
|
474
|
+
obj[key] = obj[key].replace(/\$\{(\w+)\}/g, function (_, envVar) { return env[envVar] || ''; });
|
|
475
|
+
}
|
|
476
|
+
else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
477
|
+
replaceEnvInObject(obj[key]); // 递归处理嵌套对象
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
replaceEnvInObject(config);
|
|
482
|
+
var targetInfo = config.platforms[platform][_arch];
|
|
483
|
+
console.log('find target file:');
|
|
484
|
+
console.log(targetInfo);
|
|
485
|
+
var accessKey = getAccessKey(optionAccessKey, config.access);
|
|
486
|
+
return { config: config, targetInfo: targetInfo, accessKey: accessKey, version: env.version };
|
|
487
|
+
}
|
|
488
|
+
var getAccessKey = function (accessKey, access) {
|
|
489
|
+
if (accessKey) {
|
|
490
|
+
return accessKey;
|
|
491
|
+
}
|
|
492
|
+
if (access === null || access === void 0 ? void 0 : access.key) {
|
|
493
|
+
return access === null || access === void 0 ? void 0 : access.key;
|
|
494
|
+
}
|
|
495
|
+
if (access === null || access === void 0 ? void 0 : access.name) {
|
|
496
|
+
var configData = fs__default.readFileSync("".concat(os.homedir(), "/.rop/config"), 'utf8');
|
|
497
|
+
var regex = "\\[".concat(access.name, "]\\n(.+)");
|
|
498
|
+
var match = new RegExp(regex).exec(configData);
|
|
499
|
+
if (match) {
|
|
500
|
+
return match[1];
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
throw new Error('missing access-key');
|
|
504
|
+
};
|
|
505
|
+
var getAutoEnvByFramework = function (framework, projectPath) {
|
|
506
|
+
switch (framework.toLowerCase()) {
|
|
507
|
+
case Framework.TAURI.toLowerCase():
|
|
508
|
+
return getTauriEnv(projectPath);
|
|
509
|
+
default:
|
|
510
|
+
return undefined;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
var RopUpload = /** @class */ (function () {
|
|
515
|
+
function RopUpload(_a) {
|
|
516
|
+
var baseDomain = _a.baseDomain;
|
|
517
|
+
var _this = this;
|
|
518
|
+
this.checkParams = function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
519
|
+
var branch, _a;
|
|
520
|
+
var _b;
|
|
521
|
+
return __generator(this, function (_c) {
|
|
522
|
+
switch (_c.label) {
|
|
523
|
+
case 0:
|
|
524
|
+
if (!config.accessKey) {
|
|
525
|
+
throw new Error('accessKey not null');
|
|
526
|
+
}
|
|
527
|
+
if (!((_b = config.branch) !== null && _b !== void 0)) return [3 /*break*/, 1];
|
|
528
|
+
_a = _b;
|
|
529
|
+
return [3 /*break*/, 3];
|
|
530
|
+
case 1: return [4 /*yield*/, getBranch()];
|
|
531
|
+
case 2:
|
|
532
|
+
_a = (_c.sent());
|
|
533
|
+
_c.label = 3;
|
|
534
|
+
case 3:
|
|
535
|
+
branch = _a;
|
|
536
|
+
if (!branch) {
|
|
537
|
+
throw new Error('branch not null');
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
config.branch = branch;
|
|
541
|
+
}
|
|
542
|
+
if (!config.platform) {
|
|
543
|
+
throw new Error('platform not null');
|
|
544
|
+
}
|
|
545
|
+
if (!config.arch) {
|
|
546
|
+
throw new Error('arch not null');
|
|
547
|
+
}
|
|
548
|
+
if (!config.targetPath) {
|
|
549
|
+
throw new Error('target path not null');
|
|
550
|
+
}
|
|
551
|
+
if (!fs__default.existsSync(config.targetPath)) {
|
|
552
|
+
throw new Error("target file not found, file path: ".concat(config.targetPath));
|
|
553
|
+
}
|
|
554
|
+
if (config.updatePath && !fs__default.existsSync(config.updatePath)) {
|
|
555
|
+
throw new Error("update file not found\uFF0C file path: ".concat(config.updatePath));
|
|
556
|
+
}
|
|
557
|
+
if (!config.version) {
|
|
558
|
+
throw new Error('version not null');
|
|
559
|
+
}
|
|
560
|
+
return [2 /*return*/, config];
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
}); };
|
|
564
|
+
this.baseDomain = baseDomain;
|
|
565
|
+
}
|
|
566
|
+
RopUpload.prototype.upload = function (_config) {
|
|
567
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
568
|
+
var config, formData, fileStream, multibar, bar1, totalUploaded, updateFileStream, bar2_1, totalUpdateUploaded_1, res, body;
|
|
569
|
+
var _a, _b;
|
|
570
|
+
return __generator(this, function (_c) {
|
|
571
|
+
switch (_c.label) {
|
|
572
|
+
case 0: return [4 /*yield*/, this.checkParams(_config)];
|
|
573
|
+
case 1:
|
|
574
|
+
config = _c.sent();
|
|
575
|
+
formData = new FormData();
|
|
576
|
+
fileStream = fs__default.createReadStream(config.targetPath);
|
|
577
|
+
multibar = new cliProgress.MultiBar({
|
|
578
|
+
format: 'Upload Progress |' + colors.cyan('{bar}') + '| {percentage}% | {filename}',
|
|
579
|
+
barCompleteChar: '\u2588',
|
|
580
|
+
barIncompleteChar: '\u2591',
|
|
581
|
+
hideCursor: true,
|
|
582
|
+
});
|
|
583
|
+
bar1 = multibar.create(fs__default.statSync(config.targetPath).size, 0);
|
|
584
|
+
totalUploaded = 0;
|
|
585
|
+
fileStream.on('data', function (chunk) {
|
|
586
|
+
totalUploaded += chunk.length;
|
|
587
|
+
bar1.update(totalUploaded, { filename: path.basename(config.targetPath) });
|
|
588
|
+
});
|
|
589
|
+
formData.append('targetFile', fileStream, {
|
|
590
|
+
filename: (_a = config.targetName) !== null && _a !== void 0 ? _a : path.basename(config.targetPath),
|
|
591
|
+
});
|
|
592
|
+
if (config.updatePath) {
|
|
593
|
+
bar2_1 = multibar.create(fs__default.statSync(config.updatePath).size, 0);
|
|
594
|
+
updateFileStream = fs__default.createReadStream(config.updatePath);
|
|
595
|
+
totalUpdateUploaded_1 = 0;
|
|
596
|
+
updateFileStream.on('data', function (chunk) {
|
|
597
|
+
totalUpdateUploaded_1 += chunk.length;
|
|
598
|
+
bar2_1.update(totalUpdateUploaded_1, { filename: path.basename(config.updatePath) });
|
|
599
|
+
});
|
|
600
|
+
formData.append('updateFile', updateFileStream, {
|
|
601
|
+
filename: (_b = config.updateName) !== null && _b !== void 0 ? _b : path.basename(config.updatePath),
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
formData.append('accessKey', config.accessKey);
|
|
605
|
+
formData.append('branch', config.branch);
|
|
606
|
+
formData.append('version', config.version);
|
|
607
|
+
formData.append('platform', config.platform);
|
|
608
|
+
formData.append('arch', config.arch);
|
|
609
|
+
if (config.signature) {
|
|
610
|
+
formData.append('signature', config.signature);
|
|
611
|
+
}
|
|
612
|
+
return [4 /*yield*/, fetch("".concat(this.baseDomain, "/api/upload"), {
|
|
613
|
+
method: 'POST',
|
|
614
|
+
headers: formData.getHeaders(),
|
|
615
|
+
body: formData,
|
|
616
|
+
})];
|
|
617
|
+
case 2:
|
|
618
|
+
res = _c.sent();
|
|
619
|
+
return [4 /*yield*/, res.json()];
|
|
620
|
+
case 3:
|
|
621
|
+
body = _c.sent();
|
|
622
|
+
if (!res.ok) {
|
|
623
|
+
console.log(res.status, res.statusText, body);
|
|
624
|
+
}
|
|
625
|
+
multibar.stop();
|
|
626
|
+
fileStream.destroy();
|
|
627
|
+
updateFileStream === null || updateFileStream === void 0 ? void 0 : updateFileStream.destroy();
|
|
628
|
+
return [2 /*return*/, { success: res.ok, body: body }];
|
|
629
|
+
}
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
};
|
|
633
|
+
return RopUpload;
|
|
634
|
+
}());
|
|
635
|
+
|
|
636
|
+
var program = new Command();
|
|
637
|
+
program.name('rop').description('CLI to some JavaScript string utilities').version('0.1.0');
|
|
638
|
+
program
|
|
639
|
+
.command('init')
|
|
640
|
+
.description('init rop')
|
|
641
|
+
.action(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
642
|
+
var accessKey, init;
|
|
643
|
+
return __generator(this, function (_a) {
|
|
644
|
+
switch (_a.label) {
|
|
645
|
+
case 0:
|
|
646
|
+
accessKey = '';
|
|
647
|
+
_a.label = 1;
|
|
648
|
+
case 1:
|
|
649
|
+
if (!!accessKey) return [3 /*break*/, 6];
|
|
650
|
+
_a.label = 2;
|
|
651
|
+
case 2:
|
|
652
|
+
_a.trys.push([2, 4, , 5]);
|
|
653
|
+
return [4 /*yield*/, input({ message: "Please enter ".concat(colors.cyan('access-key')) })];
|
|
654
|
+
case 3:
|
|
655
|
+
accessKey = _a.sent();
|
|
656
|
+
return [3 /*break*/, 5];
|
|
657
|
+
case 4:
|
|
658
|
+
_a.sent();
|
|
659
|
+
console.log('cancel');
|
|
660
|
+
return [2 /*return*/];
|
|
661
|
+
case 5: return [3 /*break*/, 1];
|
|
662
|
+
case 6:
|
|
663
|
+
init = new Init();
|
|
664
|
+
return [4 /*yield*/, init.initYaml(accessKey)];
|
|
665
|
+
case 7:
|
|
666
|
+
if (!_a.sent()) return [3 /*break*/, 10];
|
|
667
|
+
return [4 /*yield*/, init.initRopConfig(accessKey)];
|
|
668
|
+
case 8:
|
|
669
|
+
_a.sent();
|
|
670
|
+
return [4 /*yield*/, init.initGitignore()];
|
|
671
|
+
case 9:
|
|
672
|
+
_a.sent();
|
|
673
|
+
console.log('done');
|
|
674
|
+
_a.label = 10;
|
|
675
|
+
case 10: return [2 /*return*/];
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
}); });
|
|
679
|
+
program
|
|
680
|
+
.command('set-key')
|
|
681
|
+
.description('set access-key')
|
|
682
|
+
.argument('<string>', 'projectAccessKey')
|
|
683
|
+
.action(function (projectAccessKey) { return __awaiter(void 0, void 0, void 0, function () {
|
|
684
|
+
var array, projectName, accessKey, homeDirectory, homedir, filePath, content, configData, regex, match;
|
|
685
|
+
return __generator(this, function (_a) {
|
|
686
|
+
try {
|
|
687
|
+
array = projectAccessKey.split('=');
|
|
688
|
+
if (array.length != 2) {
|
|
689
|
+
throw new Error('parameter format error');
|
|
690
|
+
}
|
|
691
|
+
projectName = array[0], accessKey = array[1];
|
|
692
|
+
homeDirectory = os.homedir();
|
|
693
|
+
homedir = "".concat(homeDirectory, "/.rop");
|
|
694
|
+
if (!fs.existsSync(homedir)) {
|
|
695
|
+
fs.mkdirSync(homedir);
|
|
696
|
+
}
|
|
697
|
+
filePath = "".concat(homedir, "/config");
|
|
698
|
+
content = "[".concat(projectName, "]\n").concat(accessKey);
|
|
699
|
+
if (!fs.existsSync(filePath)) {
|
|
700
|
+
fs.writeFileSync(filePath, content);
|
|
701
|
+
}
|
|
702
|
+
else {
|
|
703
|
+
configData = fs.readFileSync(filePath, 'utf8');
|
|
704
|
+
regex = "\\[".concat(projectName, "]\\n(.+)");
|
|
705
|
+
match = new RegExp(regex).exec(configData);
|
|
706
|
+
if (match) {
|
|
707
|
+
fs.writeFileSync(filePath, configData.replace(match[0], content));
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
fs.appendFileSync(filePath, '\n' + content);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
catch (error) {
|
|
715
|
+
console.error('Error reading configuration file or missing required properties:', error);
|
|
716
|
+
}
|
|
717
|
+
return [2 /*return*/];
|
|
718
|
+
});
|
|
719
|
+
}); });
|
|
720
|
+
program
|
|
721
|
+
.command('upload')
|
|
722
|
+
.description('Upload some framework build')
|
|
723
|
+
.argument('<string>', 'platform')
|
|
724
|
+
.argument('[string]', 'arch')
|
|
725
|
+
.option('-a, --accessKey <string>', 'accessKey path')
|
|
726
|
+
.action(function (platform, arch, options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
727
|
+
var _a, config, targetInfo, accessKey, version, uploadClient;
|
|
728
|
+
var _b, _c, _d, _e;
|
|
729
|
+
return __generator(this, function (_f) {
|
|
730
|
+
switch (_f.label) {
|
|
731
|
+
case 0:
|
|
732
|
+
_a = loadYamlWithEnv({
|
|
733
|
+
platform: platform,
|
|
734
|
+
arch: arch,
|
|
735
|
+
optionAccessKey: options.accessKey,
|
|
736
|
+
}), config = _a.config, targetInfo = _a.targetInfo, accessKey = _a.accessKey, version = _a.version;
|
|
737
|
+
// 确保配置文件中存在 host 属性
|
|
738
|
+
if (!config.host) {
|
|
739
|
+
throw new Error('Missing "host" property in the configuration file.');
|
|
740
|
+
}
|
|
741
|
+
if (!targetInfo) {
|
|
742
|
+
throw new Error('Missing "targetInfo" property in the configuration file.');
|
|
743
|
+
}
|
|
744
|
+
uploadClient = new RopUpload({ baseDomain: config.host });
|
|
745
|
+
return [4 /*yield*/, uploadClient.upload({
|
|
746
|
+
accessKey: accessKey,
|
|
747
|
+
arch: arch,
|
|
748
|
+
platform: platform,
|
|
749
|
+
version: version,
|
|
750
|
+
targetPath: targetInfo.target.path,
|
|
751
|
+
targetName: (_b = targetInfo.target) === null || _b === void 0 ? void 0 : _b.name,
|
|
752
|
+
updatePath: (_c = targetInfo.update) === null || _c === void 0 ? void 0 : _c.path,
|
|
753
|
+
updateName: (_d = targetInfo.update) === null || _d === void 0 ? void 0 : _d.name,
|
|
754
|
+
signature: ((_e = targetInfo.sig) === null || _e === void 0 ? void 0 : _e.path) ? fs.readFileSync(targetInfo.sig.path, 'utf8') : undefined,
|
|
755
|
+
})];
|
|
756
|
+
case 1:
|
|
757
|
+
_f.sent();
|
|
758
|
+
return [2 /*return*/];
|
|
759
|
+
}
|
|
760
|
+
});
|
|
761
|
+
}); });
|
|
762
|
+
// 解析命令行参数
|
|
763
|
+
program.parse();
|
|
764
|
+
// // // 如果没有指定任何命令,则显示帮助信息
|
|
765
|
+
// if (process.argv.length <= 2) {
|
|
766
|
+
// program.help();
|
|
767
|
+
// }
|