Skip to content

Commit a750bf5

Browse files
authored
Add JS/CSS build script (hestiacp#3471)
1 parent 14b2e2f commit a750bf5

File tree

12 files changed

+188
-323
lines changed

12 files changed

+188
-323
lines changed

build.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Build JS and CSS using esbuild and PostCSS
2+
const esbuild = require('esbuild');
3+
const postcss = require('postcss');
4+
const fs = require('fs').promises;
5+
const path = require('path');
6+
const postcssConfig = require('./postcss.config.js');
7+
8+
// Esbuild JavaScript configuration
9+
const esbuildConfig = {
10+
outdir: './web/js/dist',
11+
entryNames: '[dir]/[name].min',
12+
minify: true,
13+
};
14+
15+
// Build JavaScript
16+
async function buildJS() {
17+
const jsSrcPath = './web/js/src/';
18+
const jsEntries = await fs.readdir(jsSrcPath);
19+
const jsBuildPromises = jsEntries
20+
.filter((entry) => path.extname(entry) === '.js')
21+
.map((entry) => {
22+
const inputPath = path.join(jsSrcPath, entry);
23+
return esbuild
24+
.build({
25+
...esbuildConfig,
26+
entryPoints: [inputPath],
27+
})
28+
.then(() => {
29+
console.log('✅ JavaScript build completed for', inputPath);
30+
});
31+
});
32+
33+
try {
34+
await Promise.all(jsBuildPromises);
35+
} catch (error) {
36+
console.error('❌ Error building JavaScript:', error);
37+
process.exit(1);
38+
}
39+
}
40+
41+
// Process and build CSS
42+
async function processCSS(inputFile, outputFile) {
43+
try {
44+
const css = await fs.readFile(inputFile);
45+
const result = await postcss(postcssConfig.plugins).process(css, {
46+
from: inputFile,
47+
to: outputFile,
48+
});
49+
await fs.writeFile(outputFile, result.css);
50+
console.log(`✅ CSS build completed for ${inputFile}`);
51+
} catch (error) {
52+
console.error(`❌ Error processing CSS for ${inputFile}:`, error);
53+
process.exit(1);
54+
}
55+
}
56+
57+
// Build CSS files
58+
async function buildCSS() {
59+
const themesSrcPath = './web/css/src/themes/';
60+
const cssEntries = await fs.readdir(themesSrcPath);
61+
62+
const cssBuildPromises = cssEntries
63+
.filter((entry) => path.extname(entry) === '.css')
64+
.map(async (entry) => {
65+
const entryName = entry.replace('.css', '.min.css');
66+
const inputPath = path.join(themesSrcPath, entry);
67+
const outputPath = `./web/css/themes/${entryName}`;
68+
await processCSS(inputPath, outputPath);
69+
});
70+
71+
await Promise.all(cssBuildPromises);
72+
}
73+
74+
// Build all assets
75+
async function build() {
76+
console.log('🚀 Building JS and CSS...');
77+
await buildJS();
78+
await buildCSS();
79+
console.log('🎉 Build completed.');
80+
}
81+
82+
// Execute build
83+
build();

package.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"docs:dev": "vitepress dev docs",
1010
"docs:build": "vitepress build docs",
1111
"docs:serve": "vitepress serve docs",
12-
"build": "postcss web/css/src/themes/*.css --dir web/css/themes --ext .min.css",
12+
"build": "node build.js",
1313
"lint": "prettier --cache --check . && eslint --cache . && stylelint web/css/src/**/*.css && markdownlint-cli2 *.md docs/**/*.md",
1414
"lint-staged": "lint-staged",
1515
"format": "prettier --cache --write .",
@@ -26,14 +26,14 @@
2626
"@typescript-eslint/eslint-plugin": "^5.58.0",
2727
"@typescript-eslint/parser": "^5.58.0",
2828
"cssnano": "^6.0.0",
29+
"esbuild": "^0.17.16",
2930
"eslint": "^8.38.0",
3031
"eslint-config-prettier": "^8.8.0",
3132
"eslint-plugin-editorconfig": "^4.0.2",
3233
"husky": "^8.0.3",
3334
"lint-staged": "^13.2.1",
3435
"markdownlint-cli2": "^0.6.0",
35-
"postcss": "^8.4.21",
36-
"postcss-cli": "^10.1.0",
36+
"postcss": "^8.4.22",
3737
"postcss-import": "^15.1.0",
3838
"postcss-path-replace": "^1.0.4",
3939
"postcss-preset-env": "^8.3.1",
@@ -42,10 +42,13 @@
4242
"prettier-plugin-nginx": "^1.0.3",
4343
"prettier-plugin-sh": "^0.12.8",
4444
"prettier-plugin-sql": "^0.14.0",
45-
"stylelint": "^15.4.0",
46-
"stylelint-config-standard": "^32.0.0",
45+
"stylelint": "^15.5.0",
46+
"stylelint-config-standard": "^33.0.0",
4747
"typescript": "^5.0.4",
48-
"vitepress": "1.0.0-alpha.65",
48+
"vitepress": "1.0.0-alpha.70",
4949
"vue": "^3.2.47"
50-
}
50+
},
51+
"browserslist": [
52+
"defaults"
53+
]
5154
}

web/js/dist/events.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/js/dist/init.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/js/dist/main.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)