-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.mjs
More file actions
72 lines (59 loc) · 1.74 KB
/
build.mjs
File metadata and controls
72 lines (59 loc) · 1.74 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import * as esbuild from 'esbuild';
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
import { exec } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
// Get all .ts files in src directory recursively
function getAllSourceFiles(dir) {
const files = [];
const items = readdirSync(dir);
for (const item of items) {
const fullPath = join(dir, item);
const stat = statSync(fullPath);
if (stat.isDirectory()) {
files.push(...getAllSourceFiles(fullPath));
} else if (item.endsWith('.ts')) {
files.push(fullPath);
}
}
return files;
}
const sourceFiles = getAllSourceFiles('src');
// Build library (CommonJS for backward compatibility)
await esbuild.build({
entryPoints: sourceFiles,
outdir: 'lib',
format: 'cjs',
platform: 'node',
target: 'node18',
outExtension: { '.js': '.js' },
footer: {
js: 'if (module.exports.default) module.exports = module.exports.default;'
}
});
console.log('✓ CommonJS build to lib/');
// Build library (ESM for modern usage)
await esbuild.build({
entryPoints: sourceFiles,
outdir: 'esm',
format: 'esm',
platform: 'node',
target: 'node18',
outExtension: { '.js': '.js' }
});
console.log('✓ ESM build to esm/');
// Generate TypeScript declarations (shared by both CJS and ESM)
await execAsync('npx tsc --emitDeclarationOnly --declaration --declarationMap --outDir lib');
console.log('✓ Type declarations generated');
// Build docs bundle (IIFE for browser)
await esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
outfile: 'docs/url-match.js',
format: 'iife',
globalName: 'UrlMatch',
platform: 'browser',
target: 'es2020'
});
console.log('✓ Docs bundle built to docs/url-match.js');