This repository was archived by the owner on Jan 4, 2026. It is now read-only.
forked from BetterSolano/bettersolano
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
127 lines (112 loc) · 3.19 KB
/
build.js
File metadata and controls
127 lines (112 loc) · 3.19 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
console.log('Building BetterSJDM for production...');
// Clean and create dist folder
if (fs.existsSync('dist')) {
fs.rmSync('dist', { recursive: true, force: true });
}
fs.mkdirSync('dist');
// Copy all files recursively
function copyRecursive(src, dest, exclude = []) {
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
// Skip excluded patterns
if (exclude.some(pattern => entry.name.match(pattern))) {
continue;
}
if (entry.isDirectory()) {
fs.mkdirSync(destPath, { recursive: true });
copyRecursive(srcPath, destPath, exclude);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
console.log('Copying files...');
copyRecursive('.', 'dist', [
/^node_modules$/,
/^\.git$/,
/^dist$/,
/^\.vscode$/,
/^backup-restore-point-/,
/^build\.sh$/,
/^build\.js$/,
/^package.*\.json$/,
/^scripts$/
]);
// Minify HTML files
console.log('Minifying HTML...');
const htmlFiles = [];
function findHtmlFiles(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
findHtmlFiles(fullPath);
} else if (entry.name.endsWith('.html')) {
htmlFiles.push(fullPath);
}
}
}
findHtmlFiles('dist');
for (const file of htmlFiles) {
try {
execSync(`npx html-minifier-terser --collapse-whitespace --remove-comments --minify-css true --minify-js true -o "${file}" "${file}"`, { stdio: 'inherit' });
} catch (e) {
console.warn(`Warning: Failed to minify ${file}`);
}
}
// Minify CSS files
console.log('Minifying CSS...');
const cssFiles = [];
function findCssFiles(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
findCssFiles(fullPath);
} else if (entry.name.endsWith('.css')) {
cssFiles.push(fullPath);
}
}
}
if (fs.existsSync('dist/assets/css')) {
findCssFiles('dist/assets/css');
}
for (const file of cssFiles) {
try {
execSync(`npx cleancss -o "${file}" "${file}"`, { stdio: 'inherit' });
} catch (e) {
console.warn(`Warning: Failed to minify ${file}`);
}
}
// Minify JS files
console.log('Minifying JavaScript...');
const jsFiles = [];
function findJsFiles(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
findJsFiles(fullPath);
} else if (entry.name.endsWith('.js')) {
jsFiles.push(fullPath);
}
}
}
if (fs.existsSync('dist/assets/js')) {
findJsFiles('dist/assets/js');
}
for (const file of jsFiles) {
try {
execSync(`npx terser "${file}" -o "${file}" --compress --mangle`, { stdio: 'inherit' });
} catch (e) {
console.warn(`Warning: Failed to minify ${file}`);
}
}
console.log('\nBuild complete!');
console.log('Output: dist/');