-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
executable file
·36 lines (29 loc) · 1.2 KB
/
build.js
File metadata and controls
executable file
·36 lines (29 loc) · 1.2 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const htmlPath = path.join(__dirname, 'src', 'index.html');
const cssPath = path.join(__dirname, 'src', 'styles.css');
const jsFiles = [
path.join(__dirname, 'src', 'TextProcessor.js'),
path.join(__dirname, 'src', 'SpeedController.js'),
path.join(__dirname, 'src', 'UIController.js'),
path.join(__dirname, 'src', 'EventHandlers.js'),
path.join(__dirname, 'src', 'script.js')
];
const outputPath = path.join(__dirname, 'dist', 'speedreader.html');
const html = fs.readFileSync(htmlPath, 'utf8');
const css = fs.readFileSync(cssPath, 'utf8');
let combinedJs = '';
jsFiles.forEach(file => {
const jsContent = fs.readFileSync(file, 'utf8');
const filteredJs = jsContent.split('\n').map(line => {
if (line.trim().startsWith('import')) return '';
return line.replace(/^\s*export\s+/, '');
}).filter(line => line.trim() !== '').join('\n');
combinedJs += filteredJs + '\n';
});
const finalHtml = html
.replace('<!-- CSS -->', `<style>\n${css}\n</style>`)
.replace('<!-- JS -->', `<script>\n${combinedJs}\n</script>`);
fs.writeFileSync(outputPath, finalHtml);
console.log('Building successfull.');