gram/packages/language-server/build.cjs
abiwab d08b9bbce4
All checks were successful
CI / Build & Test (pull_request) Successful in 6m15s
feat(language-server): answer --version and --help
2026-11-24 16:16:27 +01:00

33 lines
909 B
JavaScript

const { chmodSync } = require('node:fs');
const esbuild = require('esbuild');
const isWatch = process.argv.includes('--watch');
const OUTFILE = 'dist/server.cjs';
const config = {
entryPoints: ['src/main.ts'],
bundle: true,
outfile: OUTFILE,
format: 'cjs',
platform: 'node',
target: 'node18',
// The bundle is also the `gram-language-server` binary.
banner: { js: '#!/usr/bin/env node' },
define: { __GRAM_LS_VERSION__: JSON.stringify(require('./package.json').version) },
plugins: [
{
name: 'executable',
setup(build) {
build.onEnd((result) => {
if (result.errors.length === 0) chmodSync(OUTFILE, 0o755);
});
},
},
],
};
if (isWatch) {
esbuild.context(config).then(ctx => ctx.watch());
} else {
esbuild.build(config).catch(() => process.exit(1));
}