@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.
Files changed (2) hide show
  1. package/dist/rop.js +487 -286
  2. package/package.json +2 -1
package/dist/rop.js CHANGED
@@ -1,385 +1,586 @@
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
+ #!/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
- n = O(m(n, ".."));
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 _(n) {
40
- const t = N(["**/tauri.conf.json", "**/tauri.conf.json5", "**/Tauri.toml"], {
41
- gitignore: !0,
42
- cwd: n,
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
- return t.length === 0 ? null : x(n, t[0], "..");
76
+ if (tauriConfPaths.length === 0) {
77
+ return null;
78
+ }
79
+ return path.resolve(root, tauriConfPaths[0], "..");
47
80
  }
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)
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
- 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);
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
- ...e,
104
+ ...cargoManifest,
62
105
  package: {
63
- ...e.package,
64
- name: r,
65
- version: o
106
+ ...cargoManifest.package,
107
+ name,
108
+ version
66
109
  }
67
110
  };
68
111
  }
69
- function V(n) {
112
+ function _tryParseJsonConfig(contents) {
70
113
  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;
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 W(n) {
124
+ function _tryParseJson5Config(contents) {
80
125
  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;
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 z(n) {
136
+ function _tryParseTomlConfig(contents) {
90
137
  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;
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 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);
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 (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);
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 (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);
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(t) {
125
- if (!t.tauri?.bundle?.identifier)
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
- 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;
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(t) {
131
- if (!t.identifier)
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
- 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;
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 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;
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
- 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
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
- }, 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
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 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
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 (!a.framework.name)
296
+ if (!config.framework.name) {
184
297
  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)
298
+ }
299
+ const _autoEnv = getAutoEnvByFramework(config.framework.name, config.projectPath);
300
+ if (!_autoEnv && !config.framework.env) {
187
301
  throw new Error(
188
- `The [${a.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
302
+ `The [${config.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
189
303
  );
190
- if (s = {
191
- ...s,
192
- ...l,
193
- ...a.framework.env ?? {}
194
- }, !s.appName)
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
- if (!s.version)
312
+ }
313
+ if (!env.version) {
197
314
  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]);
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
- 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 };
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 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];
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
- }, Q = (n, t) => {
221
- switch (n.toLowerCase()) {
222
- case F.TAURI.toLowerCase():
223
- return Y(t);
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 X {
229
- constructor({ baseDomain: t }) {
230
- this.checkParams = async (e) => {
231
- if (!e.accessKey)
357
+ class RopUpload {
358
+ constructor({ baseDomain }) {
359
+ this.checkParams = async (config) => {
360
+ if (!config.accessKey) {
232
361
  throw new Error("accessKey not null");
233
- const r = e.branch ?? await G();
234
- if (r)
235
- e.branch = r;
236
- else
362
+ }
363
+ const branch = config.branch ?? await getBranch();
364
+ if (!branch) {
237
365
  throw new Error("branch not null");
238
- if (!e.platform)
366
+ } else {
367
+ config.branch = branch;
368
+ }
369
+ if (!config.platform) {
239
370
  throw new Error("platform not null");
240
- if (!e.arch)
371
+ }
372
+ if (!config.arch) {
241
373
  throw new Error("arch not null");
242
- if (!e.targetPath)
374
+ }
375
+ if (!config.targetPath) {
243
376
  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)
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
- return e;
251
- }, this.baseDomain = t;
386
+ }
387
+ return config;
388
+ };
389
+ this.baseDomain = baseDomain;
252
390
  }
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}",
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: !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)
399
+ hideCursor: true
265
400
  });
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)
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
- 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`, {
431
+ const res = await fetch(`${this.baseDomain}/api/upload`, {
279
432
  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 };
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 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;
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
- s = await U({
294
- message: `${C.cyan("rop.yml")} already exists, does it need to be overwritten?`
455
+ flag = await prompts.confirm({
456
+ message: `${colors.cyan("rop.yml")} already exists, does it need to be overwritten?`
295
457
  });
296
- } catch {
297
- return console.log("cancel"), !1;
458
+ } catch (error) {
459
+ console.log("cancel");
460
+ return false;
461
+ }
462
+ if (!flag) {
463
+ console.log("cancel");
464
+ return false;
298
465
  }
299
- if (!s)
300
- return console.log("cancel"), !1;
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
- a.access ? a.access.name = r : a.access = {
305
- name: r
306
- };
307
- const i = P.dump(a, {
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
- return c.writeFileSync(o, i, "utf8"), !0;
479
+ fs.writeFileSync(ymlConfigPath, yamlData, "utf8");
480
+ return true;
311
481
  }
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");
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 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");
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 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; )
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
- n = await L({ message: `Please enter ${C.cyan("access-key")}` });
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
- const t = new Z();
337
- await t.initYaml(n) && (await t.initRopConfig(n), await t.initGitignore(), console.log("done"));
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
- b.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (n) => {
527
+ program.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (projectAccessKey) => {
340
528
  try {
341
- const t = n.split("=");
342
- if (t.length != 2)
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
- } catch (t) {
356
- console.error("Error reading configuration file or missing required properties:", t);
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
- 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
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 (!r.host)
565
+ if (!config.host) {
366
566
  throw new Error('Missing "host" property in the configuration file.');
367
- if (!o)
567
+ }
568
+ if (!targetInfo) {
368
569
  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
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
- b.parse();
382
- export {
383
- X as RopUpload,
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.5",
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": {