Commit 3a0b9f28 by liimin

fix(cli): 修复构建产物路径并添加全局链接功能

修改构建配置以统一输出文件命名格式,为CLI添加shebang支持
更新postinstall脚本实现安装后自动全局链接
同步更新README文档说明全局使用方式
1 parent 1a666996
...@@ -171,6 +171,20 @@ Windows 提示:如 `--ui` 名称含连字符或可能被 Shell 误解析,推 ...@@ -171,6 +171,20 @@ Windows 提示:如 `--ui` 名称含连字符或可能被 Shell 误解析,推
- Windows:`where venus` 查看命令路径;确保 `pnpm bin -g` 输出的全局 bin 目录已在系统 PATH 中。 - Windows:`where venus` 查看命令路径;确保 `pnpm bin -g` 输出的全局 bin 目录已在系统 PATH 中。
#### 安装后全局可用提示(Windows / 跨终端)
- 为了做到“clone → pnpm install → 直接使用 `venus` 全局命令”,请先在本机执行一次:
- `pnpm setup`(将 `PNPM_HOME` 加入系统 PATH)
- 关闭并重新打开终端,使新的 PATH 生效(PowerShell / CMD / Git Bash 均需)
- 本仓库的 `postinstall` 已自动执行构建并全局链接 CLI:
- `node scripts/build.js && pnpm -C packages/cli link --global`
- 验证:
- `pnpm bin --global` 应返回 `C:\Users\<YourUser>\AppData\Local\pnpm`
- `where venus`(PowerShell/CMD)或 `which venus`(Git Bash)应能找到 `venus`
- 运行 `venus --help` 查看帮助
提示:如果不希望依赖全局 PATH,在工作区内始终可以使用:`pnpm exec venus ...` 或 `pnpm venus ...`。
### 发布到 npm(可选) ### 发布到 npm(可选)
如需发布以便团队安装使用: 如需发布以便团队安装使用:
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"prepare": "husky", "prepare": "husky",
"precommit": "lint-staged", "precommit": "lint-staged",
"build": "venus build", "build": "venus build",
"postinstall": "node scripts/build.js", "postinstall": "node scripts/build.js && pnpm -C packages/cli link --global",
"venus": "venus" "venus": "venus"
}, },
"config": { "config": {
......
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"version": "0.0.1", "version": "0.0.1",
"description": "Venus CLI helpers", "description": "Venus CLI helpers",
"type": "commonjs", "type": "commonjs",
"main": "./dist/index.cjs", "main": "./dist/index.cjs.js",
"module": "./dist/index.mjs", "module": "./dist/index.esm.js",
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"scripts": { "scripts": {
"prepare": "node ../../scripts/buildSingle.js cli" "prepare": "node ../../scripts/buildSingle.js cli"
...@@ -13,12 +13,13 @@ ...@@ -13,12 +13,13 @@
"exports": { "exports": {
".": { ".": {
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"import": "./dist/index.mjs", "import": "./dist/index.esm.js",
"require": "./dist/index.cjs" "require": "./dist/index.cjs.js"
} },
"./dist/*": "./dist/*"
}, },
"bin": { "bin": {
"venus": "./dist/index.cjs" "venus": "./dist/index.cjs.js"
}, },
"files": [ "files": [
"dist", "dist",
......
...@@ -82,10 +82,9 @@ export async function getRollupConfig(root) { ...@@ -82,10 +82,9 @@ export async function getRollupConfig(root) {
}; };
const output = []; const output = [];
for (const format of formats) { for (const format of formats) {
const ext = format === "cjs" ? "cjs" : format === "esm" ? "mjs" : "js";
const outputItem = { const outputItem = {
format, format,
file: path.resolve(dist, `index.${ext}`), file: path.resolve(dist, `index.${format}.js`),
sourcemap: true, sourcemap: true,
exports: "named", exports: "named",
globals: isVue ? { vue: "Vue" } : {} globals: isVue ? { vue: "Vue" } : {}
...@@ -93,6 +92,11 @@ export async function getRollupConfig(root) { ...@@ -93,6 +92,11 @@ export async function getRollupConfig(root) {
if (format === "iife") { if (format === "iife") {
outputItem.name = name || "VenusLib"; outputItem.name = name || "VenusLib";
} }
// 为 CLI 的 cjs 产物添加 shebang 以支持作为可执行脚本运行
const isCli = /[\\\/]packages[\\\/]+cli$/.test(root);
if (isCli && format === "cjs") {
outputItem.banner = "#!/usr/bin/env node";
}
output.push(outputItem); output.push(outputItem);
} }
rollupOptions.output = output; rollupOptions.output = output;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!