Skip to content

Commit

Permalink
fix: add shebang to command-line script on post install
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Vilanculo committed Jan 24, 2023
1 parent d4865cb commit ce36d82
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"successComment": false,
"failComment": false,
"assets": [
{ "path": "dist/**/*", "label": "Transpiled source files for distribution" },
{ "path": "dist/**/*" },
]
}
]
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
},
"scripts": {
"build": "tsc",
"postbuild": "node ./scripts/post-install.js",
"dev": "tsc && ENV=dev node dist/src/index.js",
"test": "vitest"
"test": "vitest",
"postinstall": "node ./scripts/post-install.js"
},
"bugs": {
"url": "https://github.com/isneezy/pdf-generator-service/issues"
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/scripts/post-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { existsSync, readFileSync, writeFileSync } = require('fs')
const path = require('path')

const SHEBANG = '#!/usr/bin/env node'
const binFile = path.resolve(__dirname, '../dist/src/index.js')

if (existsSync(binFile)) {
const content = readFileSync(binFile, 'utf-8').trim()
if (content.startsWith(SHEBANG)) return
writeFileSync(binFile, `${SHEBANG}\n\n${content}`)
}
2 changes: 0 additions & 2 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { resolve } from 'path'
import { writeFileSync, existsSync, readFileSync } from 'fs'
import pkg from '../package.json'
Expand Down
6 changes: 4 additions & 2 deletions packages/service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"generator"
],
"author": "Ivan Vilanculo <ivan.vilanculo@vm.co.mz>",
"homepage": "https://github.com/isneezy/pdf-generator-service/tree/main/packages/pdf-generator-service#readme",
"homepage": "https://github.com/isneezy/pdf-generator-service/blob/master/README.md",
"license": "MIT",
"bin": {
"pdf-generator-service": "./dist/src/pdf-generator-service.js"
Expand All @@ -31,8 +31,10 @@
},
"scripts": {
"build": "tsc",
"postbuild": "node ./scripts/post-install.js",
"dev": "nodemon",
"test": "vitest"
"test": "vitest",
"postinstall": "node ./scripts/post-install.js"
},
"bugs": {
"url": "https://github.com/isneezy/pdf-generator-service/issues"
Expand Down
12 changes: 12 additions & 0 deletions packages/service/scripts/post-install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { existsSync, readFileSync, writeFileSync } = require('fs')
const path = require('path')

const SHEBANG = '#!/usr/bin/env node'
const binFile = path.resolve(__dirname, '../dist/src/pdf-generator-service.js')

if (existsSync(binFile)) {
const content = readFileSync(binFile, 'utf-8').trim()
if (content.startsWith(SHEBANG)) return
writeFileSync(binFile, `${SHEBANG}\n\n${content}`)
}
2 changes: 0 additions & 2 deletions packages/service/src/pdf-generator-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env node

import { program } from 'commander'
import pkg from '../package.json'
import { createApp } from './app'
Expand Down

0 comments on commit ce36d82

Please sign in to comment.