2022-07-30 10:01:54 +01:00
|
|
|
import * as esbuild from "esbuild";
|
2023-03-09 18:41:17 +00:00
|
|
|
import * as fs from "fs";
|
2023-05-19 11:13:38 +01:00
|
|
|
import { loadLoc, languageList } from "../localization/manager.js";
|
2023-08-04 19:43:12 +01:00
|
|
|
import { cleanHTML } from "./sub/utils.js";
|
2023-05-19 11:13:38 +01:00
|
|
|
|
2023-03-09 18:41:17 +00:00
|
|
|
import page from "./pageRender/page.js";
|
2022-07-30 10:01:54 +01:00
|
|
|
|
2023-03-09 18:41:17 +00:00
|
|
|
export async function buildFront(commitHash, branch) {
|
2022-07-30 10:01:54 +01:00
|
|
|
try {
|
2023-05-19 11:13:38 +01:00
|
|
|
// preload localization files
|
|
|
|
await loadLoc();
|
|
|
|
|
2023-03-09 18:41:17 +00:00
|
|
|
// build html
|
|
|
|
if (!fs.existsSync('./build/')){
|
|
|
|
fs.mkdirSync('./build/');
|
|
|
|
fs.mkdirSync('./build/ios/');
|
|
|
|
fs.mkdirSync('./build/pc/');
|
|
|
|
fs.mkdirSync('./build/mob/');
|
|
|
|
}
|
2023-05-19 11:13:38 +01:00
|
|
|
// get rid of old build path
|
|
|
|
if (fs.existsSync('./min')) {
|
|
|
|
fs.rmSync('./min', { recursive: true, force: true });
|
|
|
|
}
|
2023-03-09 18:41:17 +00:00
|
|
|
for (let i in languageList) {
|
|
|
|
i = languageList[i];
|
|
|
|
let params = {
|
|
|
|
"hash": commitHash,
|
|
|
|
"lang": i,
|
|
|
|
"useragent": "pc",
|
|
|
|
"branch": branch
|
|
|
|
}
|
|
|
|
fs.writeFileSync(`./build/pc/${i}.html`, cleanHTML(page(params)));
|
|
|
|
|
|
|
|
params["useragent"] = "iphone os";
|
|
|
|
fs.writeFileSync(`./build/ios/${i}.html`, cleanHTML(page(params)));
|
|
|
|
|
|
|
|
params["useragent"] = "android";
|
|
|
|
fs.writeFileSync(`./build/mob/${i}.html`, cleanHTML(page(params)));
|
|
|
|
}
|
|
|
|
// build js & css
|
2022-07-30 10:01:54 +01:00
|
|
|
await esbuild.build({
|
|
|
|
entryPoints: ['src/front/cobalt.js', 'src/front/cobalt.css'],
|
2023-05-19 11:13:38 +01:00
|
|
|
outdir: 'build/min/',
|
2022-07-30 10:01:54 +01:00
|
|
|
minify: true,
|
2023-03-09 18:41:17 +00:00
|
|
|
loader: { '.js': 'js', '.css': 'css', },
|
|
|
|
charset: 'utf8'
|
2022-07-30 10:01:54 +01:00
|
|
|
})
|
|
|
|
} catch (e) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|