@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.
Files changed (2) hide show
  1. package/dist/rop.js +486 -286
  2. package/package.json +1 -1
package/dist/rop.js CHANGED
@@ -1,385 +1,585 @@
1
- import { Command as T } from "commander";
2
- import * as h from "node:fs";
3
- import c, { readFileSync as w, existsSync as S } from "node:fs";
4
- import D from "node-fetch";
5
- import B from "form-data";
6
- import { exec as $ } from "child_process";
7
- import p, { resolve as x, join as m, sep as R, normalize as O } from "node:path";
8
- import * as P from "js-yaml";
9
- import * as E from "node:os";
10
- import J from "vite-plugin-node-polyfills/shims/process";
11
- import { parse as v } from "@iarna/toml";
12
- import { globbySync as N } from "globby";
13
- import K from "json5";
14
- import I from "cli-progress";
15
- import C from "ansi-colors";
16
- import { confirm as U, input as L } from "@inquirer/prompts";
17
- var F = /* @__PURE__ */ ((n) => (n.TAURI = "TAURI", n.IONIC = "IONIC", n.FLUTTER = "FLUTTER", n))(F || {});
18
- function M(n) {
19
- const t = n;
20
- for (; n.length && n[n.length - 1] !== R; ) {
21
- const e = m(n, "Cargo.toml");
22
- if (S(e)) {
23
- const r = v(w(e).toString());
24
- if (r.workspace?.members) {
25
- const o = ["**/target", "**/node_modules"];
26
- if (r.workspace.exclude && o.push(...r.workspace.exclude), N(r.workspace.members, {
27
- cwd: n,
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
- n = O(m(n, ".."));
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 _(n) {
40
- const t = N(["**/tauri.conf.json", "**/tauri.conf.json5", "**/Tauri.toml"], {
41
- gitignore: !0,
42
- cwd: n,
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
- return t.length === 0 ? null : x(n, t[0], "..");
75
+ if (tauriConfPaths.length === 0) {
76
+ return null;
77
+ }
78
+ return path.resolve(root, tauriConfPaths[0], "..");
47
79
  }
48
- function A(n) {
49
- const t = m(n, "Cargo.toml"), e = v(w(t).toString());
50
- let r = e.package.name, o = e.package.version;
51
- if (typeof e.package.version == "object" || typeof e.package.name == "object") {
52
- const a = M(n);
53
- if (!a)
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
- const i = m(a, "Cargo.toml"), s = v(w(i).toString());
58
- typeof r == "object" && s?.workspace?.package?.name !== void 0 && (r = s.workspace.package.name), typeof o == "object" && s?.workspace?.package?.version !== void 0 && (o = s.workspace.package.version);
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
- ...e,
103
+ ...cargoManifest,
62
104
  package: {
63
- ...e.package,
64
- name: r,
65
- version: o
105
+ ...cargoManifest.package,
106
+ name,
107
+ version
66
108
  }
67
109
  };
68
110
  }
69
- function V(n) {
111
+ function _tryParseJsonConfig(contents) {
70
112
  try {
71
- return JSON.parse(n);
72
- } catch (t) {
73
- const e = t.message;
74
- return console.error(
75
- `Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: "${e}"`
76
- ), null;
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 W(n) {
123
+ function _tryParseJson5Config(contents) {
80
124
  try {
81
- return K.parse(n);
82
- } catch (t) {
83
- const e = t.message;
84
- return console.error(
85
- `Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: "${e}"`
86
- ), null;
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 z(n) {
135
+ function _tryParseTomlConfig(contents) {
90
136
  try {
91
- return v(n);
92
- } catch (t) {
93
- const e = t.message;
94
- return console.error(
95
- `Couldn't parse --config flag as inline JSON. This is not an error if it's a file path. Source: "${e}"`
96
- ), null;
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 k {
100
- constructor(t) {
101
- this.identifier = t;
102
- }
103
- static fromBaseConfig(t) {
104
- if (console.log(t), S(m(t, "tauri.conf.json"))) {
105
- const e = w(m(t, "tauri.conf.json")).toString(), r = V(e);
106
- if (r)
107
- return "identifier" in r ? this.fromV2Base(r) : this.fromV1Base(r);
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 (S(m(t, "tauri.conf.json5"))) {
111
- const e = w(m(t, "tauri.conf.json5")).toString(), r = W(e);
112
- if (r)
113
- return "identifier" in r ? this.fromV2Base(r) : this.fromV1Base(r);
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 (S(m(t, "Tauri.toml"))) {
117
- const e = w(m(t, "Tauri.toml")).toString(), r = z(e);
118
- if (r)
119
- return "identifier" in r ? this.fromV2Base(r) : this.fromV1Base(r);
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(t) {
125
- if (!t.tauri?.bundle?.identifier)
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
- const e = new k(t.tauri?.bundle?.identifier);
128
- return e.productName = t.package?.productName, e.version = t.package?.version, e.frontendDist = t.build?.distDir, e.beforeBuildCommand = t.build?.beforeBuildCommand, e.rpmRelease = t.tauri.bundle.rpm?.release, e.wixLanguage = t.tauri.bundle.windows?.wix?.language, e;
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(t) {
131
- if (!t.identifier)
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
- const e = new k(t.identifier);
134
- return e.productName = t.productName, e.version = t.version, e.frontendDist = t.build?.frontendDist, e.beforeBuildCommand = t.build?.beforeBuildCommand, e.rpmRelease = t.bundle?.linux?.rpm?.release, e.wixLanguage = t.bundle?.windows?.wix?.language, e;
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 Y = (n) => {
138
- const t = _(n ?? ".");
139
- if (t !== null) {
140
- let e, r, o = "en-US", a = "1";
141
- const i = k.fromBaseConfig(t);
142
- if (e = i?.productName, i.version?.endsWith(".json")) {
143
- const l = m(t, i?.version), f = w(l).toString();
144
- r = JSON.parse(f).version;
145
- } else
146
- r = i?.version;
147
- if (!(e && r)) {
148
- const l = A(t);
149
- e = e ?? l.package.name, r = r ?? l.package.version;
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
- e && r || (console.error("Could not determine package name and version."), J.exit(1));
152
- const s = r.replace(/[-+]/g, ".");
153
- return i.wixLanguage && (o = i.wixLanguage), i.rpmRelease && (a = i.rpmRelease), {
154
- basePath: t + "/target",
155
- appName: e,
156
- version: r,
157
- wixLanguage: o,
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
- }, G = async () => new Promise((n) => $("git rev-parse --abbrev-ref HEAD", (t, e, r) => {
164
- if (t)
165
- console.log(`getBranch Error: ${t}`);
166
- else if (e) {
167
- n(e.trim());
168
- return;
169
- }
170
- n(void 0);
171
- }));
172
- function H({
173
- platform: n,
174
- arch: t,
175
- optionAccessKey: e
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 r = p.join(".", "rop.yml"), o = c.readFileSync(r, "utf8"), a = P.load(o);
178
- let i;
179
- t == "x86_64" ? i = "x64" : t ? i = t : i = "x64";
180
- let s = {
181
- arch: i
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 (!a.framework.name)
295
+ if (!config.framework.name) {
184
296
  throw new Error('Missing "framework.name" property in the configuration file.');
185
- const l = Q(a.framework.name, a.projectPath);
186
- if (!l && !a.framework.env)
297
+ }
298
+ const _autoEnv = getAutoEnvByFramework(config.framework.name, config.projectPath);
299
+ if (!_autoEnv && !config.framework.env) {
187
300
  throw new Error(
188
- `The [${a.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
301
+ `The [${config.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
189
302
  );
190
- if (s = {
191
- ...s,
192
- ...l,
193
- ...a.framework.env ?? {}
194
- }, !s.appName)
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
- if (!s.version)
311
+ }
312
+ if (!env.version) {
197
313
  throw new Error('Missing "version" property in the configuration file.');
198
- function f(u) {
199
- Object.keys(u).forEach((d) => {
200
- typeof u[d] == "string" ? u[d] = u[d].replace(/\$\{(\w+)\}/g, (ee, j) => s[j] || "") : typeof u[d] == "object" && u[d] !== null && f(u[d]);
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
- f(a);
204
- const g = a.platforms[n][i];
205
- console.log("find target file:"), console.log(g);
206
- const y = q(e, a.access);
207
- return { config: a, targetInfo: g, accessKey: y, version: s.version };
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 q = (n, t) => {
210
- if (n)
211
- return n;
212
- if (t?.key)
213
- return t?.key;
214
- if (t?.name) {
215
- const e = c.readFileSync(`${E.homedir()}/.rop/config`, "utf8"), r = `\\[${t.name}]\\n(.+)`, o = new RegExp(r).exec(e);
216
- if (o)
217
- return o[1];
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
- }, Q = (n, t) => {
221
- switch (n.toLowerCase()) {
222
- case F.TAURI.toLowerCase():
223
- return Y(t);
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 X {
229
- constructor({ baseDomain: t }) {
230
- this.checkParams = async (e) => {
231
- if (!e.accessKey)
356
+ class RopUpload {
357
+ constructor({ baseDomain }) {
358
+ this.checkParams = async (config) => {
359
+ if (!config.accessKey) {
232
360
  throw new Error("accessKey not null");
233
- const r = e.branch ?? await G();
234
- if (r)
235
- e.branch = r;
236
- else
361
+ }
362
+ const branch = config.branch ?? await getBranch();
363
+ if (!branch) {
237
364
  throw new Error("branch not null");
238
- if (!e.platform)
365
+ } else {
366
+ config.branch = branch;
367
+ }
368
+ if (!config.platform) {
239
369
  throw new Error("platform not null");
240
- if (!e.arch)
370
+ }
371
+ if (!config.arch) {
241
372
  throw new Error("arch not null");
242
- if (!e.targetPath)
373
+ }
374
+ if (!config.targetPath) {
243
375
  throw new Error("target path not null");
244
- if (!c.existsSync(e.targetPath))
245
- throw new Error(`target file not found, file path: ${e.targetPath}`);
246
- if (e.updatePath && !c.existsSync(e.updatePath))
247
- throw new Error(`update file not found, file path: ${e.updatePath}`);
248
- if (!e.version)
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
- return e;
251
- }, this.baseDomain = t;
385
+ }
386
+ return config;
387
+ };
388
+ this.baseDomain = baseDomain;
252
389
  }
253
- async upload(t) {
254
- const e = await this.checkParams(t), r = new B(), o = c.createReadStream(e.targetPath), a = new I.MultiBar({
255
- format: "Upload Progress |" + C.cyan("{bar}") + "| {percentage}% | {filename}",
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: !0
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
- let l;
267
- if (e.updatePath) {
268
- const y = a.create(c.statSync(e.updatePath).size, 0);
269
- l = c.createReadStream(e.updatePath);
270
- let u = 0;
271
- l.on("data", (d) => {
272
- u += d.length, y.update(u, { filename: p.basename(e.updatePath) });
273
- }), r.append("updateFile", l, {
274
- filename: e.updateName ?? p.basename(e.updatePath)
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
- r.append("accessKey", e.accessKey), r.append("branch", e.branch), r.append("version", e.version), r.append("platform", e.platform), r.append("arch", e.arch), e.signature && r.append("signature", e.signature);
278
- const f = await D(`${this.baseDomain}/api/upload`, {
430
+ const res = await fetch(`${this.baseDomain}/api/upload`, {
279
431
  method: "POST",
280
- headers: r.getHeaders(),
281
- body: r
282
- }), g = await f.json();
283
- return f.ok || console.log(f.status, f.statusText, g), a.stop(), o.destroy(), l?.destroy(), { success: f.ok, body: g };
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 Z {
287
- async initYaml(t) {
288
- const e = p.resolve(), r = p.basename(e), o = p.join(".", "rop.yml");
289
- let a = {};
290
- if (c.existsSync(o)) {
291
- let s = !1;
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
- s = await U({
294
- message: `${C.cyan("rop.yml")} already exists, does it need to be overwritten?`
454
+ flag = await prompts.confirm({
455
+ message: `${colors.cyan("rop.yml")} already exists, does it need to be overwritten?`
295
456
  });
296
- } catch {
297
- return console.log("cancel"), !1;
457
+ } catch (error) {
458
+ console.log("cancel");
459
+ return false;
460
+ }
461
+ if (!flag) {
462
+ console.log("cancel");
463
+ return false;
298
464
  }
299
- if (!s)
300
- return console.log("cancel"), !1;
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
- a.access ? a.access.name = r : a.access = {
305
- name: r
306
- };
307
- const i = P.dump(a, {
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
- return c.writeFileSync(o, i, "utf8"), !0;
478
+ fs.writeFileSync(ymlConfigPath, yamlData, "utf8");
479
+ return true;
311
480
  }
312
- async initRopConfig(t) {
313
- const e = p.join(".", ".rop");
314
- c.existsSync(e) || c.mkdirSync(e);
315
- const r = p.join(e, "config.json");
316
- let o = {};
317
- c.existsSync(r) && (o = JSON.parse(c.readFileSync(r, "utf8"))), o.accessKey = t, c.writeFileSync(r, JSON.stringify(o, null, 2), "utf8");
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 t = p.join(".", ".gitignore");
321
- c.existsSync(t) ? c.readFileSync(t, "utf8").includes(".rop") || c.appendFileSync(t, `
322
- .rop`, "utf8") : c.writeFileSync(t, ".rop", "utf8");
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 b = new T();
326
- b.name("rop").description("CLI to some JavaScript string utilities").version("0.1.0");
327
- b.command("init").description("init rop").action(async () => {
328
- let n = "";
329
- for (; !n; )
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
- n = await L({ message: `Please enter ${C.cyan("access-key")}` });
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
- const t = new Z();
337
- await t.initYaml(n) && (await t.initRopConfig(n), await t.initGitignore(), console.log("done"));
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
- b.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (n) => {
526
+ program.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (projectAccessKey) => {
340
527
  try {
341
- const t = n.split("=");
342
- if (t.length != 2)
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
- } catch (t) {
356
- console.error("Error reading configuration file or missing required properties:", t);
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
- b.command("upload").description("Upload some framework build").argument("<string>", "platform").argument("[string]", "arch").option("-a, --accessKey <string>", "accessKey path").action(async (n, t, e) => {
360
- const { config: r, targetInfo: o, accessKey: a, version: i } = H({
361
- platform: n,
362
- arch: t,
363
- optionAccessKey: e.accessKey
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 (!r.host)
564
+ if (!config.host) {
366
565
  throw new Error('Missing "host" property in the configuration file.');
367
- if (!o)
566
+ }
567
+ if (!targetInfo) {
368
568
  throw new Error('Missing "targetInfo" property in the configuration file.');
369
- await new X({ baseDomain: r.host }).upload({
370
- accessKey: a,
371
- arch: t,
372
- platform: n,
373
- version: i,
374
- targetPath: o.target.path,
375
- targetName: o.target?.name,
376
- updatePath: o.update?.path,
377
- updateName: o.update?.name,
378
- signature: o.sig?.path ? h.readFileSync(o.sig.path, "utf8") : void 0
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
- b.parse();
382
- export {
383
- X as RopUpload,
384
- Y as getTauriEnv
385
- };
583
+ program.parse();
584
+ exports.RopUpload = RopUpload;
585
+ exports.getTauriEnv = getTauriEnv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sevenvip666/rop",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",