@0x-jerry/x 2.12.2 → 2.12.4
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/{chunk-OEKTPD6V.js → chunk-MLK4NZGK.js} +1 -1
- package/dist/x.js +1 -1
- package/dist/xn.js +1 -1
- package/dist/xr.js +37 -19
- package/package.json +3 -3
- package/readme.md +95 -94
package/dist/x.js
CHANGED
package/dist/xn.js
CHANGED
package/dist/xr.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-ELIYGHQS.js";
|
|
5
5
|
import {
|
|
6
6
|
version
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MLK4NZGK.js";
|
|
8
8
|
|
|
9
9
|
// src/xr.ts
|
|
10
10
|
import { sliver } from "@0x-jerry/silver";
|
|
@@ -41,9 +41,9 @@ var DenoTaskDetecter = class {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
// src/commands/run/node.ts
|
|
44
|
-
import { readFile as readFile2
|
|
44
|
+
import { readdir, readFile as readFile2 } from "fs/promises";
|
|
45
45
|
import path2 from "path";
|
|
46
|
-
import { pathExists as pathExists2 } from "fs-extra";
|
|
46
|
+
import { pathExists as pathExists2 } from "fs-extra/esm";
|
|
47
47
|
var NodeTaskDetecter = class {
|
|
48
48
|
async binaryPaths(cwd) {
|
|
49
49
|
const envPaths = [];
|
|
@@ -68,22 +68,24 @@ var NodeTaskDetecter = class {
|
|
|
68
68
|
const text = await readFile2(pkgPath, "utf8");
|
|
69
69
|
const json = JSON.parse(text);
|
|
70
70
|
const tasks = json.scripts || {};
|
|
71
|
-
{
|
|
72
|
-
let dir = cwd;
|
|
73
|
-
do {
|
|
74
|
-
const binPath = path2.join(dir, "node_modules", ".bin");
|
|
75
|
-
if (await pathExists2(binPath)) {
|
|
76
|
-
const files = await readdir(binPath);
|
|
77
|
-
for (const filename of files) {
|
|
78
|
-
tasks[filename] ??= filename;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
dir = path2.resolve(dir, "..");
|
|
82
|
-
} while (dir !== path2.resolve(dir, ".."));
|
|
83
|
-
}
|
|
84
71
|
return tasks;
|
|
85
72
|
}
|
|
86
73
|
};
|
|
74
|
+
async function getBinariesPairs() {
|
|
75
|
+
let dir = process.cwd();
|
|
76
|
+
const binaries = {};
|
|
77
|
+
do {
|
|
78
|
+
const binPath = path2.join(dir, "node_modules", ".bin");
|
|
79
|
+
if (await pathExists2(binPath)) {
|
|
80
|
+
const files = await readdir(binPath);
|
|
81
|
+
for (const filename of files) {
|
|
82
|
+
binaries[filename] = path2.join(binPath, filename);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
dir = path2.resolve(dir, "..");
|
|
86
|
+
} while (dir !== path2.resolve(dir, ".."));
|
|
87
|
+
return binaries;
|
|
88
|
+
}
|
|
87
89
|
|
|
88
90
|
// src/commands/run/rust.ts
|
|
89
91
|
import path3 from "path";
|
|
@@ -115,14 +117,29 @@ async function runScript(command, params = []) {
|
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
}
|
|
120
|
+
if (await runAsBinary(command, params)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
118
123
|
const allScripts = await getAvailableCommands();
|
|
119
124
|
console.log(
|
|
120
125
|
pc.red("["),
|
|
121
126
|
pc.cyan(`${command}`),
|
|
122
|
-
pc.red("] not exists in the list: "),
|
|
127
|
+
pc.red("] does not exists in the list: "),
|
|
123
128
|
allScripts.map((name) => pc.cyan(name)).join(", ")
|
|
124
129
|
);
|
|
125
130
|
}
|
|
131
|
+
async function runAsBinary(command, params) {
|
|
132
|
+
const cwd = process.cwd();
|
|
133
|
+
const binariesPair = await getBinariesPairs();
|
|
134
|
+
const binaries = Object.keys(binariesPair);
|
|
135
|
+
if (binaries.includes(command)) {
|
|
136
|
+
const binPaths = await new NodeTaskDetecter().binaryPaths(cwd);
|
|
137
|
+
const env = makeEnv(binPaths || []);
|
|
138
|
+
await exec(command, params, { env });
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
126
143
|
function makeEnv(extraPaths) {
|
|
127
144
|
const env = process.env;
|
|
128
145
|
const envPaths = process.env.PATH?.split(path4.delimiter) || [];
|
|
@@ -147,12 +164,13 @@ async function getAvailableCommands() {
|
|
|
147
164
|
var ins = sliver`
|
|
148
165
|
v${version} @help @autocompletion
|
|
149
166
|
|
|
150
|
-
xr <@
|
|
167
|
+
xr <@scripts|bin|_files:command-or-file> #stopEarly, run npm script or ts/js file quickly. ${defaultAction}
|
|
151
168
|
`;
|
|
152
|
-
ins.type("
|
|
169
|
+
ins.type("scripts", async () => {
|
|
153
170
|
const allScripts = await getAvailableCommands();
|
|
154
171
|
return allScripts;
|
|
155
172
|
});
|
|
173
|
+
ins.type("bin", () => getBinariesPairs().then((resp) => Object.keys(resp)));
|
|
156
174
|
async function defaultAction(_, arg) {
|
|
157
175
|
const [commandOrFile, ...params] = arg._;
|
|
158
176
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0x-jerry/x",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/0x-jerry/x.git"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"clean": true
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@0x-jerry/silver": "^1.2.
|
|
50
|
+
"@0x-jerry/silver": "^1.2.4",
|
|
51
51
|
"@0x-jerry/utils": "^5.0.0",
|
|
52
52
|
"decompress": "^4.2.1",
|
|
53
53
|
"fs-extra": "^11.3.1",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@0x-jerry/x-release": "^2.4.0",
|
|
66
|
-
"@biomejs/biome": "^2.2.
|
|
66
|
+
"@biomejs/biome": "^2.2.4",
|
|
67
67
|
"@types/decompress": "^4.2.7",
|
|
68
68
|
"@types/fs-extra": "^11.0.4",
|
|
69
69
|
"@types/global-agent": "^3.0.0",
|
package/readme.md
CHANGED
|
@@ -1,94 +1,95 @@
|
|
|
1
|
-
# X
|
|
2
|
-
|
|
3
|
-
Some useful command for myself.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
pnpm i -g @0x-jerry/x
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Run task `xr`
|
|
12
|
-
|
|
13
|
-
`xr` command can auto detect tasks in `package.json/scripts`, `deno.json/tasks`, and run it. you can also append any parameters.
|
|
14
|
-
|
|
15
|
-
Example: In a node project with `pnpm-lock.yaml`. And `package.json` has a script `"test": "vitest run"`
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
xr test test/*.ts
|
|
19
|
-
# equals
|
|
20
|
-
vitest run test/*.ts
|
|
21
|
-
|
|
22
|
-
# you can also execute binary file in `node_modules/.bin` folder.
|
|
23
|
-
xr vite --port 4004
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
Example: In a deno project with `deno.json` or `deno.jsonc`. And have a task `"dev": "deno run -A main.ts"`
|
|
27
|
-
|
|
28
|
-
```sh
|
|
29
|
-
xr dev
|
|
30
|
-
# equals
|
|
31
|
-
deno run -A main.ts
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
## Dependency Manager `xn`
|
|
35
|
-
|
|
36
|
-
`xn` command can install modules by detect the correct tool, it detects lockfile to decide which dependency manager tools should be used.
|
|
37
|
-
|
|
38
|
-
Example: install packages in a node project with `pnpm-lock.yaml`
|
|
39
|
-
|
|
40
|
-
```sh
|
|
41
|
-
xn i lodash-es
|
|
42
|
-
# equals
|
|
43
|
-
pnpm i lodash-es
|
|
44
|
-
|
|
45
|
-
xn i lodash-es -D
|
|
46
|
-
# equals
|
|
47
|
-
pnpm i lodash-es -D
|
|
48
|
-
|
|
49
|
-
# -t/--types option support install @types/xx package in one command.
|
|
50
|
-
xn i lodash-es --types
|
|
51
|
-
# equals
|
|
52
|
-
pnpm i lodash-es && pnpm i @types/lodash-es -D
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Example: remove packages in a node project with `pnpm-lock.yaml`
|
|
56
|
-
|
|
57
|
-
```sh
|
|
58
|
-
xn rm lodash-es
|
|
59
|
-
# equals
|
|
60
|
-
pnpm uninstall lodash-es
|
|
61
|
-
|
|
62
|
-
xn rm lodash-es -D
|
|
63
|
-
# equals
|
|
64
|
-
pnpm uninstall lodash-es -D
|
|
65
|
-
|
|
66
|
-
# -t/--types option support remove @types/xx package in one command.
|
|
67
|
-
xn rm lodash-es --types
|
|
68
|
-
# equals
|
|
69
|
-
pnpm uninstall lodash-es @types/lodash-es
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
`xn` also support rust project.
|
|
73
|
-
|
|
74
|
-
Example: in a rust project with `Cargo.toml`
|
|
75
|
-
|
|
76
|
-
```sh
|
|
77
|
-
xn i log
|
|
78
|
-
# equals
|
|
79
|
-
cargo add log
|
|
80
|
-
|
|
81
|
-
xn rm log
|
|
82
|
-
# equals
|
|
83
|
-
cargo remove log
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Command Completions
|
|
87
|
-
|
|
88
|
-
Add this code to `~/.zshrc`
|
|
89
|
-
|
|
90
|
-
```zsh
|
|
91
|
-
source <(x
|
|
92
|
-
source <(xr
|
|
93
|
-
source <(xn
|
|
94
|
-
```
|
|
1
|
+
# X
|
|
2
|
+
|
|
3
|
+
Some useful command for myself.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm i -g @0x-jerry/x
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Run task `xr`
|
|
12
|
+
|
|
13
|
+
`xr` command can auto detect tasks in `package.json/scripts`, `deno.json/tasks`, and run it. you can also append any parameters.
|
|
14
|
+
|
|
15
|
+
Example: In a node project with `pnpm-lock.yaml`. And `package.json` has a script `"test": "vitest run"`
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
xr test test/*.ts
|
|
19
|
+
# equals
|
|
20
|
+
vitest run test/*.ts
|
|
21
|
+
|
|
22
|
+
# you can also execute binary file in `node_modules/.bin` folder.
|
|
23
|
+
xr vite --port 4004
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Example: In a deno project with `deno.json` or `deno.jsonc`. And have a task `"dev": "deno run -A main.ts"`
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
xr dev
|
|
30
|
+
# equals
|
|
31
|
+
deno run -A main.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Dependency Manager `xn`
|
|
35
|
+
|
|
36
|
+
`xn` command can install modules by detect the correct tool, it detects lockfile to decide which dependency manager tools should be used.
|
|
37
|
+
|
|
38
|
+
Example: install packages in a node project with `pnpm-lock.yaml`
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
xn i lodash-es
|
|
42
|
+
# equals
|
|
43
|
+
pnpm i lodash-es
|
|
44
|
+
|
|
45
|
+
xn i lodash-es -D
|
|
46
|
+
# equals
|
|
47
|
+
pnpm i lodash-es -D
|
|
48
|
+
|
|
49
|
+
# -t/--types option support install @types/xx package in one command.
|
|
50
|
+
xn i lodash-es --types
|
|
51
|
+
# equals
|
|
52
|
+
pnpm i lodash-es && pnpm i @types/lodash-es -D
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Example: remove packages in a node project with `pnpm-lock.yaml`
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
xn rm lodash-es
|
|
59
|
+
# equals
|
|
60
|
+
pnpm uninstall lodash-es
|
|
61
|
+
|
|
62
|
+
xn rm lodash-es -D
|
|
63
|
+
# equals
|
|
64
|
+
pnpm uninstall lodash-es -D
|
|
65
|
+
|
|
66
|
+
# -t/--types option support remove @types/xx package in one command.
|
|
67
|
+
xn rm lodash-es --types
|
|
68
|
+
# equals
|
|
69
|
+
pnpm uninstall lodash-es @types/lodash-es
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`xn` also support rust project.
|
|
73
|
+
|
|
74
|
+
Example: in a rust project with `Cargo.toml`
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
xn i log
|
|
78
|
+
# equals
|
|
79
|
+
cargo add log
|
|
80
|
+
|
|
81
|
+
xn rm log
|
|
82
|
+
# equals
|
|
83
|
+
cargo remove log
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Command Completions
|
|
87
|
+
|
|
88
|
+
Add this code to `~/.zshrc`
|
|
89
|
+
|
|
90
|
+
```zsh
|
|
91
|
+
source <(x completion)
|
|
92
|
+
source <(xr completion)
|
|
93
|
+
source <(xn completion)
|
|
94
|
+
```
|
|
95
|
+
|