@harvey0379/vite-ts-cli 0.1.0 → 0.1.1
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/README.md +19 -0
- package/dist/index.js +85 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,12 +16,31 @@ pnpm run build
|
|
|
16
16
|
node dist/index.js --name=Harvey
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
输出当前环境版本信息:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
node dist/index.js --env-info
|
|
23
|
+
```
|
|
24
|
+
|
|
19
25
|
或通过 bin 名称执行(全局安装或 npm link 后):
|
|
20
26
|
|
|
21
27
|
```bash
|
|
22
28
|
harvey-cli --name=Harvey
|
|
23
29
|
```
|
|
24
30
|
|
|
31
|
+
```bash
|
|
32
|
+
harvey-cli --env-info
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`--env-info` 会输出当前环境中常见开发工具的版本信息,包括:
|
|
36
|
+
|
|
37
|
+
- Java
|
|
38
|
+
- Python
|
|
39
|
+
- Node.js
|
|
40
|
+
- npm
|
|
41
|
+
- pnpm
|
|
42
|
+
- Go
|
|
43
|
+
|
|
25
44
|
## 发布流程
|
|
26
45
|
|
|
27
46
|
### 1) GitHub Release
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
2
3
|
//#region src/index.ts
|
|
4
|
+
function readVersion({ label, command, args, useStderr = false }) {
|
|
5
|
+
const result = spawnSync(command, args, {
|
|
6
|
+
encoding: "utf8",
|
|
7
|
+
stdio: [
|
|
8
|
+
"ignore",
|
|
9
|
+
"pipe",
|
|
10
|
+
"pipe"
|
|
11
|
+
]
|
|
12
|
+
});
|
|
13
|
+
if (result.error) return `${label}: not installed`;
|
|
14
|
+
if (result.status !== 0) return `${label}: unavailable`;
|
|
15
|
+
return `${label}: ${(useStderr ? result.stderr : result.stdout).trim().split(/\r?\n/).map((line) => line.trim()).find(Boolean) ?? "unknown version"}`;
|
|
16
|
+
}
|
|
17
|
+
function readPythonVersion() {
|
|
18
|
+
for (const tool of [{
|
|
19
|
+
label: "Python",
|
|
20
|
+
command: "python3",
|
|
21
|
+
args: ["--version"]
|
|
22
|
+
}, {
|
|
23
|
+
label: "Python",
|
|
24
|
+
command: "python",
|
|
25
|
+
args: ["--version"]
|
|
26
|
+
}]) {
|
|
27
|
+
const result = spawnSync(tool.command, tool.args, {
|
|
28
|
+
encoding: "utf8",
|
|
29
|
+
stdio: [
|
|
30
|
+
"ignore",
|
|
31
|
+
"pipe",
|
|
32
|
+
"pipe"
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
if (!result.error && result.status === 0) {
|
|
36
|
+
const firstLine = (result.stdout.trim() || result.stderr.trim()).split(/\r?\n/).map((line) => line.trim()).find(Boolean);
|
|
37
|
+
return `${tool.label}: ${firstLine ?? "unknown version"}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return "Python: not installed";
|
|
41
|
+
}
|
|
42
|
+
function printEnvironmentVersions() {
|
|
43
|
+
const versions = [
|
|
44
|
+
readVersion({
|
|
45
|
+
label: "Java",
|
|
46
|
+
command: "java",
|
|
47
|
+
args: ["-version"],
|
|
48
|
+
useStderr: true
|
|
49
|
+
}),
|
|
50
|
+
readPythonVersion(),
|
|
51
|
+
readVersion({
|
|
52
|
+
label: "Node.js",
|
|
53
|
+
command: "node",
|
|
54
|
+
args: ["--version"]
|
|
55
|
+
}),
|
|
56
|
+
readVersion({
|
|
57
|
+
label: "npm",
|
|
58
|
+
command: "npm",
|
|
59
|
+
args: ["--version"]
|
|
60
|
+
}),
|
|
61
|
+
readVersion({
|
|
62
|
+
label: "pnpm",
|
|
63
|
+
command: "pnpm",
|
|
64
|
+
args: ["--version"]
|
|
65
|
+
}),
|
|
66
|
+
readVersion({
|
|
67
|
+
label: "Go",
|
|
68
|
+
command: "go",
|
|
69
|
+
args: ["version"]
|
|
70
|
+
})
|
|
71
|
+
];
|
|
72
|
+
console.log("Environment versions:");
|
|
73
|
+
for (const version of versions) console.log(`- ${version}`);
|
|
74
|
+
}
|
|
75
|
+
function printHelp() {
|
|
76
|
+
console.log("Usage: harvey-cli [--name=<name>] [--env-info]");
|
|
77
|
+
console.log("");
|
|
78
|
+
console.log("Options:");
|
|
79
|
+
console.log(" --name=<name> Print a greeting message.");
|
|
80
|
+
console.log(" --env-info Print version information for the current environment.");
|
|
81
|
+
console.log(" -h, --help Show this help message.");
|
|
82
|
+
}
|
|
3
83
|
function run() {
|
|
4
84
|
const args = process.argv.slice(2);
|
|
5
85
|
const nameArg = args.find((arg) => arg.startsWith("--name="));
|
|
6
86
|
const name = nameArg ? nameArg.split("=")[1] : "world";
|
|
7
87
|
if (args.includes("--help") || args.includes("-h")) {
|
|
8
|
-
|
|
88
|
+
printHelp();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (args.includes("--env-info")) {
|
|
92
|
+
printEnvironmentVersions();
|
|
9
93
|
return;
|
|
10
94
|
}
|
|
11
95
|
console.log(`Hello, ${name}! This CLI is built with Vite + TypeScript.`);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\n\ntype ToolVersion = {\n label: string;\n command: string;\n args: string[];\n useStderr?: boolean;\n};\n\nfunction readVersion({ label, command, args, useStderr = false }: ToolVersion): string {\n const result = spawnSync(command, args, {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n if (result.error) {\n return `${label}: not installed`;\n }\n\n if (result.status !== 0) {\n return `${label}: unavailable`;\n }\n\n const output = (useStderr ? result.stderr : result.stdout).trim();\n const firstLine = output\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find(Boolean);\n\n return `${label}: ${firstLine ?? \"unknown version\"}`;\n}\n\nfunction readPythonVersion(): string {\n const pythonCommands: ToolVersion[] = [\n { label: \"Python\", command: \"python3\", args: [\"--version\"] },\n { label: \"Python\", command: \"python\", args: [\"--version\"] },\n ];\n\n for (const tool of pythonCommands) {\n const result = spawnSync(tool.command, tool.args, {\n encoding: \"utf8\",\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n });\n\n if (!result.error && result.status === 0) {\n const output = result.stdout.trim() || result.stderr.trim();\n const firstLine = output\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find(Boolean);\n\n return `${tool.label}: ${firstLine ?? \"unknown version\"}`;\n }\n }\n\n return \"Python: not installed\";\n}\n\nfunction printEnvironmentVersions(): void {\n const versions = [\n readVersion({ label: \"Java\", command: \"java\", args: [\"-version\"], useStderr: true }),\n readPythonVersion(),\n readVersion({ label: \"Node.js\", command: \"node\", args: [\"--version\"] }),\n readVersion({ label: \"npm\", command: \"npm\", args: [\"--version\"] }),\n readVersion({ label: \"pnpm\", command: \"pnpm\", args: [\"--version\"] }),\n readVersion({ label: \"Go\", command: \"go\", args: [\"version\"] }),\n ];\n\n console.log(\"Environment versions:\");\n for (const version of versions) {\n console.log(`- ${version}`);\n }\n}\n\nfunction printHelp(): void {\n console.log(\"Usage: harvey-cli [--name=<name>] [--env-info]\");\n console.log(\"\");\n console.log(\"Options:\");\n console.log(\" --name=<name> Print a greeting message.\");\n console.log(\" --env-info Print version information for the current environment.\");\n console.log(\" -h, --help Show this help message.\");\n}\n\nfunction run(): void {\n const args = process.argv.slice(2);\n const nameArg = args.find((arg) => arg.startsWith(\"--name=\"));\n const name = nameArg ? nameArg.split(\"=\")[1] : \"world\";\n\n if (args.includes(\"--help\") || args.includes(\"-h\")) {\n printHelp();\n return;\n }\n\n if (args.includes(\"--env-info\")) {\n printEnvironmentVersions();\n return;\n }\n\n console.log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