@0x-jerry/x 2.5.0 → 2.6.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/chunk-WA6Z2RU3.js +26 -0
- package/dist/xn.d.ts +0 -11
- package/dist/xn.js +155 -44
- package/dist/xr.js +10 -3
- package/package.json +3 -3
- package/dist/chunk-O5N22U5G.js +0 -15
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { run } from "@0x-jerry/utils/node";
|
|
4
|
+
async function exec(script, params, env) {
|
|
5
|
+
const cmd = [script, ...params].join(" ");
|
|
6
|
+
await run(cmd, env);
|
|
7
|
+
}
|
|
8
|
+
function exists(path) {
|
|
9
|
+
return existsSync(path);
|
|
10
|
+
}
|
|
11
|
+
function flagOptionToStringArray(opt) {
|
|
12
|
+
return Object.entries(opt).map(([_key, value]) => {
|
|
13
|
+
const key = (_key.length === 1 ? "-" : "--") + _key;
|
|
14
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
15
|
+
return [key, String(value)];
|
|
16
|
+
} else {
|
|
17
|
+
return [key];
|
|
18
|
+
}
|
|
19
|
+
}).flat();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
exec,
|
|
24
|
+
exists,
|
|
25
|
+
flagOptionToStringArray
|
|
26
|
+
};
|
package/dist/xn.d.ts
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
* @param pkg
|
|
5
|
-
*
|
|
6
|
-
* getPackageName('lodash@latest') => @types/lodash
|
|
7
|
-
* getPackageName('@babel/core') => @types/babel__core
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
declare function getTypePackageName(pkg: string): string;
|
|
11
|
-
|
|
12
|
-
export { getTypePackageName };
|
package/dist/xn.js
CHANGED
|
@@ -1,18 +1,71 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
exec,
|
|
4
|
-
exists
|
|
5
|
-
|
|
4
|
+
exists,
|
|
5
|
+
flagOptionToStringArray
|
|
6
|
+
} from "./chunk-WA6Z2RU3.js";
|
|
6
7
|
|
|
7
8
|
// src/xn.ts
|
|
8
9
|
import { sliver } from "@0x-jerry/silver";
|
|
9
10
|
|
|
10
|
-
// src/commands/
|
|
11
|
-
import {
|
|
11
|
+
// src/commands/dep/deno.ts
|
|
12
|
+
import { pathExists } from "fs-extra";
|
|
13
|
+
import path from "path";
|
|
14
|
+
var DenoDependencyManager = class {
|
|
15
|
+
check() {
|
|
16
|
+
const cwd = process.cwd();
|
|
17
|
+
return pathExists(path.join(cwd, "deno.json")) || pathExists(path.join(cwd, "deno.jsonc"));
|
|
18
|
+
}
|
|
19
|
+
async install(option) {
|
|
20
|
+
await exec("deno", ["cache"]);
|
|
21
|
+
}
|
|
22
|
+
async add(modules, option) {
|
|
23
|
+
await exec("deno", ["add", ...modules]);
|
|
24
|
+
}
|
|
25
|
+
async remove(modules, option) {
|
|
26
|
+
throw new Error("Deno not support remove modules");
|
|
27
|
+
}
|
|
28
|
+
async upgrade(modules, option) {
|
|
29
|
+
throw new Error("Deno not support upgrade modules");
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/commands/dep/node.ts
|
|
34
|
+
import path2, { join } from "path";
|
|
12
35
|
import pc from "picocolors";
|
|
13
36
|
import { readFile } from "fs/promises";
|
|
37
|
+
import { pathExists as pathExists2 } from "fs-extra";
|
|
38
|
+
var NodeDependencyManager = class {
|
|
39
|
+
async check() {
|
|
40
|
+
return pathExists2(path2.join(process.cwd(), "package.json"));
|
|
41
|
+
}
|
|
42
|
+
async install(option) {
|
|
43
|
+
await runDepManagerCommand("install");
|
|
44
|
+
}
|
|
45
|
+
async add(modules, option = {}) {
|
|
46
|
+
await runDepManagerCommand("add", ...modules);
|
|
47
|
+
if (option.type) {
|
|
48
|
+
const typeModules = modules.map((pkg) => getTypePackageName(pkg));
|
|
49
|
+
await runDepManagerCommand("add", ...typeModules, "-D");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async remove(modules, option = {}) {
|
|
53
|
+
await runDepManagerCommand(
|
|
54
|
+
"remove",
|
|
55
|
+
...modules,
|
|
56
|
+
...flagOptionToStringArray(option)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
async upgrade(modules, option = {}) {
|
|
60
|
+
await runDepManagerCommand(
|
|
61
|
+
"upgrade",
|
|
62
|
+
...modules,
|
|
63
|
+
...flagOptionToStringArray(option)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
14
67
|
var { yellow } = pc;
|
|
15
|
-
var
|
|
68
|
+
var depInstallerCommandMapper = {
|
|
16
69
|
install: {
|
|
17
70
|
npm: "i",
|
|
18
71
|
yarn: "install",
|
|
@@ -25,6 +78,12 @@ var npmCommandMapper = {
|
|
|
25
78
|
pnpm: "i",
|
|
26
79
|
bun: "add"
|
|
27
80
|
},
|
|
81
|
+
remove: {
|
|
82
|
+
npm: "uninstall",
|
|
83
|
+
yarn: "remove",
|
|
84
|
+
pnpm: "uninstall",
|
|
85
|
+
bun: "remove"
|
|
86
|
+
},
|
|
28
87
|
upgrade: {
|
|
29
88
|
npm: "up",
|
|
30
89
|
yarn: "upgrade",
|
|
@@ -32,7 +91,7 @@ var npmCommandMapper = {
|
|
|
32
91
|
bun: "update"
|
|
33
92
|
}
|
|
34
93
|
};
|
|
35
|
-
async function
|
|
94
|
+
async function runDepManagerCommand(action, ...params) {
|
|
36
95
|
if (!await getPkgJson()) {
|
|
37
96
|
console.log(
|
|
38
97
|
yellow(
|
|
@@ -41,19 +100,19 @@ async function runNpm(action, ...params) {
|
|
|
41
100
|
);
|
|
42
101
|
return;
|
|
43
102
|
}
|
|
44
|
-
const
|
|
45
|
-
const actionName =
|
|
46
|
-
await exec(
|
|
103
|
+
const depInstallerCommand = await detectPkgManagerCommand();
|
|
104
|
+
const actionName = depInstallerCommandMapper[action][depInstallerCommand];
|
|
105
|
+
await exec(depInstallerCommand, [actionName, ...params]);
|
|
47
106
|
}
|
|
48
|
-
async function
|
|
49
|
-
const bunLockFile = join(cwd, "bun.lockb");
|
|
50
|
-
if (exists(bunLockFile)) {
|
|
51
|
-
return "bun";
|
|
52
|
-
}
|
|
107
|
+
async function detectPkgManagerCommand(cwd = process.cwd()) {
|
|
53
108
|
const pnpmLockFile = join(cwd, "pnpm-lock.yaml");
|
|
54
109
|
if (exists(pnpmLockFile)) {
|
|
55
110
|
return "pnpm";
|
|
56
111
|
}
|
|
112
|
+
const bunLockFile = join(cwd, "bun.lockb");
|
|
113
|
+
if (exists(bunLockFile)) {
|
|
114
|
+
return "bun";
|
|
115
|
+
}
|
|
57
116
|
const yarnLockFile = join(cwd, "yarn.lock");
|
|
58
117
|
if (exists(yarnLockFile)) {
|
|
59
118
|
return "yarn";
|
|
@@ -73,52 +132,104 @@ async function getPkgJson(cwd = process.cwd()) {
|
|
|
73
132
|
return false;
|
|
74
133
|
}
|
|
75
134
|
}
|
|
135
|
+
function getTypePackageName(pkg) {
|
|
136
|
+
const idx = pkg.lastIndexOf("@");
|
|
137
|
+
const name = idx > 0 ? pkg.slice(0, idx) : pkg;
|
|
138
|
+
if (name.includes("@")) {
|
|
139
|
+
const [scope, pkgName] = name.split("/");
|
|
140
|
+
return `@types/${scope.slice(1)}__${pkgName}`;
|
|
141
|
+
} else {
|
|
142
|
+
return `@types/${name}`;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// src/commands/dep/rust.ts
|
|
147
|
+
import { pathExists as pathExists3 } from "fs-extra";
|
|
148
|
+
import path3 from "path";
|
|
149
|
+
var RustDependencyManager = class {
|
|
150
|
+
check() {
|
|
151
|
+
return pathExists3(path3.join(process.cwd(), "Cargo.toml"));
|
|
152
|
+
}
|
|
153
|
+
async install(option) {
|
|
154
|
+
await exec("cargo", ["check"]);
|
|
155
|
+
}
|
|
156
|
+
async add(modules, option) {
|
|
157
|
+
await exec("cargo", ["add", ...modules]);
|
|
158
|
+
}
|
|
159
|
+
async remove(modules, option) {
|
|
160
|
+
await exec("cargo", ["remove", ...modules]);
|
|
161
|
+
}
|
|
162
|
+
async upgrade(modules, option) {
|
|
163
|
+
await exec("cargo", ["update", ...modules]);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/commands/depManager.ts
|
|
168
|
+
var DepManager = class {
|
|
169
|
+
managers = [
|
|
170
|
+
new NodeDependencyManager(),
|
|
171
|
+
new DenoDependencyManager(),
|
|
172
|
+
new RustDependencyManager()
|
|
173
|
+
];
|
|
174
|
+
async check() {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
async _getManager() {
|
|
178
|
+
for (const m of this.managers) {
|
|
179
|
+
if (await m.check()) {
|
|
180
|
+
return m;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
async install(option) {
|
|
185
|
+
;
|
|
186
|
+
(await this._getManager())?.install(option);
|
|
187
|
+
}
|
|
188
|
+
async add(modules, option) {
|
|
189
|
+
;
|
|
190
|
+
(await this._getManager())?.add(modules, option);
|
|
191
|
+
}
|
|
192
|
+
async remove(modules, option) {
|
|
193
|
+
;
|
|
194
|
+
(await this._getManager())?.remove(modules, option);
|
|
195
|
+
}
|
|
196
|
+
async upgrade(modules, option) {
|
|
197
|
+
;
|
|
198
|
+
(await this._getManager())?.upgrade(modules, option);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
76
201
|
|
|
77
202
|
// src/xn.ts
|
|
78
203
|
sliver`
|
|
79
204
|
@help @autocompletion
|
|
80
205
|
|
|
81
|
-
xn, install
|
|
206
|
+
xn, install dependency quickly, support node/deno/cargo. ${defaultAction}
|
|
207
|
+
|
|
208
|
+
i/install [...modules] #stopEarly, install dependencies. ${installAction}
|
|
82
209
|
|
|
83
|
-
|
|
210
|
+
-t --types @bool, install package's types too, only effect node project.
|
|
84
211
|
|
|
85
|
-
|
|
212
|
+
up/upgrade [...modules] #stopEarly, upgrade dependencies. ${upgradeAction}
|
|
86
213
|
|
|
87
|
-
|
|
214
|
+
rm/remove <...modules> #stopEarly, remove dependencies. ${removeAction}
|
|
88
215
|
`;
|
|
89
216
|
async function defaultAction() {
|
|
90
|
-
await
|
|
217
|
+
await new DepManager().install();
|
|
91
218
|
}
|
|
92
219
|
async function installAction(_, opt) {
|
|
93
|
-
const
|
|
94
|
-
const installOnly = !
|
|
220
|
+
const params = opt._;
|
|
221
|
+
const installOnly = !params.length;
|
|
95
222
|
if (installOnly) {
|
|
96
|
-
await
|
|
223
|
+
await new DepManager().install(opt);
|
|
97
224
|
return;
|
|
98
225
|
}
|
|
99
|
-
await
|
|
100
|
-
if (opt.types) {
|
|
101
|
-
const typesPackages = parameters.filter((n) => !n.startsWith("-")).map((pkg) => getTypePackageName(pkg));
|
|
102
|
-
await runNpm("add", ...typesPackages, "-D");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
function getTypePackageName(pkg) {
|
|
106
|
-
const idx = pkg.lastIndexOf("@");
|
|
107
|
-
const name = idx > 0 ? pkg.slice(0, idx) : pkg;
|
|
108
|
-
if (name.includes("@")) {
|
|
109
|
-
const [scope, pkgName] = name.split("/");
|
|
110
|
-
return `@types/${scope.slice(1)}__${pkgName}`;
|
|
111
|
-
} else {
|
|
112
|
-
return `@types/${name}`;
|
|
113
|
-
}
|
|
226
|
+
await new DepManager().add(params, opt);
|
|
114
227
|
}
|
|
115
228
|
async function upgradeAction(_, opt) {
|
|
116
229
|
const params = opt._;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
230
|
+
await new DepManager().upgrade(params, opt);
|
|
231
|
+
}
|
|
232
|
+
async function removeAction(_, opt) {
|
|
233
|
+
const params = opt._;
|
|
234
|
+
await new DepManager().remove(params, opt);
|
|
121
235
|
}
|
|
122
|
-
export {
|
|
123
|
-
getTypePackageName
|
|
124
|
-
};
|
package/dist/xr.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
exec
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WA6Z2RU3.js";
|
|
5
5
|
|
|
6
6
|
// src/xr.ts
|
|
7
7
|
import { sliver } from "@0x-jerry/silver";
|
|
8
8
|
|
|
9
9
|
// src/commands/run.ts
|
|
10
10
|
import path4 from "path";
|
|
11
|
+
import pc from "picocolors";
|
|
11
12
|
|
|
12
13
|
// src/commands/run/node.ts
|
|
13
14
|
import { pathExists } from "fs-extra";
|
|
@@ -107,11 +108,17 @@ async function runScript(command, params = []) {
|
|
|
107
108
|
if (task) {
|
|
108
109
|
const env = makeEnv(await taskDetector.binaryPaths?.(cwd) || []);
|
|
109
110
|
await exec(task, params, env);
|
|
110
|
-
|
|
111
|
+
return;
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
|
-
|
|
115
|
+
const allScripts = await getAvailableCommands();
|
|
116
|
+
console.log(
|
|
117
|
+
pc.red("["),
|
|
118
|
+
pc.cyan(`${command}`),
|
|
119
|
+
pc.red("] not exists in the list: "),
|
|
120
|
+
allScripts.map((name) => pc.cyan(name)).join(", ")
|
|
121
|
+
);
|
|
115
122
|
}
|
|
116
123
|
function makeEnv(extraPaths) {
|
|
117
124
|
const env = process.env;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0x-jerry/x",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/0x-jerry/x.git"
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"dev:xr": "tsx src/xr.ts",
|
|
26
26
|
"dev:xn": "tsx src/xn.ts",
|
|
27
27
|
"dev:x": "tsx src/x.ts",
|
|
28
|
-
"test": "vitest",
|
|
29
|
-
"
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest",
|
|
30
30
|
"prepublishOnly": "npm run build",
|
|
31
31
|
"release": "x-release"
|
|
32
32
|
},
|
package/dist/chunk-O5N22U5G.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { run } from "@0x-jerry/utils/node";
|
|
4
|
-
async function exec(script, params, env) {
|
|
5
|
-
const cmd = [script, ...params].join(" ");
|
|
6
|
-
await run(cmd, env);
|
|
7
|
-
}
|
|
8
|
-
function exists(path) {
|
|
9
|
-
return existsSync(path);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
exec,
|
|
14
|
-
exists
|
|
15
|
-
};
|