Skip to content

Commit

Permalink
add script to update hashbang
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Nov 21, 2024
1 parent ac2a12d commit 1549817
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"test:ci": "mocha --recursive ./test --require ./test/mocha-root-hooks.mjs --reporter mocha-multi-reporters --reporter-options configFile=./test/config/reporter.json",
"build": "npm run build:app && npm run build:sea",
"build:app": "esbuild --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl",
"postbuild:app": "sed -i '' '1s/.*/#!\\/usr\\/bin\\/env NODE_NO_WARNINGS=1 node/' ./dist/cli.cjs",
"postbuild:app": "node ./scripts/update-prod-hashbang.mjs",
"build:sea": "node ./sea/build.cjs",
"format": "prettier -w ."
},
Expand Down
14 changes: 14 additions & 0 deletions scripts/update-prod-hashbang.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node
import * as fs from "node:fs";
import * as path from "node:path";

const __dirname = import.meta.dirname;

const filePath = path.resolve(path.join(__dirname, "../dist/cli.cjs"));
let fileContents = fs.readFileSync(filePath);
const endOfFirstLine = fileContents.indexOf("\n");
fileContents = fileContents.slice(endOfFirstLine);
fileContents = `#!/usr/bin/env NODE_NO_WARNINGS=1 node\n${fileContents}`;
fs.rmSync(filePath);
fs.writeFileSync(filePath, fileContents);
fs.writeFileSync(filePath, fileContents);

0 comments on commit 1549817

Please sign in to comment.