Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package CLI code as ES module to allow import()
- Loading branch information
Showing
6 changed files
with
45 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env node | ||
|
||
import { UserError, cli, help } from './dist/cli.mjs' | ||
|
||
cli(process.stdin, error => { | ||
if (error instanceof UserError) { | ||
if (error.code === UserError.ARGS) console.error(`${help}\n`) | ||
console.error(error.message) | ||
process.exitCode = error.code | ||
} else if (error) throw error | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
import { chmod, stat } from 'node:fs/promises' | ||
import typescript from '@rollup/plugin-typescript' | ||
|
||
export default { | ||
input: { | ||
cli: 'src/cli.ts', | ||
index: 'src/index.ts', | ||
'test-events': 'src/test-events.ts', | ||
util: 'src/util.ts' | ||
export default [ | ||
{ | ||
input: { | ||
index: 'src/index.ts', | ||
'test-events': 'src/test-events.ts', | ||
util: 'src/util.ts' | ||
}, | ||
output: { | ||
dir: 'dist', | ||
format: 'cjs', | ||
esModule: false, | ||
preserveModules: true | ||
}, | ||
plugins: [typescript()], | ||
treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } | ||
}, | ||
output: { | ||
dir: 'dist', | ||
format: 'cjs', | ||
esModule: false, | ||
preserveModules: true | ||
}, | ||
external: ['node:path', 'node:util'], | ||
plugins: [ | ||
typescript(), | ||
{ | ||
async writeBundle() { | ||
// chmod a+x dist/cli.js | ||
const file = 'dist/cli.js' | ||
const prev = await stat(file) | ||
await chmod(file, prev.mode | 0o111) | ||
} | ||
} | ||
], | ||
treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } | ||
} | ||
{ | ||
input: 'src/cli.ts', | ||
output: { file: 'dist/cli.mjs' }, | ||
external: () => true, | ||
plugins: [typescript()] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters