-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
52 lines (45 loc) · 1.26 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { build } from 'esbuild';
import { exec } from 'child_process';
import { promisify } from 'util';
import { rimraf } from 'rimraf';
const execAsync = promisify(exec);
const distPath = './dist';
async function clearDistFolder() {
await rimraf(distPath);
console.log('Output folder cleaned.');
}
async function buildJavaScript() {
await build({
entryPoints: ['./src/index.ts'],
outfile: distPath + '/index.js',
bundle: true,
platform: 'node',
target: 'es2022',
sourcemap: true,
format: 'esm',
minify: false,
logLevel: 'info',
external: ['*.test.ts', '*/tests'],
banner: {
js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);"
},
});
console.log('JavaScript build completed.');
}
async function generateTypeDeclarations() {
await execAsync('tsc --emitDeclarationOnly --outDir ./dist');
console.log('TypeScript declarations generated.');
}
async function buildLibrary() {
try {
console.log('Starting build...');
await clearDistFolder();
await buildJavaScript();
await generateTypeDeclarations();
console.log('Build completed successfully.');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
buildLibrary();