Skip to content

Commit 50325c5

Browse files
authored
Refactor JS to use ES modules (hestiacp#3476)
1 parent 5ff652b commit 50325c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1011
-1281
lines changed

build.js

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,26 @@
11
// 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');
2+
import esbuild from 'esbuild';
3+
import postcss from 'postcss';
4+
import { promises as fs } from 'node:fs';
5+
import path from 'node:path';
6+
import postcssConfig from './postcss.config.js';
77

8-
// Esbuild JavaScript configuration
98
const esbuildConfig = {
10-
outdir: './web/js/dist',
11-
entryNames: '[dir]/[name].min',
9+
outfile: './web/js/dist/main.min.js',
10+
bundle: true,
1211
minify: true,
12+
sourcemap: true,
1313
};
1414

1515
// Build JavaScript
1616
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-
17+
const inputPath = './web/js/src/main.js';
3318
try {
34-
await Promise.all(jsBuildPromises);
19+
await esbuild.build({
20+
...esbuildConfig,
21+
entryPoints: [inputPath],
22+
});
23+
console.log('✅ JavaScript build completed for', inputPath);
3524
} catch (error) {
3625
console.error('❌ Error building JavaScript:', error);
3726
process.exit(1);
@@ -56,14 +45,14 @@ async function processCSS(inputFile, outputFile) {
5645

5746
// Build CSS files
5847
async function buildCSS() {
59-
const themesSrcPath = './web/css/src/themes/';
60-
const cssEntries = await fs.readdir(themesSrcPath);
48+
const themesSourcePath = './web/css/src/themes/';
49+
const cssEntries = await fs.readdir(themesSourcePath);
6150

6251
const cssBuildPromises = cssEntries
6352
.filter((entry) => path.extname(entry) === '.css')
6453
.map(async (entry) => {
6554
const entryName = entry.replace('.css', '.min.css');
66-
const inputPath = path.join(themesSrcPath, entry);
55+
const inputPath = path.join(themesSourcePath, entry);
6756
const outputPath = `./web/css/themes/${entryName}`;
6857
await processCSS(inputPath, outputPath);
6958
});

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "An open-source Linux web server control panel.",
66
"repository": "https://github.com/hestiacp/hestiacp",
77
"license": "GPL-3.0-or-later",
8+
"type": "module",
89
"scripts": {
910
"docs:dev": "vitepress dev docs",
1011
"docs:build": "vitepress build docs",
@@ -19,14 +20,15 @@
1920
"packageManager": "yarn@3.5.0",
2021
"dependencies": {
2122
"@fortawesome/fontawesome-free": "^6.4.0",
23+
"nanoid": "^4.0.2",
2224
"normalize.css": "^8.0.1"
2325
},
2426
"devDependencies": {
2527
"@prettier/plugin-php": "^0.19.4",
26-
"@typescript-eslint/eslint-plugin": "^5.58.0",
27-
"@typescript-eslint/parser": "^5.58.0",
28+
"@typescript-eslint/eslint-plugin": "^5.59.0",
29+
"@typescript-eslint/parser": "^5.59.0",
2830
"cssnano": "^6.0.0",
29-
"esbuild": "^0.17.16",
31+
"esbuild": "^0.17.17",
3032
"eslint": "^8.38.0",
3133
"eslint-config-prettier": "^8.8.0",
3234
"eslint-plugin-editorconfig": "^4.0.2",
@@ -36,7 +38,7 @@
3638
"postcss": "^8.4.22",
3739
"postcss-import": "^15.1.0",
3840
"postcss-path-replace": "^1.0.4",
39-
"postcss-preset-env": "^8.3.1",
41+
"postcss-preset-env": "^8.3.2",
4042
"postcss-size": "^4.0.1",
4143
"prettier": "^2.8.7",
4244
"prettier-plugin-nginx": "^1.0.3",
@@ -45,7 +47,7 @@
4547
"stylelint": "^15.5.0",
4648
"stylelint-config-standard": "^33.0.0",
4749
"typescript": "^5.0.4",
48-
"vitepress": "1.0.0-alpha.70",
50+
"vitepress": "1.0.0-alpha.72",
4951
"vue": "^3.2.47"
5052
},
5153
"browserslist": [

postcss.config.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
module.exports = {
1+
import postcssImport from 'postcss-import';
2+
import postcssPathReplace from 'postcss-path-replace';
3+
import postcssSize from 'postcss-size';
4+
import cssnano from 'cssnano';
5+
import postcssPresetEnv from 'postcss-preset-env';
6+
7+
export default {
28
plugins: [
3-
require('postcss-import'),
4-
require('postcss-path-replace')({
9+
postcssImport,
10+
postcssPathReplace({
511
publicPath: '/webfonts/',
612
matched: '../webfonts/',
713
mode: 'replace',
814
}),
9-
require('postcss-size'),
10-
require('cssnano'),
11-
require('postcss-preset-env')({
15+
postcssSize,
16+
cssnano,
17+
postcssPresetEnv({
1218
autoprefixer: {
1319
flexbox: 'no-2009',
1420
},

web/css/src/themes/default.css

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,20 +1588,6 @@
15881588
}
15891589
}
15901590

1591-
.toggle-password {
1592-
color: #aaa;
1593-
z-index: 1;
1594-
position: absolute;
1595-
top: 9px;
1596-
right: 12px;
1597-
}
1598-
1599-
.toggle-psw-visibility-icon {
1600-
cursor: pointer;
1601-
opacity: 1;
1602-
margin: -2px;
1603-
}
1604-
16051591
.password-meter {
16061592
height: 3px;
16071593
overflow: hidden;
@@ -1698,7 +1684,7 @@
16981684
opacity: 0.8;
16991685
}
17001686

1701-
&.is-active {
1687+
&.active {
17021688
opacity: 1;
17031689
}
17041690

@@ -2213,7 +2199,7 @@
22132199
opacity: 0;
22142200
transition: opacity 0.2s ease, visibility 0s 0.2s;
22152201

2216-
&.show {
2202+
&.active {
22172203
visibility: visible;
22182204
opacity: 1;
22192205
transition: opacity 0.2s ease, visibility 0s 0s;

web/css/src/utilities.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
white-space: nowrap !important;
4646
}
4747

48-
.u-opacity-50 {
49-
opacity: 0.5 !important;
50-
}
51-
5248
.u-mt15 {
5349
margin-top: 15px !important;
5450
}
@@ -145,6 +141,12 @@
145141
resize: both !important;
146142
}
147143

144+
.u-unstyled-button {
145+
border: 0 !important;
146+
padding: 0 !important;
147+
background-color: transparent !important;
148+
}
149+
148150
.u-console {
149151
font-family: var(--font-family-monospace) !important;
150152
white-space: pre !important;

web/css/themes/default.min.css

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

web/js/dist/events.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

web/js/dist/init.min.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)