@sevenvip666/rop 0.0.3 → 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/index.d.ts +44 -0
- package/dist/rop.js +585 -0
- package/package.json +8 -11
- package/dist/398.index.js +0 -450
- package/dist/api-types/src/index.d.ts +0 -201
- package/dist/api-types/src/index.d.ts.map +0 -1
- package/dist/index.js +0 -34739
- package/dist/package.json +0 -3
- package/dist/upload/lib/init.d.ts +0 -6
- package/dist/upload/lib/init.d.ts.map +0 -1
- package/dist/upload/lib/rop.d.ts +0 -2
- package/dist/upload/lib/rop.d.ts.map +0 -1
- package/dist/upload/lib/tauri/artifacts.d.ts +0 -3
- package/dist/upload/lib/tauri/artifacts.d.ts.map +0 -1
- package/dist/upload/lib/tauri/config.d.ts +0 -22
- package/dist/upload/lib/tauri/config.d.ts.map +0 -1
- package/dist/upload/lib/tauri/index.d.ts +0 -20
- package/dist/upload/lib/tauri/index.d.ts.map +0 -1
- package/dist/upload/lib/tauri/utils.d.ts +0 -9
- package/dist/upload/lib/tauri/utils.d.ts.map +0 -1
- package/dist/upload/lib/tauri.d.ts +0 -11
- package/dist/upload/lib/tauri.d.ts.map +0 -1
- package/dist/upload/lib/types.d.ts +0 -18
- package/dist/upload/lib/types.d.ts.map +0 -1
- package/dist/upload/lib/upload.d.ts +0 -14
- package/dist/upload/lib/upload.d.ts.map +0 -1
- package/dist/upload/lib/utils.d.ts +0 -151
- package/dist/upload/lib/utils.d.ts.map +0 -1
- package/dist/upload/src/main.d.ts +0 -2
- package/dist/upload/src/main.d.ts.map +0 -1
- package/dist/upload/test/upload.spec.d.ts +0 -2
- package/dist/upload/test/upload.spec.d.ts.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare type Arch = 'aarch64' | 'x86_64' | 'x64' | 'i686' | string;
|
|
2
|
+
|
|
3
|
+
export declare const getTauriEnv: (projectPath?: string) => {
|
|
4
|
+
basePath: string;
|
|
5
|
+
appName: string;
|
|
6
|
+
version: string;
|
|
7
|
+
wixLanguage: string | string[] | {
|
|
8
|
+
[language: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
wixAppVersion: string;
|
|
11
|
+
rpmRelease: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
declare type Platform = 'android' | 'ios' | 'windows' | 'macos' | 'linux' | 'h5';
|
|
15
|
+
|
|
16
|
+
export declare class RopUpload {
|
|
17
|
+
baseDomain: string;
|
|
18
|
+
constructor({ baseDomain }: {
|
|
19
|
+
baseDomain: string;
|
|
20
|
+
});
|
|
21
|
+
upload(_config: UploadType): Promise<{
|
|
22
|
+
success: boolean;
|
|
23
|
+
body: unknown;
|
|
24
|
+
}>;
|
|
25
|
+
private checkParams;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare interface UploadDto {
|
|
29
|
+
platform: Platform;
|
|
30
|
+
accessKey: string;
|
|
31
|
+
branch?: string;
|
|
32
|
+
version?: string;
|
|
33
|
+
arch: Arch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare type UploadType = UploadDto & {
|
|
37
|
+
targetPath: string;
|
|
38
|
+
targetName?: string;
|
|
39
|
+
updatePath?: string;
|
|
40
|
+
updateName?: string;
|
|
41
|
+
signature?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export { }
|
package/dist/rop.js
ADDED
|
@@ -0,0 +1,585 @@
|
|
|
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
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
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, ".."));
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
function getTauriDir(root) {
|
|
69
|
+
const tauriConfPaths = globby.globbySync(["**/tauri.conf.json", "**/tauri.conf.json5", "**/Tauri.toml"], {
|
|
70
|
+
gitignore: true,
|
|
71
|
+
cwd: root,
|
|
72
|
+
// Forcefully ignore target and node_modules dirs
|
|
73
|
+
ignore: ["**/target", "**/node_modules"]
|
|
74
|
+
});
|
|
75
|
+
if (tauriConfPaths.length === 0) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return path.resolve(root, tauriConfPaths[0], "..");
|
|
79
|
+
}
|
|
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) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
"Could not find workspace directory, but version and/or name specifies to use workspace package"
|
|
91
|
+
);
|
|
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
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
...cargoManifest,
|
|
104
|
+
package: {
|
|
105
|
+
...cargoManifest.package,
|
|
106
|
+
name,
|
|
107
|
+
version
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function _tryParseJsonConfig(contents) {
|
|
112
|
+
try {
|
|
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;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function _tryParseJson5Config(contents) {
|
|
124
|
+
try {
|
|
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;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function _tryParseTomlConfig(contents) {
|
|
136
|
+
try {
|
|
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;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
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
|
+
}
|
|
163
|
+
console.error("Found tauri.conf.json file but couldn't parse it as JSON.");
|
|
164
|
+
}
|
|
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
|
+
}
|
|
175
|
+
console.error("Found tauri.conf.json5 file but couldn't parse it as JSON5.");
|
|
176
|
+
}
|
|
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
|
+
}
|
|
187
|
+
console.error("Found Tauri.toml file but couldn't parse it as TOML.");
|
|
188
|
+
}
|
|
189
|
+
throw new Error("Couldn't locate or parse tauri config.");
|
|
190
|
+
}
|
|
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)) {
|
|
194
|
+
throw Error("base config has no bundle identifier.");
|
|
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;
|
|
204
|
+
}
|
|
205
|
+
static fromV2Base(config) {
|
|
206
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
207
|
+
if (!config.identifier) {
|
|
208
|
+
throw Error("base config has no bundle identifier.");
|
|
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;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
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;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
basePath: tauriDir + "/target",
|
|
255
|
+
appName: name,
|
|
256
|
+
version,
|
|
257
|
+
wixLanguage,
|
|
258
|
+
wixAppVersion,
|
|
259
|
+
rpmRelease
|
|
260
|
+
};
|
|
261
|
+
} else {
|
|
262
|
+
throw Error("Couldn't detect Tauri dir");
|
|
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
|
|
280
|
+
}) {
|
|
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
|
|
294
|
+
};
|
|
295
|
+
if (!config.framework.name) {
|
|
296
|
+
throw new Error('Missing "framework.name" property in the configuration file.');
|
|
297
|
+
}
|
|
298
|
+
const _autoEnv = getAutoEnvByFramework(config.framework.name, config.projectPath);
|
|
299
|
+
if (!_autoEnv && !config.framework.env) {
|
|
300
|
+
throw new Error(
|
|
301
|
+
`The [${config.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
env = {
|
|
305
|
+
...env,
|
|
306
|
+
..._autoEnv,
|
|
307
|
+
...config.framework.env ?? {}
|
|
308
|
+
};
|
|
309
|
+
if (!env.appName) {
|
|
310
|
+
throw new Error('Missing "appName" property in the configuration file.');
|
|
311
|
+
}
|
|
312
|
+
if (!env.version) {
|
|
313
|
+
throw new Error('Missing "version" property in the configuration file.');
|
|
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
|
+
}
|
|
322
|
+
});
|
|
323
|
+
}
|
|
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 };
|
|
330
|
+
}
|
|
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
|
+
}
|
|
345
|
+
}
|
|
346
|
+
throw new Error("missing access-key");
|
|
347
|
+
};
|
|
348
|
+
const getAutoEnvByFramework = (framework, projectPath) => {
|
|
349
|
+
switch (framework.toLowerCase()) {
|
|
350
|
+
case Framework.TAURI.toLowerCase():
|
|
351
|
+
return getTauriEnv(projectPath);
|
|
352
|
+
default:
|
|
353
|
+
return void 0;
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
class RopUpload {
|
|
357
|
+
constructor({ baseDomain }) {
|
|
358
|
+
this.checkParams = async (config) => {
|
|
359
|
+
if (!config.accessKey) {
|
|
360
|
+
throw new Error("accessKey not null");
|
|
361
|
+
}
|
|
362
|
+
const branch = config.branch ?? await getBranch();
|
|
363
|
+
if (!branch) {
|
|
364
|
+
throw new Error("branch not null");
|
|
365
|
+
} else {
|
|
366
|
+
config.branch = branch;
|
|
367
|
+
}
|
|
368
|
+
if (!config.platform) {
|
|
369
|
+
throw new Error("platform not null");
|
|
370
|
+
}
|
|
371
|
+
if (!config.arch) {
|
|
372
|
+
throw new Error("arch not null");
|
|
373
|
+
}
|
|
374
|
+
if (!config.targetPath) {
|
|
375
|
+
throw new Error("target path not null");
|
|
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) {
|
|
384
|
+
throw new Error("version not null");
|
|
385
|
+
}
|
|
386
|
+
return config;
|
|
387
|
+
};
|
|
388
|
+
this.baseDomain = baseDomain;
|
|
389
|
+
}
|
|
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}",
|
|
396
|
+
barCompleteChar: "█",
|
|
397
|
+
barIncompleteChar: "░",
|
|
398
|
+
hideCursor: true
|
|
399
|
+
});
|
|
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) });
|
|
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);
|
|
429
|
+
}
|
|
430
|
+
const res = await fetch(`${this.baseDomain}/api/upload`, {
|
|
431
|
+
method: "POST",
|
|
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 };
|
|
443
|
+
}
|
|
444
|
+
}
|
|
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;
|
|
453
|
+
try {
|
|
454
|
+
flag = await prompts.confirm({
|
|
455
|
+
message: `${colors.cyan("rop.yml")} already exists, does it need to be overwritten?`
|
|
456
|
+
});
|
|
457
|
+
} catch (error) {
|
|
458
|
+
console.log("cancel");
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
if (!flag) {
|
|
462
|
+
console.log("cancel");
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
const ymlContent = fs.readFileSync(ymlConfigPath, "utf8");
|
|
466
|
+
ymlConfigJson = yaml__namespace.load(ymlContent);
|
|
467
|
+
}
|
|
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, {
|
|
476
|
+
lineWidth: 500
|
|
477
|
+
});
|
|
478
|
+
fs.writeFileSync(ymlConfigPath, yamlData, "utf8");
|
|
479
|
+
return true;
|
|
480
|
+
}
|
|
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");
|
|
493
|
+
}
|
|
494
|
+
async initGitignore() {
|
|
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
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
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) {
|
|
512
|
+
try {
|
|
513
|
+
accessKey = await prompts.input({ message: `Please enter ${colors.cyan("access-key")}` });
|
|
514
|
+
} catch (error) {
|
|
515
|
+
console.log("cancel");
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
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
|
+
}
|
|
525
|
+
});
|
|
526
|
+
program.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (projectAccessKey) => {
|
|
527
|
+
try {
|
|
528
|
+
const array = projectAccessKey.split("=");
|
|
529
|
+
if (array.length != 2) {
|
|
530
|
+
throw new Error("parameter format error");
|
|
531
|
+
}
|
|
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);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
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
|
|
563
|
+
});
|
|
564
|
+
if (!config.host) {
|
|
565
|
+
throw new Error('Missing "host" property in the configuration file.');
|
|
566
|
+
}
|
|
567
|
+
if (!targetInfo) {
|
|
568
|
+
throw new Error('Missing "targetInfo" property in the configuration file.');
|
|
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
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
program.parse();
|
|
584
|
+
exports.RopUpload = RopUpload;
|
|
585
|
+
exports.getTauriEnv = getTauriEnv;
|
package/package.json
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sevenvip666/rop",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
7
7
|
"index.d.ts"
|
|
8
8
|
],
|
|
9
9
|
"bin": {
|
|
10
|
-
"rop": "dist/
|
|
10
|
+
"rop": "dist/rop.js"
|
|
11
11
|
},
|
|
12
|
-
"main": "dist/
|
|
13
|
-
"module": "dist/
|
|
12
|
+
"main": "dist/rop.js",
|
|
13
|
+
"module": "dist/rop.js",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
15
|
"exports": {
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"import": "./dist/
|
|
17
|
+
"import": "./dist/rop.js"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
|
-
"
|
|
21
|
-
"build2": "tsc --p ./tsconfig-build.json && vite build",
|
|
22
|
-
"build": "ncc build lib/rop.ts -o dist"
|
|
20
|
+
"build": "vite build"
|
|
23
21
|
},
|
|
24
22
|
"dependencies": {
|
|
25
23
|
"@iarna/toml": "^2.2.5",
|
|
26
24
|
"@inquirer/prompts": "^5.3.5",
|
|
27
|
-
"@vercel/ncc": "^0.38.1",
|
|
28
25
|
"ansi-colors": "^4.1.3",
|
|
29
26
|
"cli-progress": "^3.12.0",
|
|
30
27
|
"commander": "^12.1.0",
|
|
@@ -32,7 +29,8 @@
|
|
|
32
29
|
"globby": "^14.0.2",
|
|
33
30
|
"js-yaml": "^4.1.0",
|
|
34
31
|
"json5": "^2.2.3",
|
|
35
|
-
"node-fetch": "^3.3.2"
|
|
32
|
+
"node-fetch": "^3.3.2",
|
|
33
|
+
"vite-plugin-node-polyfills": "^0.22.0"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@repo/api-types": "workspace:*",
|
|
@@ -43,7 +41,6 @@
|
|
|
43
41
|
"typescript": "^5.4.5",
|
|
44
42
|
"vite": "^5.2.10",
|
|
45
43
|
"vite-plugin-dts": "^3.9.1",
|
|
46
|
-
"vite-plugin-node-polyfills": "^0.22.0",
|
|
47
44
|
"vitest": "^2.0.2"
|
|
48
45
|
}
|
|
49
46
|
}
|