Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's time to replace Gulp #56

Draft
wants to merge 120 commits into
base: Maslow-Main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
2da01a4
First Steps
md8n Nov 13, 2024
95d5812
Merge branch 'Standardize_Maslow_String_Usage' into gulp_down_the_bun
md8n Nov 14, 2024
067c5e9
Basic working, but very broken
md8n Nov 14, 2024
e1e151c
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Nov 14, 2024
3ffae86
More clean up in progress
md8n Nov 15, 2024
0510eb7
Further clean ups - focussed on preference
md8n Nov 20, 2024
30d4ba3
Getting better
md8n Nov 22, 2024
46f48f5
more progress
md8n Nov 24, 2024
f8e0ff3
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Nov 24, 2024
090e3f8
CheckValue working to basic level
md8n Nov 24, 2024
9d37941
further cleanup settings, setup, status
md8n Nov 25, 2024
8fd329b
SPIFFS working (with test data)
md8n Nov 25, 2024
bfb4c1a
cleaned up closeModal click events
md8n Nov 25, 2024
6155142
and I forgot this bit
md8n Nov 25, 2024
ad2b766
Fix last_ping
md8n Nov 25, 2024
e047719
fixed missing imports of `id`
md8n Nov 25, 2024
659b495
updatedlg update
md8n Nov 25, 2024
c4b749c
More onclick cleanup - config.js and controls.js
md8n Nov 26, 2024
5b1ada6
onclick fix for scanwifidlg.js
md8n Nov 26, 2024
d68a685
Starting work in the maslow specific stuff
md8n Nov 26, 2024
b07b7e0
Further maslow specific work
md8n Nov 26, 2024
53d9cd0
Much improved, but still not right
md8n Nov 26, 2024
4aa97c6
But wait, there's more
md8n Nov 26, 2024
e7e8c8f
last `on`* attributes in tablettab
md8n Nov 26, 2024
0060086
clean up logindlg
md8n Nov 26, 2024
4b9921e
settingstab removal of `on`*
md8n Nov 26, 2024
0942002
inputdlg clean of `on`* attributes
md8n Nov 26, 2024
5524304
further cleanups
md8n Nov 27, 2024
7e9d590
cameratab and controlspanel cleaned up
md8n Nov 27, 2024
c9ad5c2
commandspanel cleanup
md8n Nov 27, 2024
b564388
controlpanel de-`on`*ed
md8n Nov 27, 2024
5766512
Now grblpanel's turn
md8n Nov 27, 2024
b2d3713
files de-`on`*ed
md8n Nov 27, 2024
5bf0dc6
use `setHTML` wherever possible
md8n Nov 27, 2024
8973c3d
Fixed a few annoying problems
md8n Nov 27, 2024
3944115
Back to cleaning up preferences
md8n Nov 28, 2024
858fe16
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Nov 28, 2024
03270c8
Continuing the process of teasing things apart
md8n Nov 28, 2024
9db0416
WIP - eliminating dodgy setup code
md8n Nov 28, 2024
9861b4e
WIP - files panel related preferences
md8n Nov 28, 2024
4fb1899
WIP - GRBL Panel related changes
md8n Nov 28, 2024
9020a99
WIP - tracking down the leftovers
md8n Nov 28, 2024
2a556e5
WIP - Some more language work
md8n Nov 29, 2024
b0c76fe
WIP - eliminate `onkeyup`
md8n Nov 29, 2024
cccf06f
WIP - onchange eliminated
md8n Nov 29, 2024
f56a4be
WIP - `onclick` elimination continues
md8n Nov 29, 2024
7972fc3
WIP - `onclick` eliminated from files
md8n Nov 29, 2024
486121d
`onclick` removed
md8n Dec 1, 2024
deca487
Some minor linting while I figure out biome
md8n Dec 1, 2024
1446645
WIP bun build
md8n Dec 1, 2024
fd744da
WIP - continuing bunnifying
md8n Dec 2, 2024
f7e83cc
WIP - build vs run
md8n Dec 2, 2024
3a2e441
WIP - moving to common singleton for some former globals
md8n Dec 2, 2024
613981b
WIP - continuing with the move to common singleton
md8n Dec 2, 2024
0b14a42
WIP - more pseudo globals moved to common
md8n Dec 2, 2024
b22efcf
Hunted down remaining typeofs that could be replaced in some way
md8n Dec 2, 2024
2b4f934
and this bit
md8n Dec 2, 2024
3d6ecfd
Bun build works, but not small enough
md8n Dec 3, 2024
74c63dc
moving export statement
md8n Dec 3, 2024
422da19
Ongoing reorg of the imports
md8n Dec 3, 2024
6a225e0
WIP - clobbering circular refs problem
md8n Dec 3, 2024
bc766fd
WIP - consolidating imports
md8n Dec 3, 2024
33e811e
WIP - next round of import consolidation
md8n Dec 3, 2024
7ebaf48
import consolidation completed
md8n Dec 3, 2024
ddf2cf7
bun build changes
md8n Dec 3, 2024
8850a41
bun build changes
md8n Dec 4, 2024
e77979f
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 4, 2024
e3eefdf
Fix jogdial svgs
md8n Dec 4, 2024
06044b4
Working on the jog dial
md8n Dec 4, 2024
4bb85fc
cameratab minor cleanup
md8n Dec 4, 2024
64c1104
minor cleanup of the commasn panel
md8n Dec 4, 2024
6cb0633
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 5, 2024
cdd6d47
Update confirmdlg comments
md8n Dec 5, 2024
ec1f5c2
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 6, 2024
094cc38
linewidth formatting default
md8n Dec 6, 2024
2ea719f
login dlg tweaks
md8n Dec 7, 2024
bb0645f
Some more utils.js cleanup
md8n Dec 7, 2024
a8407e4
Updates to macrodlg
md8n Dec 7, 2024
0e54b5f
propelry imp/exp hide_dro_menu
md8n Dec 7, 2024
aadc551
passworddlg cleanup
md8n Dec 7, 2024
6d049a5
and the passworddlg html
md8n Dec 7, 2024
2271c25
restartdlg
md8n Dec 8, 2024
82efdc0
center is a class
md8n Dec 8, 2024
45c9aff
scanwifidlg cleanup
md8n Dec 8, 2024
8f6fa98
more little cleanup
md8n Dec 8, 2024
70b9f7a
uidisableddlg cleanups
md8n Dec 8, 2024
1d882c2
cleanup updatedlg
md8n Dec 8, 2024
7f2181e
SPIFFSdlg cleanup plus related
md8n Dec 8, 2024
00e45d3
more minopr SPIFFS
md8n Dec 9, 2024
f51af0d
filesdlg cleanup
md8n Dec 9, 2024
626c11c
tweak
md8n Dec 9, 2024
a791484
partial cleanup of calibrationstuff
md8n Dec 9, 2024
96a0430
WIP
md8n Dec 9, 2024
249d44c
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 9, 2024
6bed6d4
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 10, 2024
f453850
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 10, 2024
1dfd627
navbar tidy up minor
md8n Dec 10, 2024
179f718
build work for svg
md8n Dec 10, 2024
de8ea23
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 10, 2024
4b2dd80
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 11, 2024
03d2237
move langauges to json
md8n Dec 13, 2024
59cd75a
remove removeIf
md8n Dec 13, 2024
7885bc6
restore after bad merge
md8n Dec 13, 2024
4083113
http and socket cleanup
md8n Dec 13, 2024
36e6920
build changes
md8n Dec 13, 2024
889bd9b
other stuff
md8n Dec 13, 2024
3a7eb89
more build work
md8n Dec 14, 2024
7d967eb
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 15, 2024
15109ec
configtab cleanup
md8n Dec 15, 2024
5c19d3f
Reviewed most `translate_text_item` calls
md8n Dec 16, 2024
d76dfb5
All languages working for `serve`
md8n Dec 16, 2024
8b7e4f7
first build working with limited languages
md8n Dec 16, 2024
52fb164
Merge branch 'update_configtab' into gulp_down_the_bun
md8n Dec 16, 2024
02c8800
setupdlg cleanups
md8n Dec 17, 2024
f3bf607
Merge branch 'tbalet_no_global_space_f_calls' into gulp_down_the_bun
md8n Dec 17, 2024
989452e
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 18, 2024
53003db
Merge branch 'fix_files_isdir' into gulp_down_the_bun
md8n Dec 18, 2024
7ad6f9c
validation changes
md8n Dec 20, 2024
d84c387
more things are now common
md8n Dec 23, 2024
47e0bb0
Merge branch 'Maslow-Main' into gulp_down_the_bun
md8n Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"ignore": []
},
"formatter": {
"enabled": true,
"indentStyle": "tab",
"lineWidth": 120
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
211 changes: 211 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
import html from "bun-plugin-html";
import { platform } from "bun-utilities/os";
import { minifySync } from "@swc/html";

const cleanDist = () => {
console.log("No file delete function in bun yet. So no `cleanDist`");

console.log(Bun.env.npm_lifecycle_script);
console.log(import.meta.dir);
};

const pathDiv = (path: string) => path.replaceAll("\\", platform() !== "windows" ? "/" : "\\\\");

const limitedLanguageImports = async (fileContents: string, inclLang: string[] = ["en"]) => {
const langUtilsFile = [];
/** This shgould correspond exactly with `language_list in `langUtils.js` */
const language_list = [
["de", "germantrans"],
["en", "englishtrans"],
["es", "spanishtrans"],
["fr", "frenchtrans"],
["it", "italiantrans"],
["ja", "japanesetrans"],
["hu", "hungariantrans"],
["pl", "polishtrans"],
["ptbr", "ptbrtrans"],
["ru", "russiantrans"],
["tr", "turkishtrans"],
["uk", "ukrtrans"],
["zh_CN", "zh_CN_trans"],
];
for (let ix = 0; ix < language_list.length; ix++) {
const lang = language_list[ix];
if (inclLang.includes(lang[0])) {
const absPath = pathDiv(`${import.meta.dir}\\www\\js\\language\\${lang[0]}.json`);
langUtilsFile.push(`import ${lang[1]} from "${absPath}" with {type: "json"};`);
}
}
// Add in the original file
langUtilsFile.push(fileContents);

return langUtilsFile.join("\n");
};

/** Change all import filepaths to their absolute version */
const absolutifyImports = async (fileContents: string) => {
const regexImp = /}\s*from\s*['"](?<imppath>.*)['"]\;/gm;
const impResults = [...fileContents.matchAll(regexImp)];
if (!impResults.length) {
// Leave the file as-is - and move on
return fileContents;
}

let fcAbsImp = fileContents;
const repPath = `${import.meta.dir}\\www\\js\\`;
for (let ix = 0; ix < impResults.length; ix++) {
const ir = impResults[ix];
const impFilePath = pathDiv(ir[1].replace("./", repPath));
fcAbsImp = fcAbsImp.replace(ir[1], impFilePath);
}
return fcAbsImp;
};

const loadAndReplaceHTML = async (filePath: string, fileContents: string) => {
const fcLower = fileContents.toLowerCase();
const hasLoadHTML = fcLower.includes("loadhtml");
const hasSVG = fcLower.includes(".svg");
console.log(`Processing '${filePath}'`);
if (!hasLoadHTML && !hasSVG) {
// Leave the file as-is - and move on
console.log(`No 'loadhtml' or '.svg' in '${filePath}'`);
return fileContents;
}

let fcProcessed = fileContents;

if (hasLoadHTML) {
console.log(`Processing '${filePath}' for included HTML files`);
// Remove the script that does the html loading - we won't need it after bundling
const regexScript = /\<script.*loadhtml.*>\<\/script>/gim;
const fcNoLoad = fileContents.replace(regexScript, "");

// Now find all of the places where the above script was used
const regexHTML = /\<div\s+id\s*=\s*['"](?<htmlpath>.*\.html)['"]\s*class.*loadhtml.*><\/div>/gm;
const loadHTMLResults = [...fcNoLoad.matchAll(regexHTML)];
if (!loadHTMLResults.length) {
// Leave the file as-is-ish - and move on
return fcNoLoad;
}

// Finally replace the original `div` with the actual file
let fcReplLoad = fcNoLoad;
for (let ix = 0; ix < loadHTMLResults.length; ix++) {
const lhr = loadHTMLResults[ix];
const childFilePath = lhr[1].replace("./sub/", "./www/sub/");
const hFile = Bun.file(childFilePath);
let hText = await hFile.text();
if (hText.includes(".svg")) {
const regexSVG = /\<img\s+src\s*=\s*['"](?<svgpath>.*\.svg)['"].*><\/img>/gim;
const findSVGResults = [...hText.matchAll(regexSVG)];
if (findSVGResults.length) {
console.log(`found SVGs in ${childFilePath}`);
for (let jx = 0; jx < findSVGResults.length; jx++) {
const svr = findSVGResults[jx];
const svgPath = svr[1].replace("../images/", "./www/images/");
const svgFile = Bun.file(svgPath);
const svgExists = await svgFile.exists();
if (svgExists) {
hText = hText.replace(svr[0], await svgFile.text());
}
}
}
}
fcReplLoad = fcReplLoad.replace(lhr[0], hText);

if (hText.includes("loadhtml")) {
fcReplLoad = await loadAndReplaceHTML(childFilePath, fcReplLoad);
}
}

fcProcessed = fcReplLoad;
}

return fcProcessed;
};

const build = async () => {
await Bun.build({
entrypoints: ["./www/index.html", "./js/app.js"],
outdir: "./dist",
target: "browser",
format: "esm",
splitting: false,
naming: "[dir]/[name].[ext]",
minify: true,
plugins: [
html({
inline: true,
keepOriginalPaths: false,
async preprocessor(processor) {
const files = processor.getFiles();

// CSS also gets processed, but it falls right through this loop unaffected

// Process JS / TS before the HTML
for (const file of files) {
if (![".js", ".ts"].includes(file.extension)) {
continue;
}
console.log(`Processing JS/TS file '${file.path}'`);
if (file.path.endsWith("langUtils.js")) {
const fcLang = await limitedLanguageImports(await file.content);
processor.writeFile(file.path, fcLang);
} else {
const fcAbsImp = await absolutifyImports(await file.content);
processor.writeFile(file.path, fcAbsImp);
}
}

for (const file of files) {
if (file.extension !== ".html") {
// Now we're only processing html files
continue;
}
console.log(`Processing HTML file '${file.path}'`);
const fc = await file.content;
processor.writeFile(file.path, await loadAndReplaceHTML(file.path, fc));
}
},
}),
],
});
};

const compress = async () => {
const indexFile = Bun.file("./dist/index.html");
const data = await indexFile.arrayBuffer();
// const { code, map } = minifySync(data, {
// // filename?: string;
// // iframeSrcdoc?: boolean;
// scriptingEnabled: true,
// // forceSetHtml5Doctype?: boolean;
// collapseWhitespaces: "all",
// removeEmptyMetadataElements: true,
// removeComments: true,
// // preserveComments?: string[],
// minifyConditionalComments: true,
// removeEmptyAttributes: true,
// removeRedundantAttributes: "all",
// collapseBooleanAttributes: true,
// normalizeAttributes: true,
// minifyJson: true,
// // TODO improve me after typing `@swc/css`
// minifyJs: true,
// minifyCss: true,
// // minifyAdditionalScriptsContent?: [string, MinifierType][];
// // minifyAdditionalAttributes?: [string, MinifierType][];
// // sortSpaceSeparatedAttributeValues?: boolean;
// // // sortAttributes?: boolean;
// // tagOmission?: boolean;
// // selfClosingVoidElements?: boolean;
// // quotes?: boolean;
// });
const compressed = Bun.gzipSync(data, { level: 9 });
Bun.write("./dist/index.html.gz", compressed);
};

console.log("Running the build");
cleanDist();
await build();
await compress();
Binary file modified bun.lockb
Binary file not shown.
48 changes: 18 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
{
"name": "ESP3D-WebUI",
"description": "Web UI for ESP3D",
"module": "index.ts",
"type": "module",
"repository": "https://github.com/luc-github/ESP3D-WEBUI",
"author": "Luc LEBOSSE",
"license": "(ISC OR GPL-3.0)",
"scripts": {
"build": "gulp package",
"build:en": "gulp package -en",
"serve": "python fluidnc-web-sim.py maslow.local",
"start": "npm run build:en && npm run serve"
"build:bun": "bun run build.ts --lang en",
"serve": "bun run --hot serve.ts"
},
"devDependencies": {
"@happy-dom/global-registrator": "^15.11.0",
"@types/bun": "^1.1.13",
"del": "6.0.0",
"deprecated": "latest",
"fs": "latest",
"gulp": "^4.0.2",
"gulp-bytediff": "latest",
"gulp-cdnizer": "latest",
"gulp-clean-css": "latest",
"gulp-concat": "latest",
"gulp-filesize": "latest",
"gulp-gzip": "latest",
"gulp-htmlmin": "latest",
"gulp-if": "latest",
"gulp-jshint": "latest",
"gulp-ng-annotate": "latest",
"gulp-remove-code": "latest",
"gulp-replace": "latest",
"gulp-smoosher": "latest",
"gulp-uglify": "^3.0.2",
"gulp-zip": "latest",
"jshint": "latest",
"merge-stream": "latest",
"uglify-js": "^3.14.2"
"@biomejs/biome": "1.9.4",
"@happy-dom/global-registrator": "^15.11.7",
"@swc/core": "^1.10.1",
"@swc/html": "^1.10.1",
"@types/bun": "^1.1.14",
"bun-plugin-html": "^2.2.4",
"bun-utilities": "^0.2.1"
},
"repository": "https://github.com/luc-github/ESP3D-WEBUI",
"author": "Luc LEBOSSE",
"license": "(ISC OR GPL-3.0)",
"dependencies": {
"global": "latest"
},
"peerDependencies": {
"typescript": "^5.6.3"
}
}
}
Loading
Loading