2023-05-14 13:52:47 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
import { build, context } from 'esbuild'
|
|
|
|
import pkg from '../package.json' assert { type: 'json' }
|
|
|
|
|
2024-03-04 18:32:03 +01:00
|
|
|
const common = {
|
2023-05-14 13:52:47 +02:00
|
|
|
bundle: true,
|
|
|
|
minify: true,
|
|
|
|
platform: 'node',
|
|
|
|
define: { VERSION: `"${pkg.version}"` },
|
|
|
|
}
|
|
|
|
|
2024-03-04 18:32:03 +01:00
|
|
|
const cliOptions = {
|
|
|
|
...common,
|
|
|
|
entryPoints: ['./src/cli.ts'],
|
|
|
|
format: 'cjs',
|
|
|
|
outfile: './dist/cli.cjs',
|
|
|
|
}
|
|
|
|
|
|
|
|
const indexOptions = {
|
|
|
|
...common,
|
|
|
|
entryPoints: ['./src/index.ts'],
|
|
|
|
outfile: './dist/index.mjs',
|
|
|
|
format: 'esm',
|
|
|
|
}
|
|
|
|
|
2023-05-14 13:52:47 +02:00
|
|
|
const watch = process.argv.slice(2)[0] === '--watch'
|
2024-03-03 01:22:39 +01:00
|
|
|
if (watch) {
|
2024-03-04 18:32:03 +01:00
|
|
|
const ctx = await context(cliOptions)
|
|
|
|
ctx.watch()
|
2024-03-03 01:22:39 +01:00
|
|
|
} else {
|
2024-03-04 18:32:03 +01:00
|
|
|
await build(cliOptions)
|
|
|
|
await build(indexOptions)
|
2024-03-03 01:22:39 +01:00
|
|
|
}
|