@gaomingzhao666/stack-info 1.0.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/LICENSE +21 -0
- package/dist/cli.d.mts +8 -0
- package/dist/cli.mjs +208 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nano@Gaomingzhao
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/cli.d.mts
ADDED
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { defineCommand, runMain } from "citty";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import process$1 from "node:process";
|
|
5
|
+
import clipboard from "clipboardy";
|
|
6
|
+
import { box, log } from "@clack/prompts";
|
|
7
|
+
import { colors } from "consola/utils";
|
|
8
|
+
import { detectPackageManager } from "nypm";
|
|
9
|
+
import { resolve } from "pathe";
|
|
10
|
+
import { readPackageJSON } from "pkg-types";
|
|
11
|
+
import { isBun, isDeno, isMinimal } from "std-env";
|
|
12
|
+
import { stripVTControlCharacters } from "node:util";
|
|
13
|
+
import { execSync } from "node:child_process";
|
|
14
|
+
|
|
15
|
+
//#region src/utils/formatting.ts
|
|
16
|
+
const getStringWidth = (str) => {
|
|
17
|
+
const stripped = stripVTControlCharacters(str);
|
|
18
|
+
let width = 0;
|
|
19
|
+
for (const char of stripped) {
|
|
20
|
+
const code = char.codePointAt(0);
|
|
21
|
+
if (!code) continue;
|
|
22
|
+
if (code >= 65024 && code <= 65039) continue;
|
|
23
|
+
if (code >= 127744 && code <= 129535 || code >= 128512 && code <= 128591 || code >= 128640 && code <= 128767 || code >= 9728 && code <= 9983 || code >= 9984 && code <= 10175 || code >= 129280 && code <= 129535 || code >= 129648 && code <= 129791) width += 2;
|
|
24
|
+
else width += 1;
|
|
25
|
+
}
|
|
26
|
+
return width;
|
|
27
|
+
};
|
|
28
|
+
const formatInfoBox = (infoObj) => {
|
|
29
|
+
let firstColumnLength = 0;
|
|
30
|
+
let ansiFirstColumnLength = 0;
|
|
31
|
+
const entries = Object.entries(infoObj).map(([label, val]) => {
|
|
32
|
+
if (label.length > firstColumnLength) {
|
|
33
|
+
ansiFirstColumnLength = colors.bold(colors.whiteBright(label)).length + 6;
|
|
34
|
+
firstColumnLength = label.length + 6;
|
|
35
|
+
}
|
|
36
|
+
return [label, val || "-"];
|
|
37
|
+
});
|
|
38
|
+
const terminalWidth = Math.max(process$1.stdout.columns || 80, firstColumnLength) - 8;
|
|
39
|
+
let boxStr = "";
|
|
40
|
+
for (const [label, value] of entries) {
|
|
41
|
+
const formattedValue = value.replace(/\b@([^, ]+)/g, (_, r) => colors.gray(` ${r}`)).replace(/`([^`]*)`/g, (_, r) => r);
|
|
42
|
+
boxStr += `${colors.bold(colors.whiteBright(label))}`.padEnd(ansiFirstColumnLength);
|
|
43
|
+
let boxRowLength = firstColumnLength;
|
|
44
|
+
const words = formattedValue.split(" ");
|
|
45
|
+
let currentLine = "";
|
|
46
|
+
for (const word of words) {
|
|
47
|
+
const wordLength = getStringWidth(word);
|
|
48
|
+
const spaceLength = currentLine ? 1 : 0;
|
|
49
|
+
if (boxRowLength + wordLength + spaceLength > terminalWidth) {
|
|
50
|
+
if (currentLine) boxStr += colors.cyan(currentLine);
|
|
51
|
+
boxStr += `\n${" ".repeat(firstColumnLength)}`;
|
|
52
|
+
currentLine = word;
|
|
53
|
+
boxRowLength = firstColumnLength + wordLength;
|
|
54
|
+
} else {
|
|
55
|
+
currentLine += (currentLine ? " " : "") + word;
|
|
56
|
+
boxRowLength += wordLength + spaceLength;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (currentLine) boxStr += colors.cyan(currentLine);
|
|
60
|
+
boxStr += "\n";
|
|
61
|
+
}
|
|
62
|
+
return boxStr;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/utils/packageManager.ts
|
|
67
|
+
const getPackageManagerVersion = (name) => execSync(`${name} --version`).toString("utf8").trim();
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/utils/builder.ts
|
|
71
|
+
/**
|
|
72
|
+
* Detect the build tool used by the project.
|
|
73
|
+
* Order matters: modern tools first.
|
|
74
|
+
*/
|
|
75
|
+
const getBuilder = async (cwd) => {
|
|
76
|
+
const pkg = await readPackageJSON(cwd).catch(() => null);
|
|
77
|
+
if (!pkg) return null;
|
|
78
|
+
const deps = {
|
|
79
|
+
...pkg.dependencies || {},
|
|
80
|
+
...pkg.devDependencies || {}
|
|
81
|
+
};
|
|
82
|
+
const has = (name) => Boolean(deps[name]);
|
|
83
|
+
const versionOf = (name) => deps[name] ?? "-";
|
|
84
|
+
if (has("vite")) return {
|
|
85
|
+
name: has("rolldown") || has("@rolldown/core") || has("vite-rolldown") ? "Rolldown (Vite-compatible)" : "Vite",
|
|
86
|
+
version: versionOf("vite")
|
|
87
|
+
};
|
|
88
|
+
if (has("@rspack/core") || has("rspack")) return {
|
|
89
|
+
name: "Rspack",
|
|
90
|
+
version: versionOf("@rspack/core") || versionOf("rspack")
|
|
91
|
+
};
|
|
92
|
+
if (has("webpack")) return {
|
|
93
|
+
name: "Webpack",
|
|
94
|
+
version: versionOf("webpack")
|
|
95
|
+
};
|
|
96
|
+
if (has("parcel")) return {
|
|
97
|
+
name: "Parcel",
|
|
98
|
+
version: versionOf("parcel")
|
|
99
|
+
};
|
|
100
|
+
return null;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/commands/info.ts
|
|
105
|
+
const cwdArgs = { cwd: {
|
|
106
|
+
type: "string",
|
|
107
|
+
description: "Specify the working directory",
|
|
108
|
+
valueHint: "directory",
|
|
109
|
+
default: "."
|
|
110
|
+
} };
|
|
111
|
+
var info_default = defineCommand({
|
|
112
|
+
meta: {
|
|
113
|
+
name: "info",
|
|
114
|
+
description: "Get information about your project"
|
|
115
|
+
},
|
|
116
|
+
args: { ...cwdArgs },
|
|
117
|
+
run: async (ctx) => {
|
|
118
|
+
const cwd = resolve(ctx.args.cwd || process$1.cwd());
|
|
119
|
+
const { dependencies = {}, devDependencies = {} } = await readPackageJSON(cwd).catch(() => ({}));
|
|
120
|
+
const allDeps = {
|
|
121
|
+
...dependencies,
|
|
122
|
+
...devDependencies
|
|
123
|
+
};
|
|
124
|
+
const getDepVersion = (name) => allDeps[name] || "-";
|
|
125
|
+
const frameworks = [
|
|
126
|
+
{
|
|
127
|
+
name: "Vue",
|
|
128
|
+
pkg: "vue"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
name: "React",
|
|
132
|
+
pkg: "react"
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "Svelte",
|
|
136
|
+
pkg: "svelte"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "Angular",
|
|
140
|
+
pkg: "@angular/core"
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: "Nuxt",
|
|
144
|
+
pkg: "nuxt"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "Next",
|
|
148
|
+
pkg: "next"
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "Astro",
|
|
152
|
+
pkg: "astro"
|
|
153
|
+
}
|
|
154
|
+
].filter((f) => allDeps[f.pkg]).map((f) => `${f.name}@${getDepVersion(f.pkg)}`).join(", ") || "None detected";
|
|
155
|
+
let packageManager = (await detectPackageManager(cwd))?.name;
|
|
156
|
+
if (packageManager) packageManager += `@${getPackageManagerVersion(packageManager)}`;
|
|
157
|
+
const builder = await getBuilder(cwd);
|
|
158
|
+
const builderInfo = builder ? `${builder.name}@${builder.version}` : "None detected";
|
|
159
|
+
const osType = os.type();
|
|
160
|
+
const infoObj = {
|
|
161
|
+
"Project root": cwd,
|
|
162
|
+
"Operating system": osType === "Darwin" ? `macOS ${os.release()}` : osType === "Windows_NT" ? `Windows ${os.release()}` : `${osType} ${os.release()}`,
|
|
163
|
+
CPU: `${os.cpus()[0]?.model || "unknown"} (${os.cpus().length} cores)`,
|
|
164
|
+
...isBun ? { "Bun version": Bun?.version } : isDeno ? { "Deno version": Deno?.version.deno } : { "Node.js version": process$1.version },
|
|
165
|
+
"Package manager": packageManager ?? "unknown",
|
|
166
|
+
Builder: builderInfo,
|
|
167
|
+
Frameworks: frameworks
|
|
168
|
+
};
|
|
169
|
+
const boxStr = formatInfoBox(infoObj);
|
|
170
|
+
let firstColumnLength = 0;
|
|
171
|
+
let secondColumnLength = 0;
|
|
172
|
+
const entries = Object.entries(infoObj).map(([label, val]) => {
|
|
173
|
+
firstColumnLength = Math.max(firstColumnLength, label.length + 4);
|
|
174
|
+
secondColumnLength = Math.max(secondColumnLength, String(val).length + 2);
|
|
175
|
+
return [label, String(val || "-")];
|
|
176
|
+
});
|
|
177
|
+
let copyStr = `| ${" ".repeat(firstColumnLength)} | ${" ".repeat(secondColumnLength)} |\n| ${"-".repeat(firstColumnLength)} | ${"-".repeat(secondColumnLength)} |\n`;
|
|
178
|
+
for (const [label, value] of entries) if (!isMinimal) copyStr += `| ${`**${label}**`.padEnd(firstColumnLength)} | ${(value.includes("`") ? value : `\`${value}\``).padEnd(secondColumnLength)} |\n`;
|
|
179
|
+
if (!isMinimal && await clipboard.write(copyStr).then(() => true).catch(() => false)) box(`\n${boxStr}`, ` Project info ${colors.gray("(copied to clipboard)")}`, {
|
|
180
|
+
contentAlign: "left",
|
|
181
|
+
titleAlign: "left",
|
|
182
|
+
width: "auto",
|
|
183
|
+
titlePadding: 2,
|
|
184
|
+
contentPadding: 2,
|
|
185
|
+
rounded: true
|
|
186
|
+
});
|
|
187
|
+
else log.info(`Project info:\n${copyStr}`);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/index.ts
|
|
193
|
+
const main = defineCommand({
|
|
194
|
+
meta: {
|
|
195
|
+
name: "stack-info",
|
|
196
|
+
version: "1.0.0",
|
|
197
|
+
description: "A cross-platform, framework-agnostic CLI for inspecting web project stacks in command line."
|
|
198
|
+
},
|
|
199
|
+
subCommands: { info: info_default }
|
|
200
|
+
});
|
|
201
|
+
const run = async () => await runMain(main);
|
|
202
|
+
run().catch((err) => {
|
|
203
|
+
console.error(err);
|
|
204
|
+
process.exit(1);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
//#endregion
|
|
208
|
+
export { main, run };
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gaomingzhao666/stack-info",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A cross-platform, framework-agnostic CLI for inspecting web project stacks in command line.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"info",
|
|
8
|
+
"project-info",
|
|
9
|
+
"command-line",
|
|
10
|
+
"tool",
|
|
11
|
+
"web",
|
|
12
|
+
"framework",
|
|
13
|
+
"frontend",
|
|
14
|
+
"stack",
|
|
15
|
+
"vite",
|
|
16
|
+
"builder",
|
|
17
|
+
"printer",
|
|
18
|
+
"command-line"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "gaomingzhao <gaomingzhao666@outlook.com> (https://github.com/gaomingzhao)",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/cli.mjs",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "tsdown",
|
|
26
|
+
"prepack": "pnpm build"
|
|
27
|
+
},
|
|
28
|
+
"bin": {
|
|
29
|
+
"stack-info": "./dist/cli.mjs"
|
|
30
|
+
},
|
|
31
|
+
"types": "./dist/cli.d.mts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
34
|
+
],
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@clack/prompts": "^1.0.0",
|
|
40
|
+
"citty": "^0.2.0",
|
|
41
|
+
"clipboardy": "^5.2.1",
|
|
42
|
+
"consola": "^3.4.2",
|
|
43
|
+
"nypm": "^0.6.5",
|
|
44
|
+
"pathe": "^2.0.3",
|
|
45
|
+
"pkg-types": "^2.3.0",
|
|
46
|
+
"semver": "^7.7.4",
|
|
47
|
+
"std-env": "^3.10.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/clipboardy": "^2.0.4",
|
|
51
|
+
"@types/node": "^25.2.1",
|
|
52
|
+
"@types/semver": "^7.7.1",
|
|
53
|
+
"tsdown": "^0.20.3",
|
|
54
|
+
"typescript": "^5.9.3"
|
|
55
|
+
}
|
|
56
|
+
}
|