@0x-jerry/x 2.4.2 → 2.5.0
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/x.js +3 -6
- package/dist/xn.js +1 -1
- package/dist/xr.js +116 -87
- package/package.json +11 -11
package/dist/x.js
CHANGED
|
@@ -21,8 +21,7 @@ async function downloadGitRepo(opt) {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
destDir = await checkDest(destDir) || "";
|
|
24
|
-
if (!destDir)
|
|
25
|
-
return;
|
|
24
|
+
if (!destDir) return;
|
|
26
25
|
const gitConf = normalizeGitUrl(url);
|
|
27
26
|
const zipFilePath = await downloadGitBranch(gitConf, branch);
|
|
28
27
|
await fs.ensureDir(destDir);
|
|
@@ -56,8 +55,7 @@ async function checkDest(dest) {
|
|
|
56
55
|
});
|
|
57
56
|
dest = res.dest;
|
|
58
57
|
}
|
|
59
|
-
if (!dest)
|
|
60
|
-
return;
|
|
58
|
+
if (!dest) return;
|
|
61
59
|
dest = path.isAbsolute(dest) ? dest : path.join(cwd, dest);
|
|
62
60
|
const files = fs.pathExistsSync(dest) ? await fs.readdir(dest) : null;
|
|
63
61
|
if (files?.length) {
|
|
@@ -67,8 +65,7 @@ async function checkDest(dest) {
|
|
|
67
65
|
message: `Detect files in ${pc.cyan(dest)}, override it?`,
|
|
68
66
|
initial: false
|
|
69
67
|
});
|
|
70
|
-
if (!res.override)
|
|
71
|
-
return;
|
|
68
|
+
if (!res.override) return;
|
|
72
69
|
}
|
|
73
70
|
return dest;
|
|
74
71
|
}
|
package/dist/xn.js
CHANGED
|
@@ -98,7 +98,7 @@ async function installAction(_, opt) {
|
|
|
98
98
|
}
|
|
99
99
|
await runNpm("add", ...parameters);
|
|
100
100
|
if (opt.types) {
|
|
101
|
-
const typesPackages = parameters.filter((n) => n.startsWith("-")).map((pkg) => getTypePackageName(pkg));
|
|
101
|
+
const typesPackages = parameters.filter((n) => !n.startsWith("-")).map((pkg) => getTypePackageName(pkg));
|
|
102
102
|
await runNpm("add", ...typesPackages, "-D");
|
|
103
103
|
}
|
|
104
104
|
}
|
package/dist/xr.js
CHANGED
|
@@ -7,101 +7,130 @@ import {
|
|
|
7
7
|
import { sliver } from "@0x-jerry/silver";
|
|
8
8
|
|
|
9
9
|
// src/commands/run.ts
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
import path4 from "path";
|
|
11
|
+
|
|
12
|
+
// src/commands/run/node.ts
|
|
13
|
+
import { pathExists } from "fs-extra";
|
|
14
|
+
import path from "path";
|
|
15
|
+
import { readdir, readFile } from "fs/promises";
|
|
16
|
+
var NodeTaskDetecter = class {
|
|
17
|
+
async binaryPaths(cwd) {
|
|
18
|
+
const envPaths = [];
|
|
19
|
+
let dir = cwd;
|
|
20
|
+
do {
|
|
21
|
+
const binPath = path.join(dir, "node_modules", ".bin");
|
|
22
|
+
if (await pathExists(binPath)) {
|
|
23
|
+
envPaths.push(binPath);
|
|
24
|
+
}
|
|
25
|
+
dir = path.resolve(dir, "..");
|
|
26
|
+
} while (dir !== path.resolve(dir, ".."));
|
|
27
|
+
return envPaths;
|
|
21
28
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const env = process.env;
|
|
32
|
-
const envPaths = process.env.PATH?.split(path.delimiter) || [];
|
|
33
|
-
let dir = cwd;
|
|
34
|
-
do {
|
|
35
|
-
const binPath = join(dir, "node_modules", ".bin");
|
|
36
|
-
if (existsSync(binPath)) {
|
|
37
|
-
envPaths.push(binPath);
|
|
38
|
-
}
|
|
39
|
-
dir = resolve(dir, "..");
|
|
40
|
-
} while (dir !== resolve(dir, ".."));
|
|
41
|
-
env.PATH = envPaths.join(path.delimiter);
|
|
42
|
-
return env;
|
|
43
|
-
}
|
|
44
|
-
async function getPackageScripts() {
|
|
45
|
-
const scripts = /* @__PURE__ */ new Map();
|
|
46
|
-
const cwd = process.cwd();
|
|
47
|
-
const pkgPath = join(cwd, "package.json");
|
|
48
|
-
try {
|
|
49
|
-
const text = await readFile(pkgPath, { encoding: "utf-8" });
|
|
29
|
+
check(cwd) {
|
|
30
|
+
return pathExists(path.join(cwd, "package.json"));
|
|
31
|
+
}
|
|
32
|
+
async task(cwd, taskName) {
|
|
33
|
+
return (await this.tasks(cwd))[taskName];
|
|
34
|
+
}
|
|
35
|
+
async tasks(cwd) {
|
|
36
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
37
|
+
const text = await readFile(pkgPath, "utf8");
|
|
50
38
|
const json = JSON.parse(text);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
const tasks = json.scripts || {};
|
|
40
|
+
{
|
|
41
|
+
let dir = cwd;
|
|
42
|
+
do {
|
|
43
|
+
const binPath = path.join(dir, "node_modules", ".bin");
|
|
44
|
+
if (await pathExists(binPath)) {
|
|
45
|
+
const files = await readdir(binPath);
|
|
46
|
+
for (const filename of files) {
|
|
47
|
+
tasks[filename] ??= filename;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
dir = path.resolve(dir, "..");
|
|
51
|
+
} while (dir !== path.resolve(dir, ".."));
|
|
52
|
+
}
|
|
53
|
+
return tasks;
|
|
55
54
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/commands/run/deno.ts
|
|
58
|
+
import { parse } from "jsonc-parser";
|
|
59
|
+
import { pathExists as pathExists2 } from "fs-extra";
|
|
60
|
+
import path2 from "path";
|
|
61
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
62
|
+
var DenoTaskDetecter = class {
|
|
63
|
+
check(cwd) {
|
|
64
|
+
return pathExists2(path2.join(cwd, "deno.json")) || pathExists2(path2.join(cwd, "deno.jsonc"));
|
|
65
|
+
}
|
|
66
|
+
async task(cwd, taskName) {
|
|
67
|
+
return (await this.tasks(cwd))[taskName];
|
|
68
|
+
}
|
|
69
|
+
async tasks(cwd) {
|
|
70
|
+
let tasks = {};
|
|
71
|
+
let denoConfigPath = path2.join(cwd, "deno.json");
|
|
72
|
+
if (!await pathExists2(denoConfigPath)) {
|
|
73
|
+
denoConfigPath = path2.join(cwd, "deno.jsonc");
|
|
68
74
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
async function getDenoTasks() {
|
|
74
|
-
const tasks = /* @__PURE__ */ new Map();
|
|
75
|
-
const cwd = process.cwd();
|
|
76
|
-
try {
|
|
77
|
-
let txt = "";
|
|
78
|
-
try {
|
|
79
|
-
const denoConf = join(cwd, "deno.json");
|
|
80
|
-
txt = await readFile(denoConf, { encoding: "utf-8" });
|
|
81
|
-
} catch (_error) {
|
|
82
|
-
const denoConf = join(cwd, "deno.jsonc");
|
|
83
|
-
txt = await readFile(denoConf, { encoding: "utf-8" });
|
|
75
|
+
if (await pathExists2(denoConfigPath)) {
|
|
76
|
+
const text = await readFile2(denoConfigPath, "utf8");
|
|
77
|
+
const json = parse(text);
|
|
78
|
+
tasks = json.tasks || {};
|
|
84
79
|
}
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
return tasks;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// src/commands/run/rust.ts
|
|
85
|
+
import { pathExists as pathExists3 } from "fs-extra";
|
|
86
|
+
import path3 from "path";
|
|
87
|
+
var RustTaskDetecter = class {
|
|
88
|
+
check(cwd) {
|
|
89
|
+
return pathExists3(path3.join(cwd, "Cargo.toml"));
|
|
90
|
+
}
|
|
91
|
+
async task(_cwd, _taskName) {
|
|
92
|
+
return "cargo run";
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
// src/commands/run.ts
|
|
97
|
+
async function runScript(command, params = []) {
|
|
98
|
+
const taskDetectors = [
|
|
99
|
+
new NodeTaskDetecter(),
|
|
100
|
+
new DenoTaskDetecter(),
|
|
101
|
+
new RustTaskDetecter()
|
|
102
|
+
];
|
|
103
|
+
const cwd = process.cwd();
|
|
104
|
+
for (const taskDetector of taskDetectors) {
|
|
105
|
+
if (await taskDetector.check(cwd)) {
|
|
106
|
+
const task = await taskDetector.task(cwd, command);
|
|
107
|
+
if (task) {
|
|
108
|
+
const env = makeEnv(await taskDetector.binaryPaths?.(cwd) || []);
|
|
109
|
+
await exec(task, params, env);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
87
112
|
}
|
|
88
|
-
const json = jsonc.parse(txt);
|
|
89
|
-
Object.entries(json.tasks).forEach(([name, content]) => {
|
|
90
|
-
tasks.set(name, content);
|
|
91
|
-
});
|
|
92
|
-
} catch (_error) {
|
|
93
113
|
}
|
|
94
|
-
|
|
114
|
+
await exec(command, params, makeEnv([]));
|
|
95
115
|
}
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
116
|
+
function makeEnv(extraPaths) {
|
|
117
|
+
const env = process.env;
|
|
118
|
+
const envPaths = process.env.PATH?.split(path4.delimiter) || [];
|
|
119
|
+
env.PATH = [...envPaths, ...extraPaths].join(path4.delimiter);
|
|
120
|
+
return env;
|
|
121
|
+
}
|
|
122
|
+
async function getAvailableCommands() {
|
|
123
|
+
const taskDetectors = [
|
|
124
|
+
new NodeTaskDetecter(),
|
|
125
|
+
new DenoTaskDetecter(),
|
|
126
|
+
new RustTaskDetecter()
|
|
103
127
|
];
|
|
104
|
-
|
|
128
|
+
const cwd = process.cwd();
|
|
129
|
+
const p = taskDetectors.map(
|
|
130
|
+
async (t) => await t.check(cwd) ? Object.keys(await t.tasks?.(cwd) || {}) : []
|
|
131
|
+
);
|
|
132
|
+
const tasks = await Promise.all(p);
|
|
133
|
+
return tasks.flat();
|
|
105
134
|
}
|
|
106
135
|
|
|
107
136
|
// src/xr.ts
|
|
@@ -111,7 +140,7 @@ var ins = sliver`
|
|
|
111
140
|
xr [@command:command] #stopEarly, run command quickly. ${defaultAction}
|
|
112
141
|
`;
|
|
113
142
|
ins.type("command", async () => {
|
|
114
|
-
const
|
|
143
|
+
const allScripts = await getAvailableCommands();
|
|
115
144
|
return allScripts;
|
|
116
145
|
});
|
|
117
146
|
async function defaultAction(_, arg) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0x-jerry/x",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/0x-jerry/x.git"
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"clean": true
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@0x-jerry/silver": "^0.1.
|
|
47
|
-
"@0x-jerry/utils": "^2.2
|
|
46
|
+
"@0x-jerry/silver": "^0.1.8",
|
|
47
|
+
"@0x-jerry/utils": "^2.4.2",
|
|
48
48
|
"decompress": "^4.2.1",
|
|
49
49
|
"fs-extra": "^11.2.0",
|
|
50
50
|
"global-agent": "^3.0.0",
|
|
51
|
-
"got": "^14.
|
|
52
|
-
"jsonc-parser": "^3.
|
|
51
|
+
"got": "^14.4.1",
|
|
52
|
+
"jsonc-parser": "^3.3.1",
|
|
53
53
|
"ora": "^8.0.1",
|
|
54
54
|
"picocolors": "^1.0.1",
|
|
55
55
|
"prompts": "^2.4.2"
|
|
@@ -59,12 +59,12 @@
|
|
|
59
59
|
"@types/decompress": "^4.2.7",
|
|
60
60
|
"@types/fs-extra": "^11.0.4",
|
|
61
61
|
"@types/global-agent": "^2.1.3",
|
|
62
|
-
"@types/node": "^20.
|
|
62
|
+
"@types/node": "^20.14.11",
|
|
63
63
|
"@types/prompts": "^2.4.9",
|
|
64
|
-
"@vitest/coverage-v8": "^
|
|
65
|
-
"tsup": "^8.
|
|
66
|
-
"tsx": "^4.
|
|
67
|
-
"typescript": "^5.
|
|
68
|
-
"vitest": "^
|
|
64
|
+
"@vitest/coverage-v8": "^2.0.3",
|
|
65
|
+
"tsup": "^8.1.2",
|
|
66
|
+
"tsx": "^4.16.2",
|
|
67
|
+
"typescript": "^5.5.3",
|
|
68
|
+
"vitest": "^2.0.3"
|
|
69
69
|
}
|
|
70
70
|
}
|