-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-bundle.mjs
More file actions
61 lines (53 loc) · 1.69 KB
/
build-bundle.mjs
File metadata and controls
61 lines (53 loc) · 1.69 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
#!/usr/bin/env node
// Builds dag-map-bundle.js — a single IIFE that exposes window.DagMap
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
function stripModuleSyntax(code) {
return code
.replace(/^import\s+.*?from\s+['"].*?['"];?\s*$/gm, '')
.replace(/^export\s+(function|const|let|var|class)\s/gm, '$1 ')
.replace(/^export\s+\{[^}]*\};?\s*$/gm, '')
.replace(/^export\s+default\s+/gm, '');
}
const files = [
'route-bezier.js',
'route-angular.js',
'route-metro.js',
'graph-utils.js',
'themes.js',
'color-scales.js',
'layout-metro.js',
'layout-hasse.js',
'occupancy.js',
'layout-flow.js',
'render-flow-station.js',
'render.js',
];
const sources = files.map(f => `// --- ${f} ---\n` + stripModuleSyntax(readFileSync(join(__dirname, 'src', f), 'utf-8')));
const bundle = `// dag-map-bundle.js — auto-generated, do not edit
(function() {
${sources.join('\n\n')}
window.DagMap = {
layoutMetro: layoutMetro,
layoutHasse: layoutHasse,
layoutFlow: layoutFlow,
renderSVG: renderSVG,
resolveTheme: resolveTheme,
THEMES: THEMES,
dominantClass: dominantClass,
validateDag: validateDag,
swapPathXY: swapPathXY,
colorScales: colorScales,
createStationRenderer: createStationRenderer,
createEdgeRenderer: createEdgeRenderer,
};
})();
`;
const outPath = process.argv[2] || join(__dirname, 'dist', 'dag-map-bundle.js');
// Ensure output directory exists
const outDir = dirname(outPath);
mkdirSync(outDir, { recursive: true });
writeFileSync(outPath, bundle);
console.log('Built ' + outPath);