-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_inline_viewer.cjs
More file actions
54 lines (41 loc) · 1.77 KB
/
build_inline_viewer.cjs
File metadata and controls
54 lines (41 loc) · 1.77 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
#!/usr/bin/env node
/**
* Build script to create a self-contained viewer HTML with inlined JavaScript
* Run: node build_inline_viewer.js
*/
const fs = require('fs');
const path = require('path');
const viewerHtmlPath = path.join(__dirname, 'web/viewer_motion.html');
const bundlePath = path.join(__dirname, 'static/three/viewer-bundle.js');
const outputPath = path.join(__dirname, 'web/js/viewer_inline.js');
console.log('Building inline viewer for HY-Motion...');
// Check if bundle exists
if (!fs.existsSync(bundlePath)) {
console.error('Error: viewer-bundle.js not found at:', bundlePath);
console.log('Please copy the Three.js bundle from ComfyUI-UniRig or run esbuild first.');
process.exit(1);
}
console.log('Reading viewer HTML...');
let html = fs.readFileSync(viewerHtmlPath, 'utf-8');
console.log('Reading bundle JavaScript...');
const bundleJs = fs.readFileSync(bundlePath, 'utf-8');
console.log('Bundle size:', (bundleJs.length / 1024 / 1024).toFixed(2), 'MB');
// Replace the script src with inline script
html = html.replace(
/<script src="\/extensions\/ComfyUI-HY-Motion1\/static\/three\/viewer-bundle\.js"><\/script>/,
`<script>${bundleJs}</script>`
);
// Escape backticks and dollar signs for template literal
const escapedHtml = html
.replace(/\\/g, '\\\\')
.replace(/`/g, '\\`')
.replace(/\${/g, '\\${');
// Create JavaScript module that exports the HTML
const jsModule = `// Auto-generated inline viewer - DO NOT EDIT
// Generated on ${new Date().toISOString()}
export const VIEWER_HTML = \`${escapedHtml}\`;
`;
console.log('Writing output to:', outputPath);
fs.writeFileSync(outputPath, jsModule, 'utf-8');
console.log('Done! Inline viewer created successfully.');
console.log('Output size:', (jsModule.length / 1024 / 1024).toFixed(2), 'MB');