Commit 3a0b9f28 by liimin

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

修改构建配置以统一输出文件命名格式,为CLI添加shebang支持
更新postinstall脚本实现安装后自动全局链接
同步更新README文档说明全局使用方式
1 parent 1a666996
......@@ -171,6 +171,20 @@ Windows 提示:如 `--ui` 名称含连字符或可能被 Shell 误解析,推
- 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(可选)
如需发布以便团队安装使用:
......
......@@ -13,7 +13,7 @@
"prepare": "husky",
"precommit": "lint-staged",
"build": "venus build",
"postinstall": "node scripts/build.js",
"postinstall": "node scripts/build.js && pnpm -C packages/cli link --global",
"venus": "venus"
},
"config": {
......
......@@ -4,8 +4,8 @@
"version": "0.0.1",
"description": "Venus CLI helpers",
"type": "commonjs",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/buildSingle.js cli"
......@@ -13,12 +13,13 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./dist/*": "./dist/*"
},
"bin": {
"venus": "./dist/index.cjs"
"venus": "./dist/index.cjs.js"
},
"files": [
"dist",
......
......@@ -82,10 +82,9 @@ export async function getRollupConfig(root) {
};
const output = [];
for (const format of formats) {
const ext = format === "cjs" ? "cjs" : format === "esm" ? "mjs" : "js";
const outputItem = {
format,
file: path.resolve(dist, `index.${ext}`),
file: path.resolve(dist, `index.${format}.js`),
sourcemap: true,
exports: "named",
globals: isVue ? { vue: "Vue" } : {}
......@@ -93,6 +92,11 @@ export async function getRollupConfig(root) {
if (format === "iife") {
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);
}
rollupOptions.output = output;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!