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