更新 package.json 中的 build 腳本以添加 shebang,並新增 scripts/add-shebang.js 腳本以確保 dist/index.js 文件中包含正確的 shebang。

This commit is contained in:
siage 2025-04-18 13:00:05 +08:00
parent 6f3d2211ac
commit 607b9c9bab
2 changed files with 13 additions and 1 deletions

View File

@ -16,7 +16,7 @@
"shrimp-task-manager": "./dist/index.js"
},
"scripts": {
"build": "tsc",
"build": "tsc && node scripts/add-shebang.js",
"dev": "ts-node src/index.ts",
"start": "node dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"

12
scripts/add-shebang.js Normal file
View File

@ -0,0 +1,12 @@
import fs from "fs";
const filePath = "./dist/index.js";
const shebang = "#!/usr/bin/env node\n";
let content = fs.readFileSync(filePath, "utf8");
if (!content.startsWith(shebang)) {
content = shebang + content;
fs.writeFileSync(filePath, content);
console.log("✅ Shebang added to dist/index.js");
} else {
console.log(" Shebang already present.");
}