@sevenvip666/rop 0.0.5 → 0.0.6
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/rop.js +486 -286
- package/package.json +1 -1
package/dist/rop.js
CHANGED
|
@@ -1,385 +1,585 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
ignore: o,
|
|
29
|
-
expandDirectories: !1,
|
|
30
|
-
onlyFiles: !1
|
|
31
|
-
}).some((i) => x(n, i) === t))
|
|
32
|
-
return n;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const commander = require("commander");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const fetch = require("node-fetch");
|
|
6
|
+
const FormData = require("form-data");
|
|
7
|
+
const child_process = require("child_process");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
const yaml = require("js-yaml");
|
|
10
|
+
const os = require("node:os");
|
|
11
|
+
const process = require("vite-plugin-node-polyfills/shims/process");
|
|
12
|
+
const toml = require("@iarna/toml");
|
|
13
|
+
const globby = require("globby");
|
|
14
|
+
const JSON5 = require("json5");
|
|
15
|
+
const cliProgress = require("cli-progress");
|
|
16
|
+
const colors = require("ansi-colors");
|
|
17
|
+
const prompts = require("@inquirer/prompts");
|
|
18
|
+
function _interopNamespaceDefault(e) {
|
|
19
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
20
|
+
if (e) {
|
|
21
|
+
for (const k in e) {
|
|
22
|
+
if (k !== "default") {
|
|
23
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: () => e[k]
|
|
27
|
+
});
|
|
33
28
|
}
|
|
34
29
|
}
|
|
35
|
-
|
|
30
|
+
}
|
|
31
|
+
n.default = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
35
|
+
const yaml__namespace = /* @__PURE__ */ _interopNamespaceDefault(yaml);
|
|
36
|
+
const os__namespace = /* @__PURE__ */ _interopNamespaceDefault(os);
|
|
37
|
+
var Framework = /* @__PURE__ */ ((Framework2) => {
|
|
38
|
+
Framework2["TAURI"] = "TAURI";
|
|
39
|
+
Framework2["IONIC"] = "IONIC";
|
|
40
|
+
Framework2["FLUTTER"] = "FLUTTER";
|
|
41
|
+
return Framework2;
|
|
42
|
+
})(Framework || {});
|
|
43
|
+
function getWorkspaceDir(dir) {
|
|
44
|
+
var _a;
|
|
45
|
+
const rootPath = dir;
|
|
46
|
+
while (dir.length && dir[dir.length - 1] !== path.sep) {
|
|
47
|
+
const manifestPath = path.join(dir, "Cargo.toml");
|
|
48
|
+
if (fs.existsSync(manifestPath)) {
|
|
49
|
+
const toml$1 = toml.parse(fs.readFileSync(manifestPath).toString());
|
|
50
|
+
if ((_a = toml$1.workspace) == null ? void 0 : _a.members) {
|
|
51
|
+
const ignore = ["**/target", "**/node_modules"];
|
|
52
|
+
if (toml$1.workspace.exclude) ignore.push(...toml$1.workspace.exclude);
|
|
53
|
+
const memberPaths = globby.globbySync(toml$1.workspace.members, {
|
|
54
|
+
cwd: dir,
|
|
55
|
+
ignore,
|
|
56
|
+
expandDirectories: false,
|
|
57
|
+
onlyFiles: false
|
|
58
|
+
});
|
|
59
|
+
if (memberPaths.some((m) => path.resolve(dir, m) === rootPath)) {
|
|
60
|
+
return dir;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
dir = path.normalize(path.join(dir, ".."));
|
|
36
65
|
}
|
|
37
66
|
return null;
|
|
38
67
|
}
|
|
39
|
-
function
|
|
40
|
-
const
|
|
41
|
-
gitignore:
|
|
42
|
-
cwd:
|
|
68
|
+
function getTauriDir(root) {
|
|
69
|
+
const tauriConfPaths = globby.globbySync(["**/tauri.conf.json", "**/tauri.conf.json5", "**/Tauri.toml"], {
|
|
70
|
+
gitignore: true,
|
|
71
|
+
cwd: root,
|
|
43
72
|
// Forcefully ignore target and node_modules dirs
|
|
44
73
|
ignore: ["**/target", "**/node_modules"]
|
|
45
74
|
});
|
|
46
|
-
|
|
75
|
+
if (tauriConfPaths.length === 0) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return path.resolve(root, tauriConfPaths[0], "..");
|
|
47
79
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
80
|
+
function getCargoManifest(dir) {
|
|
81
|
+
var _a, _b, _c, _d;
|
|
82
|
+
const manifestPath = path.join(dir, "Cargo.toml");
|
|
83
|
+
const cargoManifest = toml.parse(fs.readFileSync(manifestPath).toString());
|
|
84
|
+
let name = cargoManifest.package.name;
|
|
85
|
+
let version = cargoManifest.package.version;
|
|
86
|
+
if (typeof cargoManifest.package.version == "object" || typeof cargoManifest.package.name == "object") {
|
|
87
|
+
const workspaceDir = getWorkspaceDir(dir);
|
|
88
|
+
if (!workspaceDir) {
|
|
54
89
|
throw new Error(
|
|
55
90
|
"Could not find workspace directory, but version and/or name specifies to use workspace package"
|
|
56
91
|
);
|
|
57
|
-
|
|
58
|
-
|
|
92
|
+
}
|
|
93
|
+
const manifestPath2 = path.join(workspaceDir, "Cargo.toml");
|
|
94
|
+
const workspaceManifest = toml.parse(fs.readFileSync(manifestPath2).toString());
|
|
95
|
+
if (typeof name === "object" && ((_b = (_a = workspaceManifest == null ? void 0 : workspaceManifest.workspace) == null ? void 0 : _a.package) == null ? void 0 : _b.name) !== void 0) {
|
|
96
|
+
name = workspaceManifest.workspace.package.name;
|
|
97
|
+
}
|
|
98
|
+
if (typeof version === "object" && ((_d = (_c = workspaceManifest == null ? void 0 : workspaceManifest.workspace) == null ? void 0 : _c.package) == null ? void 0 : _d.version) !== void 0) {
|
|
99
|
+
version = workspaceManifest.workspace.package.version;
|
|
100
|
+
}
|
|
59
101
|
}
|
|
60
102
|
return {
|
|
61
|
-
...
|
|
103
|
+
...cargoManifest,
|
|
62
104
|
package: {
|
|
63
|
-
...
|
|
64
|
-
name
|
|
65
|
-
version
|
|
105
|
+
...cargoManifest.package,
|
|
106
|
+
name,
|
|
107
|
+
version
|
|
66
108
|
}
|
|
67
109
|
};
|
|
68
110
|
}
|
|
69
|
-
function
|
|
111
|
+
function _tryParseJsonConfig(contents) {
|
|
70
112
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
113
|
+
const config = JSON.parse(contents);
|
|
114
|
+
return config;
|
|
115
|
+
} catch (e) {
|
|
116
|
+
const msg = e.message;
|
|
117
|
+
console.error(
|
|
118
|
+
`Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: "${msg}"`
|
|
119
|
+
);
|
|
120
|
+
return null;
|
|
77
121
|
}
|
|
78
122
|
}
|
|
79
|
-
function
|
|
123
|
+
function _tryParseJson5Config(contents) {
|
|
80
124
|
try {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
125
|
+
const config = JSON5.parse(contents);
|
|
126
|
+
return config;
|
|
127
|
+
} catch (e) {
|
|
128
|
+
const msg = e.message;
|
|
129
|
+
console.error(
|
|
130
|
+
`Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: "${msg}"`
|
|
131
|
+
);
|
|
132
|
+
return null;
|
|
87
133
|
}
|
|
88
134
|
}
|
|
89
|
-
function
|
|
135
|
+
function _tryParseTomlConfig(contents) {
|
|
90
136
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
const config = toml.parse(contents);
|
|
138
|
+
return config;
|
|
139
|
+
} catch (e) {
|
|
140
|
+
const msg = e.message;
|
|
141
|
+
console.error(
|
|
142
|
+
`Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: "${msg}"`
|
|
143
|
+
);
|
|
144
|
+
return null;
|
|
97
145
|
}
|
|
98
146
|
}
|
|
99
|
-
class
|
|
100
|
-
constructor(
|
|
101
|
-
this.identifier =
|
|
102
|
-
}
|
|
103
|
-
static fromBaseConfig(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
147
|
+
class TauriConfig {
|
|
148
|
+
constructor(identifier) {
|
|
149
|
+
this.identifier = identifier;
|
|
150
|
+
}
|
|
151
|
+
static fromBaseConfig(tauriDir) {
|
|
152
|
+
console.log(tauriDir);
|
|
153
|
+
if (fs.existsSync(path.join(tauriDir, "tauri.conf.json"))) {
|
|
154
|
+
const contents = fs.readFileSync(path.join(tauriDir, "tauri.conf.json")).toString();
|
|
155
|
+
const config = _tryParseJsonConfig(contents);
|
|
156
|
+
if (config) {
|
|
157
|
+
if ("identifier" in config) {
|
|
158
|
+
return this.fromV2Base(config);
|
|
159
|
+
} else {
|
|
160
|
+
return this.fromV1Base(config);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
108
163
|
console.error("Found tauri.conf.json file but couldn't parse it as JSON.");
|
|
109
164
|
}
|
|
110
|
-
if (
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
165
|
+
if (fs.existsSync(path.join(tauriDir, "tauri.conf.json5"))) {
|
|
166
|
+
const contents = fs.readFileSync(path.join(tauriDir, "tauri.conf.json5")).toString();
|
|
167
|
+
const config = _tryParseJson5Config(contents);
|
|
168
|
+
if (config) {
|
|
169
|
+
if ("identifier" in config) {
|
|
170
|
+
return this.fromV2Base(config);
|
|
171
|
+
} else {
|
|
172
|
+
return this.fromV1Base(config);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
114
175
|
console.error("Found tauri.conf.json5 file but couldn't parse it as JSON5.");
|
|
115
176
|
}
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
177
|
+
if (fs.existsSync(path.join(tauriDir, "Tauri.toml"))) {
|
|
178
|
+
const contents = fs.readFileSync(path.join(tauriDir, "Tauri.toml")).toString();
|
|
179
|
+
const config = _tryParseTomlConfig(contents);
|
|
180
|
+
if (config) {
|
|
181
|
+
if ("identifier" in config) {
|
|
182
|
+
return this.fromV2Base(config);
|
|
183
|
+
} else {
|
|
184
|
+
return this.fromV1Base(config);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
120
187
|
console.error("Found Tauri.toml file but couldn't parse it as TOML.");
|
|
121
188
|
}
|
|
122
189
|
throw new Error("Couldn't locate or parse tauri config.");
|
|
123
190
|
}
|
|
124
|
-
static fromV1Base(
|
|
125
|
-
|
|
191
|
+
static fromV1Base(config) {
|
|
192
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
193
|
+
if (!((_b = (_a = config.tauri) == null ? void 0 : _a.bundle) == null ? void 0 : _b.identifier)) {
|
|
126
194
|
throw Error("base config has no bundle identifier.");
|
|
127
|
-
|
|
128
|
-
|
|
195
|
+
}
|
|
196
|
+
const c = new TauriConfig((_d = (_c = config.tauri) == null ? void 0 : _c.bundle) == null ? void 0 : _d.identifier);
|
|
197
|
+
c.productName = (_e = config.package) == null ? void 0 : _e.productName;
|
|
198
|
+
c.version = (_f = config.package) == null ? void 0 : _f.version;
|
|
199
|
+
c.frontendDist = (_g = config.build) == null ? void 0 : _g.distDir;
|
|
200
|
+
c.beforeBuildCommand = (_h = config.build) == null ? void 0 : _h.beforeBuildCommand;
|
|
201
|
+
c.rpmRelease = (_i = config.tauri.bundle.rpm) == null ? void 0 : _i.release;
|
|
202
|
+
c.wixLanguage = (_k = (_j = config.tauri.bundle.windows) == null ? void 0 : _j.wix) == null ? void 0 : _k.language;
|
|
203
|
+
return c;
|
|
129
204
|
}
|
|
130
|
-
static fromV2Base(
|
|
131
|
-
|
|
205
|
+
static fromV2Base(config) {
|
|
206
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
207
|
+
if (!config.identifier) {
|
|
132
208
|
throw Error("base config has no bundle identifier.");
|
|
133
|
-
|
|
134
|
-
|
|
209
|
+
}
|
|
210
|
+
const c = new TauriConfig(config.identifier);
|
|
211
|
+
c.productName = config.productName;
|
|
212
|
+
c.version = config.version;
|
|
213
|
+
c.frontendDist = (_a = config.build) == null ? void 0 : _a.frontendDist;
|
|
214
|
+
c.beforeBuildCommand = (_b = config.build) == null ? void 0 : _b.beforeBuildCommand;
|
|
215
|
+
c.rpmRelease = (_e = (_d = (_c = config.bundle) == null ? void 0 : _c.linux) == null ? void 0 : _d.rpm) == null ? void 0 : _e.release;
|
|
216
|
+
c.wixLanguage = (_h = (_g = (_f = config.bundle) == null ? void 0 : _f.windows) == null ? void 0 : _g.wix) == null ? void 0 : _h.language;
|
|
217
|
+
return c;
|
|
135
218
|
}
|
|
136
219
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
const
|
|
149
|
-
|
|
220
|
+
const getTauriEnv = (projectPath) => {
|
|
221
|
+
var _a;
|
|
222
|
+
const tauriDir = getTauriDir(projectPath ?? ".");
|
|
223
|
+
if (tauriDir !== null) {
|
|
224
|
+
let name;
|
|
225
|
+
let version;
|
|
226
|
+
let wixLanguage = "en-US";
|
|
227
|
+
let rpmRelease = "1";
|
|
228
|
+
const config = TauriConfig.fromBaseConfig(tauriDir);
|
|
229
|
+
name = config == null ? void 0 : config.productName;
|
|
230
|
+
if ((_a = config.version) == null ? void 0 : _a.endsWith(".json")) {
|
|
231
|
+
const packageJsonPath = path.join(tauriDir, config == null ? void 0 : config.version);
|
|
232
|
+
const contents = fs.readFileSync(packageJsonPath).toString();
|
|
233
|
+
version = JSON.parse(contents).version;
|
|
234
|
+
} else {
|
|
235
|
+
version = config == null ? void 0 : config.version;
|
|
236
|
+
}
|
|
237
|
+
if (!(name && version)) {
|
|
238
|
+
const cargoManifest = getCargoManifest(tauriDir);
|
|
239
|
+
name = name ?? cargoManifest.package.name;
|
|
240
|
+
version = version ?? cargoManifest.package.version;
|
|
241
|
+
}
|
|
242
|
+
if (!(name && version)) {
|
|
243
|
+
console.error("Could not determine package name and version.");
|
|
244
|
+
process.exit(1);
|
|
245
|
+
}
|
|
246
|
+
const wixAppVersion = version.replace(/[-+]/g, ".");
|
|
247
|
+
if (config.wixLanguage) {
|
|
248
|
+
wixLanguage = config.wixLanguage;
|
|
249
|
+
}
|
|
250
|
+
if (config.rpmRelease) {
|
|
251
|
+
rpmRelease = config.rpmRelease;
|
|
150
252
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
wixAppVersion: s,
|
|
159
|
-
rpmRelease: a
|
|
253
|
+
return {
|
|
254
|
+
basePath: tauriDir + "/target",
|
|
255
|
+
appName: name,
|
|
256
|
+
version,
|
|
257
|
+
wixLanguage,
|
|
258
|
+
wixAppVersion,
|
|
259
|
+
rpmRelease
|
|
160
260
|
};
|
|
161
|
-
} else
|
|
261
|
+
} else {
|
|
162
262
|
throw Error("Couldn't detect Tauri dir");
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const getBranch = async () => new Promise((resolve) => {
|
|
266
|
+
return child_process.exec("git rev-parse --abbrev-ref HEAD", (err, stdout, stderr) => {
|
|
267
|
+
if (err) {
|
|
268
|
+
console.log(`getBranch Error: ${err}`);
|
|
269
|
+
} else if (stdout) {
|
|
270
|
+
resolve(stdout.trim());
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
resolve(void 0);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
function loadYamlWithEnv({
|
|
277
|
+
platform,
|
|
278
|
+
arch,
|
|
279
|
+
optionAccessKey
|
|
176
280
|
}) {
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
let
|
|
181
|
-
|
|
281
|
+
const configFilePath = path.join(".", "rop.yml");
|
|
282
|
+
const configData = fs.readFileSync(configFilePath, "utf8");
|
|
283
|
+
const config = yaml__namespace.load(configData);
|
|
284
|
+
let _arch;
|
|
285
|
+
if (arch == "x86_64") {
|
|
286
|
+
_arch = "x64";
|
|
287
|
+
} else if (arch) {
|
|
288
|
+
_arch = arch;
|
|
289
|
+
} else {
|
|
290
|
+
_arch = "x64";
|
|
291
|
+
}
|
|
292
|
+
let env = {
|
|
293
|
+
arch: _arch
|
|
182
294
|
};
|
|
183
|
-
if (!
|
|
295
|
+
if (!config.framework.name) {
|
|
184
296
|
throw new Error('Missing "framework.name" property in the configuration file.');
|
|
185
|
-
|
|
186
|
-
|
|
297
|
+
}
|
|
298
|
+
const _autoEnv = getAutoEnvByFramework(config.framework.name, config.projectPath);
|
|
299
|
+
if (!_autoEnv && !config.framework.env) {
|
|
187
300
|
throw new Error(
|
|
188
|
-
`The [${
|
|
301
|
+
`The [${config.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
|
|
189
302
|
);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
...
|
|
193
|
-
...
|
|
194
|
-
|
|
303
|
+
}
|
|
304
|
+
env = {
|
|
305
|
+
...env,
|
|
306
|
+
..._autoEnv,
|
|
307
|
+
...config.framework.env ?? {}
|
|
308
|
+
};
|
|
309
|
+
if (!env.appName) {
|
|
195
310
|
throw new Error('Missing "appName" property in the configuration file.');
|
|
196
|
-
|
|
311
|
+
}
|
|
312
|
+
if (!env.version) {
|
|
197
313
|
throw new Error('Missing "version" property in the configuration file.');
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
314
|
+
}
|
|
315
|
+
function replaceEnvInObject(obj) {
|
|
316
|
+
Object.keys(obj).forEach((key) => {
|
|
317
|
+
if (typeof obj[key] === "string") {
|
|
318
|
+
obj[key] = obj[key].replace(/\$\{(\w+)\}/g, (_, envVar) => env[envVar] || "");
|
|
319
|
+
} else if (typeof obj[key] === "object" && obj[key] !== null) {
|
|
320
|
+
replaceEnvInObject(obj[key]);
|
|
321
|
+
}
|
|
201
322
|
});
|
|
202
323
|
}
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
console.log("find target file:")
|
|
206
|
-
|
|
207
|
-
|
|
324
|
+
replaceEnvInObject(config);
|
|
325
|
+
const targetInfo = config.platforms[platform][_arch];
|
|
326
|
+
console.log("find target file:");
|
|
327
|
+
console.log(targetInfo);
|
|
328
|
+
const accessKey = getAccessKey(optionAccessKey, config.access);
|
|
329
|
+
return { config, targetInfo, accessKey, version: env.version };
|
|
208
330
|
}
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
211
|
-
return
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
331
|
+
const getAccessKey = (accessKey, access) => {
|
|
332
|
+
if (accessKey) {
|
|
333
|
+
return accessKey;
|
|
334
|
+
}
|
|
335
|
+
if (access == null ? void 0 : access.key) {
|
|
336
|
+
return access == null ? void 0 : access.key;
|
|
337
|
+
}
|
|
338
|
+
if (access == null ? void 0 : access.name) {
|
|
339
|
+
const configData = fs.readFileSync(`${os__namespace.homedir()}/.rop/config`, "utf8");
|
|
340
|
+
const regex = `\\[${access.name}]\\n(.+)`;
|
|
341
|
+
const match = new RegExp(regex).exec(configData);
|
|
342
|
+
if (match) {
|
|
343
|
+
return match[1];
|
|
344
|
+
}
|
|
218
345
|
}
|
|
219
346
|
throw new Error("missing access-key");
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
347
|
+
};
|
|
348
|
+
const getAutoEnvByFramework = (framework, projectPath) => {
|
|
349
|
+
switch (framework.toLowerCase()) {
|
|
350
|
+
case Framework.TAURI.toLowerCase():
|
|
351
|
+
return getTauriEnv(projectPath);
|
|
224
352
|
default:
|
|
225
|
-
return;
|
|
353
|
+
return void 0;
|
|
226
354
|
}
|
|
227
355
|
};
|
|
228
|
-
class
|
|
229
|
-
constructor({ baseDomain
|
|
230
|
-
this.checkParams = async (
|
|
231
|
-
if (!
|
|
356
|
+
class RopUpload {
|
|
357
|
+
constructor({ baseDomain }) {
|
|
358
|
+
this.checkParams = async (config) => {
|
|
359
|
+
if (!config.accessKey) {
|
|
232
360
|
throw new Error("accessKey not null");
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
else
|
|
361
|
+
}
|
|
362
|
+
const branch = config.branch ?? await getBranch();
|
|
363
|
+
if (!branch) {
|
|
237
364
|
throw new Error("branch not null");
|
|
238
|
-
|
|
365
|
+
} else {
|
|
366
|
+
config.branch = branch;
|
|
367
|
+
}
|
|
368
|
+
if (!config.platform) {
|
|
239
369
|
throw new Error("platform not null");
|
|
240
|
-
|
|
370
|
+
}
|
|
371
|
+
if (!config.arch) {
|
|
241
372
|
throw new Error("arch not null");
|
|
242
|
-
|
|
373
|
+
}
|
|
374
|
+
if (!config.targetPath) {
|
|
243
375
|
throw new Error("target path not null");
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (!
|
|
376
|
+
}
|
|
377
|
+
if (!fs.existsSync(config.targetPath)) {
|
|
378
|
+
throw new Error(`target file not found, file path: ${config.targetPath}`);
|
|
379
|
+
}
|
|
380
|
+
if (config.updatePath && !fs.existsSync(config.updatePath)) {
|
|
381
|
+
throw new Error(`update file not found, file path: ${config.updatePath}`);
|
|
382
|
+
}
|
|
383
|
+
if (!config.version) {
|
|
249
384
|
throw new Error("version not null");
|
|
250
|
-
|
|
251
|
-
|
|
385
|
+
}
|
|
386
|
+
return config;
|
|
387
|
+
};
|
|
388
|
+
this.baseDomain = baseDomain;
|
|
252
389
|
}
|
|
253
|
-
async upload(
|
|
254
|
-
const
|
|
255
|
-
|
|
390
|
+
async upload(_config) {
|
|
391
|
+
const config = await this.checkParams(_config);
|
|
392
|
+
const formData = new FormData();
|
|
393
|
+
const fileStream = fs.createReadStream(config.targetPath);
|
|
394
|
+
const multibar = new cliProgress.MultiBar({
|
|
395
|
+
format: "Upload Progress |" + colors.cyan("{bar}") + "| {percentage}% | {filename}",
|
|
256
396
|
barCompleteChar: "█",
|
|
257
397
|
barIncompleteChar: "░",
|
|
258
|
-
hideCursor:
|
|
259
|
-
}), i = a.create(c.statSync(e.targetPath).size, 0);
|
|
260
|
-
let s = 0;
|
|
261
|
-
o.on("data", (y) => {
|
|
262
|
-
s += y.length, i.update(s, { filename: p.basename(e.targetPath) });
|
|
263
|
-
}), r.append("targetFile", o, {
|
|
264
|
-
filename: e.targetName ?? p.basename(e.targetPath)
|
|
398
|
+
hideCursor: true
|
|
265
399
|
});
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
400
|
+
const bar1 = multibar.create(fs.statSync(config.targetPath).size, 0);
|
|
401
|
+
let totalUploaded = 0;
|
|
402
|
+
fileStream.on("data", (chunk) => {
|
|
403
|
+
totalUploaded += chunk.length;
|
|
404
|
+
bar1.update(totalUploaded, { filename: path.basename(config.targetPath) });
|
|
405
|
+
});
|
|
406
|
+
formData.append("targetFile", fileStream, {
|
|
407
|
+
filename: config.targetName ?? path.basename(config.targetPath)
|
|
408
|
+
});
|
|
409
|
+
let updateFileStream;
|
|
410
|
+
if (config.updatePath) {
|
|
411
|
+
const bar2 = multibar.create(fs.statSync(config.updatePath).size, 0);
|
|
412
|
+
updateFileStream = fs.createReadStream(config.updatePath);
|
|
413
|
+
let totalUpdateUploaded = 0;
|
|
414
|
+
updateFileStream.on("data", (chunk) => {
|
|
415
|
+
totalUpdateUploaded += chunk.length;
|
|
416
|
+
bar2.update(totalUpdateUploaded, { filename: path.basename(config.updatePath) });
|
|
275
417
|
});
|
|
418
|
+
formData.append("updateFile", updateFileStream, {
|
|
419
|
+
filename: config.updateName ?? path.basename(config.updatePath)
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
formData.append("accessKey", config.accessKey);
|
|
423
|
+
formData.append("branch", config.branch);
|
|
424
|
+
formData.append("version", config.version);
|
|
425
|
+
formData.append("platform", config.platform);
|
|
426
|
+
formData.append("arch", config.arch);
|
|
427
|
+
if (config.signature) {
|
|
428
|
+
formData.append("signature", config.signature);
|
|
276
429
|
}
|
|
277
|
-
|
|
278
|
-
const f = await D(`${this.baseDomain}/api/upload`, {
|
|
430
|
+
const res = await fetch(`${this.baseDomain}/api/upload`, {
|
|
279
431
|
method: "POST",
|
|
280
|
-
headers:
|
|
281
|
-
body:
|
|
282
|
-
})
|
|
283
|
-
|
|
432
|
+
headers: formData.getHeaders(),
|
|
433
|
+
body: formData
|
|
434
|
+
});
|
|
435
|
+
const body = await res.json();
|
|
436
|
+
if (!res.ok) {
|
|
437
|
+
console.log(res.status, res.statusText, body);
|
|
438
|
+
}
|
|
439
|
+
multibar.stop();
|
|
440
|
+
fileStream.destroy();
|
|
441
|
+
updateFileStream == null ? void 0 : updateFileStream.destroy();
|
|
442
|
+
return { success: res.ok, body };
|
|
284
443
|
}
|
|
285
444
|
}
|
|
286
|
-
class
|
|
287
|
-
async initYaml(
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
445
|
+
class Init {
|
|
446
|
+
async initYaml(accessKey) {
|
|
447
|
+
const __dirname = path.resolve();
|
|
448
|
+
const projectName = path.basename(__dirname);
|
|
449
|
+
const ymlConfigPath = path.join(".", "rop.yml");
|
|
450
|
+
let ymlConfigJson = {};
|
|
451
|
+
if (fs.existsSync(ymlConfigPath)) {
|
|
452
|
+
let flag = false;
|
|
292
453
|
try {
|
|
293
|
-
|
|
294
|
-
message: `${
|
|
454
|
+
flag = await prompts.confirm({
|
|
455
|
+
message: `${colors.cyan("rop.yml")} already exists, does it need to be overwritten?`
|
|
295
456
|
});
|
|
296
|
-
} catch {
|
|
297
|
-
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.log("cancel");
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
if (!flag) {
|
|
462
|
+
console.log("cancel");
|
|
463
|
+
return false;
|
|
298
464
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const l = c.readFileSync(o, "utf8");
|
|
302
|
-
a = P.load(l);
|
|
465
|
+
const ymlContent = fs.readFileSync(ymlConfigPath, "utf8");
|
|
466
|
+
ymlConfigJson = yaml__namespace.load(ymlContent);
|
|
303
467
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
468
|
+
if (!ymlConfigJson.access) {
|
|
469
|
+
ymlConfigJson.access = {
|
|
470
|
+
name: projectName
|
|
471
|
+
};
|
|
472
|
+
} else {
|
|
473
|
+
ymlConfigJson.access.name = projectName;
|
|
474
|
+
}
|
|
475
|
+
const yamlData = yaml__namespace.dump(ymlConfigJson, {
|
|
308
476
|
lineWidth: 500
|
|
309
477
|
});
|
|
310
|
-
|
|
478
|
+
fs.writeFileSync(ymlConfigPath, yamlData, "utf8");
|
|
479
|
+
return true;
|
|
311
480
|
}
|
|
312
|
-
async initRopConfig(
|
|
313
|
-
const
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
481
|
+
async initRopConfig(accessKey) {
|
|
482
|
+
const ropConfigDirPath = path.join(".", ".rop");
|
|
483
|
+
if (!fs.existsSync(ropConfigDirPath)) {
|
|
484
|
+
fs.mkdirSync(ropConfigDirPath);
|
|
485
|
+
}
|
|
486
|
+
const ropConfigPath = path.join(ropConfigDirPath, "config.json");
|
|
487
|
+
let ropConfigData = {};
|
|
488
|
+
if (fs.existsSync(ropConfigPath)) {
|
|
489
|
+
ropConfigData = JSON.parse(fs.readFileSync(ropConfigPath, "utf8"));
|
|
490
|
+
}
|
|
491
|
+
ropConfigData.accessKey = accessKey;
|
|
492
|
+
fs.writeFileSync(ropConfigPath, JSON.stringify(ropConfigData, null, 2), "utf8");
|
|
318
493
|
}
|
|
319
494
|
async initGitignore() {
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
495
|
+
const gitignorePath = path.join(".", ".gitignore");
|
|
496
|
+
if (fs.existsSync(gitignorePath)) {
|
|
497
|
+
const gitignoreData = fs.readFileSync(gitignorePath, "utf8");
|
|
498
|
+
if (!gitignoreData.includes(".rop")) {
|
|
499
|
+
fs.appendFileSync(gitignorePath, `
|
|
500
|
+
.rop`, "utf8");
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
fs.writeFileSync(gitignorePath, `.rop`, "utf8");
|
|
504
|
+
}
|
|
323
505
|
}
|
|
324
506
|
}
|
|
325
|
-
const
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
let
|
|
329
|
-
|
|
507
|
+
const program = new commander.Command();
|
|
508
|
+
program.name("rop").description("CLI to some JavaScript string utilities").version("0.1.0");
|
|
509
|
+
program.command("init").description("init rop").action(async () => {
|
|
510
|
+
let accessKey = "";
|
|
511
|
+
while (!accessKey) {
|
|
330
512
|
try {
|
|
331
|
-
|
|
332
|
-
} catch {
|
|
513
|
+
accessKey = await prompts.input({ message: `Please enter ${colors.cyan("access-key")}` });
|
|
514
|
+
} catch (error) {
|
|
333
515
|
console.log("cancel");
|
|
334
516
|
return;
|
|
335
517
|
}
|
|
336
|
-
|
|
337
|
-
|
|
518
|
+
}
|
|
519
|
+
const init = new Init();
|
|
520
|
+
if (await init.initYaml(accessKey)) {
|
|
521
|
+
await init.initRopConfig(accessKey);
|
|
522
|
+
await init.initGitignore();
|
|
523
|
+
console.log("done");
|
|
524
|
+
}
|
|
338
525
|
});
|
|
339
|
-
|
|
526
|
+
program.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (projectAccessKey) => {
|
|
340
527
|
try {
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
528
|
+
const array = projectAccessKey.split("=");
|
|
529
|
+
if (array.length != 2) {
|
|
343
530
|
throw new Error("parameter format error");
|
|
344
|
-
const [e, r] = t, a = `${E.homedir()}/.rop`;
|
|
345
|
-
h.existsSync(a) || h.mkdirSync(a);
|
|
346
|
-
const i = `${a}/config`, s = `[${e}]
|
|
347
|
-
${r}`;
|
|
348
|
-
if (!h.existsSync(i))
|
|
349
|
-
h.writeFileSync(i, s);
|
|
350
|
-
else {
|
|
351
|
-
const l = h.readFileSync(i, "utf8"), f = `\\[${e}]\\n(.+)`, g = new RegExp(f).exec(l);
|
|
352
|
-
g ? h.writeFileSync(i, l.replace(g[0], s)) : h.appendFileSync(i, `
|
|
353
|
-
` + s);
|
|
354
531
|
}
|
|
355
|
-
|
|
356
|
-
|
|
532
|
+
const [projectName, accessKey] = array;
|
|
533
|
+
const homeDirectory = os__namespace.homedir();
|
|
534
|
+
const homedir = `${homeDirectory}/.rop`;
|
|
535
|
+
if (!fs__namespace.existsSync(homedir)) {
|
|
536
|
+
fs__namespace.mkdirSync(homedir);
|
|
537
|
+
}
|
|
538
|
+
const filePath = `${homedir}/config`;
|
|
539
|
+
const content = `[${projectName}]
|
|
540
|
+
${accessKey}`;
|
|
541
|
+
if (!fs__namespace.existsSync(filePath)) {
|
|
542
|
+
fs__namespace.writeFileSync(filePath, content);
|
|
543
|
+
} else {
|
|
544
|
+
const configData = fs__namespace.readFileSync(filePath, "utf8");
|
|
545
|
+
const regex = `\\[${projectName}]\\n(.+)`;
|
|
546
|
+
const match = new RegExp(regex).exec(configData);
|
|
547
|
+
if (match) {
|
|
548
|
+
fs__namespace.writeFileSync(filePath, configData.replace(match[0], content));
|
|
549
|
+
} else {
|
|
550
|
+
fs__namespace.appendFileSync(filePath, "\n" + content);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
} catch (error) {
|
|
554
|
+
console.error("Error reading configuration file or missing required properties:", error);
|
|
357
555
|
}
|
|
358
556
|
});
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
557
|
+
program.command("upload").description("Upload some framework build").argument("<string>", "platform").argument("[string]", "arch").option("-a, --accessKey <string>", "accessKey path").action(async (platform, arch, options) => {
|
|
558
|
+
var _a, _b, _c, _d;
|
|
559
|
+
const { config, targetInfo, accessKey, version } = loadYamlWithEnv({
|
|
560
|
+
platform,
|
|
561
|
+
arch,
|
|
562
|
+
optionAccessKey: options.accessKey
|
|
364
563
|
});
|
|
365
|
-
if (!
|
|
564
|
+
if (!config.host) {
|
|
366
565
|
throw new Error('Missing "host" property in the configuration file.');
|
|
367
|
-
|
|
566
|
+
}
|
|
567
|
+
if (!targetInfo) {
|
|
368
568
|
throw new Error('Missing "targetInfo" property in the configuration file.');
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
569
|
+
}
|
|
570
|
+
const uploadClient = new RopUpload({ baseDomain: config.host });
|
|
571
|
+
await uploadClient.upload({
|
|
572
|
+
accessKey,
|
|
573
|
+
arch,
|
|
574
|
+
platform,
|
|
575
|
+
version,
|
|
576
|
+
targetPath: targetInfo.target.path,
|
|
577
|
+
targetName: (_a = targetInfo.target) == null ? void 0 : _a.name,
|
|
578
|
+
updatePath: (_b = targetInfo.update) == null ? void 0 : _b.path,
|
|
579
|
+
updateName: (_c = targetInfo.update) == null ? void 0 : _c.name,
|
|
580
|
+
signature: ((_d = targetInfo.sig) == null ? void 0 : _d.path) ? fs__namespace.readFileSync(targetInfo.sig.path, "utf8") : void 0
|
|
379
581
|
});
|
|
380
582
|
});
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
Y as getTauriEnv
|
|
385
|
-
};
|
|
583
|
+
program.parse();
|
|
584
|
+
exports.RopUpload = RopUpload;
|
|
585
|
+
exports.getTauriEnv = getTauriEnv;
|