@0x-jerry/x 2.12.5 → 2.12.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.
- package/dist/{chunk-BNFTX4BH.js → chunk-LBTVWMZC.js} +1 -1
- package/dist/chunk-RDZVDWJQ.js +81 -0
- package/dist/x.js +1 -1
- package/dist/xn.js +15 -42
- package/dist/xr.js +20 -18
- package/package.json +23 -13
- package/readme.md +33 -3
- package/dist/chunk-ELIYGHQS.js +0 -25
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { exec as _exec } from "@0x-jerry/utils/node";
|
|
4
|
+
async function exec(script, params, opt) {
|
|
5
|
+
const cmd = [script, ...params].join(" ");
|
|
6
|
+
await _exec(cmd, opt);
|
|
7
|
+
}
|
|
8
|
+
function exists(path2) {
|
|
9
|
+
return existsSync(path2);
|
|
10
|
+
}
|
|
11
|
+
function flagOptionToStringArray(opt) {
|
|
12
|
+
return Object.entries(opt).flatMap(([_key, value]) => {
|
|
13
|
+
const key = (_key.length === 1 ? "-" : "--") + _key;
|
|
14
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
15
|
+
return [key, String(value)];
|
|
16
|
+
}
|
|
17
|
+
return [key];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/commands/utils/node.ts
|
|
22
|
+
import { readFile } from "fs/promises";
|
|
23
|
+
import path from "path";
|
|
24
|
+
async function detectPackageRoot(cwd, subProjectInfo) {
|
|
25
|
+
const pkg = await getPkgJson(cwd);
|
|
26
|
+
if (!pkg) {
|
|
27
|
+
return detectParentDir(subProjectInfo);
|
|
28
|
+
}
|
|
29
|
+
const pm = await detectPkgManagerCommand(cwd);
|
|
30
|
+
const info = {
|
|
31
|
+
pkgDir: cwd,
|
|
32
|
+
package: pkg,
|
|
33
|
+
pm,
|
|
34
|
+
subProject: subProjectInfo
|
|
35
|
+
};
|
|
36
|
+
if (pm) {
|
|
37
|
+
return info;
|
|
38
|
+
}
|
|
39
|
+
return detectParentDir(info);
|
|
40
|
+
async function detectParentDir(subProjectInfo2) {
|
|
41
|
+
const parentDir = path.dirname(cwd);
|
|
42
|
+
if (parentDir === cwd) {
|
|
43
|
+
return subProjectInfo2 ?? null;
|
|
44
|
+
}
|
|
45
|
+
return detectPackageRoot(parentDir, subProjectInfo2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function detectPkgManagerCommand(cwd = process.cwd()) {
|
|
49
|
+
const pnpmLockFile = path.join(cwd, "pnpm-lock.yaml");
|
|
50
|
+
if (exists(pnpmLockFile)) {
|
|
51
|
+
return "pnpm";
|
|
52
|
+
}
|
|
53
|
+
const bunLockFile = path.join(cwd, "bun.lock");
|
|
54
|
+
if (exists(bunLockFile)) {
|
|
55
|
+
return "bun";
|
|
56
|
+
}
|
|
57
|
+
const yarnLockFile = path.join(cwd, "yarn.lock");
|
|
58
|
+
if (exists(yarnLockFile)) {
|
|
59
|
+
return "yarn";
|
|
60
|
+
}
|
|
61
|
+
const jsonLockFile = path.join(cwd, "package-lock.json");
|
|
62
|
+
if (exists(jsonLockFile)) {
|
|
63
|
+
return "npm";
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
async function getPkgJson(cwd = process.cwd()) {
|
|
68
|
+
const jsonFile = path.join(cwd, "package.json");
|
|
69
|
+
try {
|
|
70
|
+
const txt = await readFile(jsonFile, { encoding: "utf-8" });
|
|
71
|
+
return JSON.parse(txt);
|
|
72
|
+
} catch (_error) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
exec,
|
|
79
|
+
flagOptionToStringArray,
|
|
80
|
+
detectPackageRoot
|
|
81
|
+
};
|
package/dist/x.js
CHANGED
package/dist/xn.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
detectPackageRoot,
|
|
3
4
|
exec,
|
|
4
|
-
exists,
|
|
5
5
|
flagOptionToStringArray
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-RDZVDWJQ.js";
|
|
7
7
|
import {
|
|
8
8
|
version
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-LBTVWMZC.js";
|
|
10
10
|
|
|
11
11
|
// src/xn.ts
|
|
12
12
|
import { sliver } from "@0x-jerry/silver";
|
|
@@ -34,13 +34,12 @@ var DenoDependencyManager = class {
|
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
// src/commands/dep/node.ts
|
|
37
|
-
import { readFile } from "fs/promises";
|
|
38
|
-
import path2, { join } from "path";
|
|
39
|
-
import { pathExists as pathExists2 } from "fs-extra";
|
|
40
37
|
import pc from "picocolors";
|
|
41
38
|
var NodeDependencyManager = class {
|
|
42
39
|
async check() {
|
|
43
|
-
|
|
40
|
+
const cwd = process.cwd();
|
|
41
|
+
const pkgInfo = await detectPackageRoot(cwd);
|
|
42
|
+
return !!pkgInfo;
|
|
44
43
|
}
|
|
45
44
|
async install(option) {
|
|
46
45
|
await runDepManagerCommand("install");
|
|
@@ -100,7 +99,9 @@ var depInstallerCommandMapper = {
|
|
|
100
99
|
}
|
|
101
100
|
};
|
|
102
101
|
async function runDepManagerCommand(action, ...params) {
|
|
103
|
-
|
|
102
|
+
const cwd = process.cwd();
|
|
103
|
+
const pkgInfo = await detectPackageRoot(cwd);
|
|
104
|
+
if (!pkgInfo) {
|
|
104
105
|
console.log(
|
|
105
106
|
yellow(
|
|
106
107
|
`Can't find package.json! Please ensure that current path is a node project.`
|
|
@@ -108,37 +109,9 @@ async function runDepManagerCommand(action, ...params) {
|
|
|
108
109
|
);
|
|
109
110
|
return;
|
|
110
111
|
}
|
|
111
|
-
const
|
|
112
|
-
const actionName = depInstallerCommandMapper[action][
|
|
113
|
-
await exec(
|
|
114
|
-
}
|
|
115
|
-
async function detectPkgManagerCommand(cwd = process.cwd()) {
|
|
116
|
-
const pnpmLockFile = join(cwd, "pnpm-lock.yaml");
|
|
117
|
-
if (exists(pnpmLockFile)) {
|
|
118
|
-
return "pnpm";
|
|
119
|
-
}
|
|
120
|
-
const bunLockFile = join(cwd, "bun.lock");
|
|
121
|
-
if (exists(bunLockFile)) {
|
|
122
|
-
return "bun";
|
|
123
|
-
}
|
|
124
|
-
const yarnLockFile = join(cwd, "yarn.lock");
|
|
125
|
-
if (exists(yarnLockFile)) {
|
|
126
|
-
return "yarn";
|
|
127
|
-
}
|
|
128
|
-
const jsonLockFile = join(cwd, "package-lock.json");
|
|
129
|
-
if (exists(jsonLockFile)) {
|
|
130
|
-
return "npm";
|
|
131
|
-
}
|
|
132
|
-
return "pnpm";
|
|
133
|
-
}
|
|
134
|
-
async function getPkgJson(cwd = process.cwd()) {
|
|
135
|
-
const jsonFile = join(cwd, "package.json");
|
|
136
|
-
try {
|
|
137
|
-
const txt = await readFile(jsonFile, { encoding: "utf-8" });
|
|
138
|
-
return JSON.parse(txt);
|
|
139
|
-
} catch (_error) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
112
|
+
const pm = pkgInfo.pm || "pnpm";
|
|
113
|
+
const actionName = depInstallerCommandMapper[action][pm];
|
|
114
|
+
await exec(pm, [actionName, ...params]);
|
|
142
115
|
}
|
|
143
116
|
function getTypePackageName(pkg) {
|
|
144
117
|
const idx = pkg.lastIndexOf("@");
|
|
@@ -151,11 +124,11 @@ function getTypePackageName(pkg) {
|
|
|
151
124
|
}
|
|
152
125
|
|
|
153
126
|
// src/commands/dep/rust.ts
|
|
154
|
-
import
|
|
155
|
-
import { pathExists as
|
|
127
|
+
import path2 from "path";
|
|
128
|
+
import { pathExists as pathExists2 } from "fs-extra";
|
|
156
129
|
var RustDependencyManager = class {
|
|
157
130
|
check() {
|
|
158
|
-
return
|
|
131
|
+
return pathExists2(path2.join(process.cwd(), "Cargo.toml"));
|
|
159
132
|
}
|
|
160
133
|
async install(option) {
|
|
161
134
|
await exec("cargo", ["check"]);
|
package/dist/xr.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
detectPackageRoot,
|
|
3
4
|
exec
|
|
4
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-RDZVDWJQ.js";
|
|
5
6
|
import {
|
|
6
7
|
version
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-LBTVWMZC.js";
|
|
8
9
|
|
|
9
10
|
// src/xr.ts
|
|
10
11
|
import { sliver } from "@0x-jerry/silver";
|
|
@@ -19,8 +20,9 @@ import path from "path";
|
|
|
19
20
|
import { pathExists } from "fs-extra";
|
|
20
21
|
import { parse } from "jsonc-parser";
|
|
21
22
|
var DenoTaskDetecter = class {
|
|
22
|
-
check(cwd) {
|
|
23
|
-
|
|
23
|
+
async check(cwd) {
|
|
24
|
+
const has = await (pathExists(path.join(cwd, "deno.json")) || pathExists(path.join(cwd, "deno.jsonc")));
|
|
25
|
+
return has ? cwd : void 0;
|
|
24
26
|
}
|
|
25
27
|
async task(cwd, taskName) {
|
|
26
28
|
return (await this.tasks(cwd))[taskName];
|
|
@@ -41,7 +43,7 @@ var DenoTaskDetecter = class {
|
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
// src/commands/run/node.ts
|
|
44
|
-
import { readdir
|
|
46
|
+
import { readdir } from "fs/promises";
|
|
45
47
|
import path2 from "path";
|
|
46
48
|
import { pathExists as pathExists2 } from "fs-extra/esm";
|
|
47
49
|
var NodeTaskDetecter = class {
|
|
@@ -57,17 +59,16 @@ var NodeTaskDetecter = class {
|
|
|
57
59
|
} while (dir !== path2.resolve(dir, ".."));
|
|
58
60
|
return envPaths;
|
|
59
61
|
}
|
|
60
|
-
check(cwd) {
|
|
61
|
-
|
|
62
|
+
async check(cwd) {
|
|
63
|
+
const pkgInfo = await detectPackageRoot(cwd);
|
|
64
|
+
return pkgInfo?.pkgDir;
|
|
62
65
|
}
|
|
63
66
|
async task(cwd, taskName) {
|
|
64
67
|
return (await this.tasks(cwd))[taskName];
|
|
65
68
|
}
|
|
66
69
|
async tasks(cwd) {
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const json = JSON.parse(text);
|
|
70
|
-
const tasks = json.scripts || {};
|
|
70
|
+
const pkgInfo = await detectPackageRoot(cwd);
|
|
71
|
+
const tasks = pkgInfo?.package.scripts || {};
|
|
71
72
|
return tasks;
|
|
72
73
|
}
|
|
73
74
|
};
|
|
@@ -91,8 +92,8 @@ async function getBinariesPairs() {
|
|
|
91
92
|
import path3 from "path";
|
|
92
93
|
import { pathExists as pathExists3 } from "fs-extra";
|
|
93
94
|
var RustTaskDetecter = class {
|
|
94
|
-
check(cwd) {
|
|
95
|
-
return pathExists3(path3.join(cwd, "Cargo.toml"));
|
|
95
|
+
async check(cwd) {
|
|
96
|
+
return await pathExists3(path3.join(cwd, "Cargo.toml")) ? cwd : void 0;
|
|
96
97
|
}
|
|
97
98
|
async task(_cwd, _taskName) {
|
|
98
99
|
return "cargo run";
|
|
@@ -106,13 +107,14 @@ async function runScript(command, params = []) {
|
|
|
106
107
|
new DenoTaskDetecter(),
|
|
107
108
|
new RustTaskDetecter()
|
|
108
109
|
];
|
|
109
|
-
|
|
110
|
+
let cwd = process.cwd();
|
|
110
111
|
for (const taskDetector of taskDetectors) {
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
const workspaceDir = await taskDetector.check(cwd);
|
|
113
|
+
if (workspaceDir) {
|
|
114
|
+
const task = await taskDetector.task(workspaceDir, command);
|
|
113
115
|
if (task) {
|
|
114
|
-
const env = makeEnv(await taskDetector.binaryPaths?.(
|
|
115
|
-
await exec(task, params, { env });
|
|
116
|
+
const env = makeEnv(await taskDetector.binaryPaths?.(workspaceDir) || []);
|
|
117
|
+
await exec(task, params, { env, cwd: workspaceDir });
|
|
116
118
|
return;
|
|
117
119
|
}
|
|
118
120
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0x-jerry/x",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/0x-jerry/x.git"
|
|
@@ -8,6 +8,16 @@
|
|
|
8
8
|
"author": "Jerry Wang <x.jerry.wang@gmail.com>",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"type": "module",
|
|
11
|
+
"description": "Some useful command for myself.",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"directories": {
|
|
14
|
+
"test": "tests"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [],
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/0x-jerry/x/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/0x-jerry/x#readme",
|
|
11
21
|
"publishConfig": {
|
|
12
22
|
"access": "public",
|
|
13
23
|
"registry": "https://registry.npmjs.org"
|
|
@@ -47,30 +57,30 @@
|
|
|
47
57
|
},
|
|
48
58
|
"dependencies": {
|
|
49
59
|
"@0x-jerry/silver": "^1.2.4",
|
|
50
|
-
"@0x-jerry/utils": "^
|
|
60
|
+
"@0x-jerry/utils": "^6.2.0",
|
|
51
61
|
"decompress": "^4.2.1",
|
|
52
|
-
"fs-extra": "^11.3.
|
|
53
|
-
"global-agent": "^
|
|
54
|
-
"got": "^14.6.
|
|
62
|
+
"fs-extra": "^11.3.3",
|
|
63
|
+
"global-agent": "^4.1.2",
|
|
64
|
+
"got": "^14.6.6",
|
|
55
65
|
"jsonc-parser": "^3.3.1",
|
|
56
|
-
"ora": "^9.
|
|
66
|
+
"ora": "^9.3.0",
|
|
57
67
|
"picocolors": "^1.1.1",
|
|
58
68
|
"prompts": "^2.4.2",
|
|
59
69
|
"strip-json-comments": "^5.0.3",
|
|
60
|
-
"tsx": "^4.
|
|
61
|
-
"yaml": "^2.8.
|
|
70
|
+
"tsx": "^4.21.0",
|
|
71
|
+
"yaml": "^2.8.2"
|
|
62
72
|
},
|
|
63
73
|
"devDependencies": {
|
|
64
|
-
"@0x-jerry/x-release": "^
|
|
65
|
-
"@biomejs/biome": "^2.
|
|
74
|
+
"@0x-jerry/x-release": "^3.0.1",
|
|
75
|
+
"@biomejs/biome": "^2.4.4",
|
|
66
76
|
"@types/decompress": "^4.2.7",
|
|
67
77
|
"@types/fs-extra": "^11.0.4",
|
|
68
78
|
"@types/global-agent": "^3.0.0",
|
|
69
|
-
"@types/node": "^
|
|
79
|
+
"@types/node": "^25.3.1",
|
|
70
80
|
"@types/prompts": "^2.4.9",
|
|
71
|
-
"@vitest/coverage-v8": "^4.0.
|
|
81
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
72
82
|
"tsup": "^8.5.1",
|
|
73
83
|
"typescript": "^5.9.3",
|
|
74
|
-
"vitest": "^4.0.
|
|
84
|
+
"vitest": "^4.0.18"
|
|
75
85
|
}
|
|
76
86
|
}
|
package/readme.md
CHANGED
|
@@ -31,9 +31,38 @@ xr dev
|
|
|
31
31
|
deno run -A main.ts
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
`xr` can execute js/ts file directly, also support import any `string/yaml/jsonc` file directly with import attribute.
|
|
35
|
+
|
|
36
|
+
Example:
|
|
37
|
+
|
|
38
|
+
`script.ts`
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const count: number = 3;
|
|
42
|
+
console.log(count)
|
|
43
|
+
|
|
44
|
+
import textData from './test.txt' with { type: 'text' }
|
|
45
|
+
console.log(textData) // => typeof textData === 'string'
|
|
46
|
+
|
|
47
|
+
import yamlData from './test.yaml' with { type: 'yaml' }
|
|
48
|
+
console.log(yamlData) // => typeof yamlData === 'object'
|
|
49
|
+
|
|
50
|
+
import jsoncData from './test.jsonc' with { type: 'jsonc' }
|
|
51
|
+
console.log(jsoncData) // => typeof jsoncData === 'object'
|
|
52
|
+
|
|
53
|
+
import sqlStr from './files/test.sql' with { type: 'text' }
|
|
54
|
+
console.log(sqlStr) // => typeof sqlStr === 'string'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Execute it:
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
xr ./script.ts
|
|
61
|
+
```
|
|
62
|
+
|
|
34
63
|
## Dependency Manager `xn`
|
|
35
64
|
|
|
36
|
-
`xn` command can install modules by detect the correct tool, it detects lockfile to decide which dependency manager
|
|
65
|
+
`xn` command can install modules by detect the correct tool automatically, it detects lockfile to decide which dependency manager tool should be used.
|
|
37
66
|
|
|
38
67
|
Example: install packages in a node project with `pnpm-lock.yaml`
|
|
39
68
|
|
|
@@ -85,11 +114,12 @@ cargo remove log
|
|
|
85
114
|
|
|
86
115
|
## Command Completions
|
|
87
116
|
|
|
88
|
-
|
|
117
|
+
This feature only support zsh.
|
|
118
|
+
|
|
119
|
+
Add those code to `~/.zshrc`
|
|
89
120
|
|
|
90
121
|
```zsh
|
|
91
122
|
source <(x completion)
|
|
92
123
|
source <(xr completion)
|
|
93
124
|
source <(xn completion)
|
|
94
125
|
```
|
|
95
|
-
|
package/dist/chunk-ELIYGHQS.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { exec as _exec } from "@0x-jerry/utils/node";
|
|
4
|
-
async function exec(script, params, opt) {
|
|
5
|
-
const cmd = [script, ...params].join(" ");
|
|
6
|
-
await _exec(cmd, opt);
|
|
7
|
-
}
|
|
8
|
-
function exists(path) {
|
|
9
|
-
return existsSync(path);
|
|
10
|
-
}
|
|
11
|
-
function flagOptionToStringArray(opt) {
|
|
12
|
-
return Object.entries(opt).flatMap(([_key, value]) => {
|
|
13
|
-
const key = (_key.length === 1 ? "-" : "--") + _key;
|
|
14
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
15
|
-
return [key, String(value)];
|
|
16
|
-
}
|
|
17
|
-
return [key];
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
exec,
|
|
23
|
-
exists,
|
|
24
|
-
flagOptionToStringArray
|
|
25
|
-
};
|