@sevenvip666/rop 0.0.3 → 0.0.5

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.
@@ -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,385 @@
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;
33
+ }
34
+ }
35
+ n = O(m(n, ".."));
36
+ }
37
+ return null;
38
+ }
39
+ function _(n) {
40
+ const t = N(["**/tauri.conf.json", "**/tauri.conf.json5", "**/Tauri.toml"], {
41
+ gitignore: !0,
42
+ cwd: n,
43
+ // Forcefully ignore target and node_modules dirs
44
+ ignore: ["**/target", "**/node_modules"]
45
+ });
46
+ return t.length === 0 ? null : x(n, t[0], "..");
47
+ }
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)
54
+ throw new Error(
55
+ "Could not find workspace directory, but version and/or name specifies to use workspace package"
56
+ );
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);
59
+ }
60
+ return {
61
+ ...e,
62
+ package: {
63
+ ...e.package,
64
+ name: r,
65
+ version: o
66
+ }
67
+ };
68
+ }
69
+ function V(n) {
70
+ 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;
77
+ }
78
+ }
79
+ function W(n) {
80
+ 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;
87
+ }
88
+ }
89
+ function z(n) {
90
+ 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;
97
+ }
98
+ }
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);
108
+ console.error("Found tauri.conf.json file but couldn't parse it as JSON.");
109
+ }
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);
114
+ console.error("Found tauri.conf.json5 file but couldn't parse it as JSON5.");
115
+ }
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);
120
+ console.error("Found Tauri.toml file but couldn't parse it as TOML.");
121
+ }
122
+ throw new Error("Couldn't locate or parse tauri config.");
123
+ }
124
+ static fromV1Base(t) {
125
+ if (!t.tauri?.bundle?.identifier)
126
+ 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;
129
+ }
130
+ static fromV2Base(t) {
131
+ if (!t.identifier)
132
+ 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;
135
+ }
136
+ }
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;
150
+ }
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
160
+ };
161
+ } else
162
+ 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
176
+ }) {
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
182
+ };
183
+ if (!a.framework.name)
184
+ 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)
187
+ throw new Error(
188
+ `The [${a.framework.name}] framework is not supported, please specify the [framework.env] attribute.`
189
+ );
190
+ if (s = {
191
+ ...s,
192
+ ...l,
193
+ ...a.framework.env ?? {}
194
+ }, !s.appName)
195
+ throw new Error('Missing "appName" property in the configuration file.');
196
+ if (!s.version)
197
+ 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]);
201
+ });
202
+ }
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 };
208
+ }
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];
218
+ }
219
+ throw new Error("missing access-key");
220
+ }, Q = (n, t) => {
221
+ switch (n.toLowerCase()) {
222
+ case F.TAURI.toLowerCase():
223
+ return Y(t);
224
+ default:
225
+ return;
226
+ }
227
+ };
228
+ class X {
229
+ constructor({ baseDomain: t }) {
230
+ this.checkParams = async (e) => {
231
+ if (!e.accessKey)
232
+ throw new Error("accessKey not null");
233
+ const r = e.branch ?? await G();
234
+ if (r)
235
+ e.branch = r;
236
+ else
237
+ throw new Error("branch not null");
238
+ if (!e.platform)
239
+ throw new Error("platform not null");
240
+ if (!e.arch)
241
+ throw new Error("arch not null");
242
+ if (!e.targetPath)
243
+ 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)
249
+ throw new Error("version not null");
250
+ return e;
251
+ }, this.baseDomain = t;
252
+ }
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}",
256
+ barCompleteChar: "█",
257
+ 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)
265
+ });
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)
275
+ });
276
+ }
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`, {
279
+ 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 };
284
+ }
285
+ }
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;
292
+ try {
293
+ s = await U({
294
+ message: `${C.cyan("rop.yml")} already exists, does it need to be overwritten?`
295
+ });
296
+ } catch {
297
+ return console.log("cancel"), !1;
298
+ }
299
+ if (!s)
300
+ return console.log("cancel"), !1;
301
+ const l = c.readFileSync(o, "utf8");
302
+ a = P.load(l);
303
+ }
304
+ a.access ? a.access.name = r : a.access = {
305
+ name: r
306
+ };
307
+ const i = P.dump(a, {
308
+ lineWidth: 500
309
+ });
310
+ return c.writeFileSync(o, i, "utf8"), !0;
311
+ }
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");
318
+ }
319
+ 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");
323
+ }
324
+ }
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; )
330
+ try {
331
+ n = await L({ message: `Please enter ${C.cyan("access-key")}` });
332
+ } catch {
333
+ console.log("cancel");
334
+ return;
335
+ }
336
+ const t = new Z();
337
+ await t.initYaml(n) && (await t.initRopConfig(n), await t.initGitignore(), console.log("done"));
338
+ });
339
+ b.command("set-key").description("set access-key").argument("<string>", "projectAccessKey").action(async (n) => {
340
+ try {
341
+ const t = n.split("=");
342
+ if (t.length != 2)
343
+ 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
+ }
355
+ } catch (t) {
356
+ console.error("Error reading configuration file or missing required properties:", t);
357
+ }
358
+ });
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
364
+ });
365
+ if (!r.host)
366
+ throw new Error('Missing "host" property in the configuration file.');
367
+ if (!o)
368
+ 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
379
+ });
380
+ });
381
+ b.parse();
382
+ export {
383
+ X as RopUpload,
384
+ Y as getTauriEnv
385
+ };
package/package.json CHANGED
@@ -1,30 +1,27 @@
1
1
  {
2
2
  "name": "@sevenvip666/rop",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
7
7
  "index.d.ts"
8
8
  ],
9
9
  "bin": {
10
- "rop": "dist/index.js"
10
+ "rop": "dist/rop.js"
11
11
  },
12
- "main": "dist/index.js",
13
- "module": "dist/index.js",
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/index.js"
17
+ "import": "./dist/rop.js"
18
18
  },
19
19
  "scripts": {
20
- "test": "vitest",
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
  }