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";
|
|
|
|
import { languageList } from "../localization/manager.js";
|
|
|
|
import page from "./pageRender/page.js";
|
2022-07-30 10:01:54 +01:00
|
|
|
|
2023-03-09 18:41:17 +00:00
|
|
|
function cleanHTML(html) {
|
|
|
|
let clean = html.replace(/ /g, '');
|
|
|
|
clean = clean.replace(/\n/g, '');
|
|
|
|
return clean
|
|
|
|
}
|
|
|
|
export async function buildFront(commitHash, branch) {
|
2022-07-30 10:01:54 +01:00
|
|
|
try {
|
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/');
|
|
|
|
}
|
|
|
|
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-02-09 14:45:17 +00:00
|
|
|
outdir: '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;
|
|
|
|
}
|
|
|
|
}
|