tailwind-ctp-intellisense/packages/tailwindcss-language-service/scripts/build.mjs

54 lines
1.2 KiB
JavaScript
Raw Normal View History

import path from 'node:path'
2023-10-27 15:27:26 +00:00
import { spawnSync } from 'node:child_process'
import esbuild from 'esbuild'
import minimist from 'minimist'
2023-10-27 15:27:26 +00:00
import { nodeExternalsPlugin } from 'esbuild-node-externals'
const __dirname = new URL('.', import.meta.url).pathname
const args = minimist(process.argv.slice(2), {
boolean: ['watch', 'minify'],
})
console.log('- Preparing')
2023-10-27 15:27:26 +00:00
let build = await esbuild.context({
entryPoints: [path.resolve(__dirname, '../src/index.ts')],
bundle: true,
platform: 'node',
external: [],
outdir: 'dist',
minify: args.minify,
format: 'esm',
plugins: [
nodeExternalsPlugin(),
{
name: 'generate-types',
async setup(build) {
build.onEnd(async (result) => {
// Call the tsc command to generate the types
spawnSync(
'tsc',
2023-10-27 15:57:36 +00:00
['--emitDeclarationOnly', '--outFile', path.resolve(__dirname, '../dist/index.d.ts')],
2023-10-27 15:27:26 +00:00
{
stdio: 'inherit',
}
)
})
},
},
],
})
console.log('- Building')
2023-10-27 15:27:26 +00:00
await build.rebuild()
if (args.watch) {
console.log('- Watching')
2023-10-27 15:27:26 +00:00
await build.watch()
} else {
console.log('- Cleaning up')
2023-10-27 15:27:26 +00:00
await build.dispose()
}