-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
73 lines (65 loc) · 2.07 KB
/
Copy pathbuild.js
File metadata and controls
73 lines (65 loc) · 2.07 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
73
import esbuild from 'esbuild';
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const isWatch = process.argv.includes('--watch');
// Get specific feature from args (skip node executable and script path)
const specificFeature = process.argv.slice(2).find(arg => !arg.startsWith('--'));
// Discover all features in src/
const srcDir = join(process.cwd(), 'src');
const allItems = readdirSync(srcDir);
const features = allItems
.filter(item => {
const itemPath = join(srcDir, item);
try {
// Only build feature dirs that have an index.ts entrypoint
// (skips static folders like embeds/)
return (
statSync(itemPath).isDirectory() &&
statSync(join(itemPath, 'index.ts')).isFile()
);
} catch (e) {
return false;
}
})
.filter(feature => !specificFeature || feature === specificFeature);
if (features.length === 0) {
console.error('No features found in src/');
process.exit(1);
}
// Build configuration for each feature
const buildConfigs = features.map(feature => ({
entryPoints: [join(process.cwd(), `src/${feature}/index.ts`)],
bundle: true,
format: 'iife',
outfile: join(process.cwd(), `dist/heard-${feature}.js`),
target: 'es2020',
minify: !isWatch,
sourcemap: isWatch,
banner: {
js: `/* Heard Custom Code - ${feature} */`
}
}));
const build = async () => {
try {
if (isWatch) {
const contexts = await Promise.all(
buildConfigs.map(config => esbuild.context(config))
);
await Promise.all(contexts.map(ctx => ctx.watch()));
console.log(`Watching ${features.length} feature(s): ${features.join(', ')}`);
} else {
await Promise.all(
buildConfigs.map(config => esbuild.build(config))
);
console.log(`Built ${features.length} feature(s): ${features.join(', ')}`);
}
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
};
build();