mirror of
https://github.com/nilbuild/diffity.git
synced 2026-09-19 07:26:16 +08:00
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import { build, context } from 'esbuild';
|
|
import { rmSync, readdirSync, statSync } from 'node:fs';
|
|
import { join, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const distDir = join(__dirname, 'dist');
|
|
const isWatch = process.argv.includes('--watch');
|
|
|
|
for (const entry of readdirSync(distDir)) {
|
|
if (entry === 'ui') {
|
|
continue;
|
|
}
|
|
const fullPath = join(distDir, entry);
|
|
const stat = statSync(fullPath);
|
|
rmSync(fullPath, { recursive: stat.isDirectory(), force: true });
|
|
}
|
|
|
|
const buildOptions = {
|
|
entryPoints: [join(__dirname, 'src/index.ts')],
|
|
bundle: true,
|
|
platform: 'node' as const,
|
|
target: 'node18',
|
|
format: 'esm' as const,
|
|
outfile: join(distDir, 'index.js'),
|
|
banner: {
|
|
js: '#!/usr/bin/env node',
|
|
},
|
|
external: [
|
|
'better-sqlite3',
|
|
'commander',
|
|
'open',
|
|
'picocolors',
|
|
],
|
|
sourcemap: isWatch,
|
|
minifySyntax: !isWatch,
|
|
treeShaking: true,
|
|
};
|
|
|
|
if (isWatch) {
|
|
const ctx = await context(buildOptions);
|
|
await ctx.watch();
|
|
console.log('Watching for changes...');
|
|
} else {
|
|
await build(buildOptions);
|
|
}
|