mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
update build script for debug boilerplate and possibility for appcache
This commit is contained in:
parent
610e83f2dd
commit
e372914e7e
@ -2,6 +2,8 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, user-scalable=no">
|
||||||
|
<meta name="application-name" content="Brawl Chat"/>
|
||||||
<link rel="stylesheet" type="text/css" href="src/ui/web/css/main.css">
|
<link rel="stylesheet" type="text/css" href="src/ui/web/css/main.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "brawl-chat",
|
"name": "brawl-chat",
|
||||||
"version": "1.0.0",
|
"version": "0.0.1",
|
||||||
"description": "A javascript matrix client prototype, trying to minize RAM usage by offloading as much as possible to IndexedDB",
|
"description": "A javascript matrix client prototype, trying to minize RAM usage by offloading as much as possible to IndexedDB",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"directories": {
|
"directories": {
|
||||||
|
@ -14,7 +14,34 @@ const __dirname = dirname(__filename);
|
|||||||
const projectDir = path.join(__dirname, "../");
|
const projectDir = path.join(__dirname, "../");
|
||||||
const targetDir = path.join(projectDir, "target");
|
const targetDir = path.join(projectDir, "target");
|
||||||
|
|
||||||
|
const jsPostfix = `
|
||||||
|
window.DEBUG = true;
|
||||||
|
let buf = "";
|
||||||
|
console.error = (...params) => {
|
||||||
|
const lastLines = "...\\n" + buf.split("\\n").slice(-10).join("\\n");
|
||||||
|
// buf = buf + "ERR " + params.join(" ") + "\\n";
|
||||||
|
// const location = new Error().stack.split("\\n")[2];
|
||||||
|
alert(params.join(" ") +"\\n...\\n" + lastLines);
|
||||||
|
};
|
||||||
|
console.log = console.info = console.warn = (...params) => {
|
||||||
|
buf = buf + params.join(" ") + "\\n";
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
|
||||||
|
const jsSuffix = `
|
||||||
|
setTimeout(() => {
|
||||||
|
const showlogs = document.getElementById("showlogs");
|
||||||
|
showlogs.addEventListener("click", () => {
|
||||||
|
const lastLines = "...\\n" + buf.split("\\n").slice(-20).join("\\n");
|
||||||
|
alert(lastLines);
|
||||||
|
}, true);
|
||||||
|
showlogs.innerText = "Show last 20 log lines";
|
||||||
|
}, 10000);
|
||||||
|
`;
|
||||||
|
|
||||||
async function build() {
|
async function build() {
|
||||||
|
// get version number
|
||||||
|
const version = JSON.parse(await fs.readFile(path.join(projectDir, "package.json"), "utf8")).version;
|
||||||
// clear target dir
|
// clear target dir
|
||||||
await removeDirIfExists(targetDir);
|
await removeDirIfExists(targetDir);
|
||||||
await fs.mkdir(targetDir);
|
await fs.mkdir(targetDir);
|
||||||
@ -22,9 +49,10 @@ async function build() {
|
|||||||
const devHtml = await fs.readFile(path.join(projectDir, "index.html"), "utf8");
|
const devHtml = await fs.readFile(path.join(projectDir, "index.html"), "utf8");
|
||||||
const doc = cheerio.load(devHtml);
|
const doc = cheerio.load(devHtml);
|
||||||
doc("link[rel=stylesheet]").attr("href", "brawl.css");
|
doc("link[rel=stylesheet]").attr("href", "brawl.css");
|
||||||
|
// doc("html").attr("manifest", "manifest.appcache");
|
||||||
doc("script").replaceWith(
|
doc("script").replaceWith(
|
||||||
`<script type="text/javascript" src="brawl.js"></script>` +
|
`<script type="text/javascript" src="brawl.js"></script>` +
|
||||||
`<script type="text/javascript">main(document.body);</script>`);
|
`<script type="text/javascript">${jsPostfix} main(document.body); ${jsSuffix}</script>`);
|
||||||
await fs.writeFile(path.join(targetDir, "index.html"), doc.html(), "utf8");
|
await fs.writeFile(path.join(targetDir, "index.html"), doc.html(), "utf8");
|
||||||
// create js bundle
|
// create js bundle
|
||||||
const rollupConfig = {
|
const rollupConfig = {
|
||||||
@ -43,6 +71,17 @@ async function build() {
|
|||||||
const cssBundler = postcss([postcssImport]);
|
const cssBundler = postcss([postcssImport]);
|
||||||
const postCss = await cssBundler.process(preCss, {from: cssMainFile});
|
const postCss = await cssBundler.process(preCss, {from: cssMainFile});
|
||||||
await fs.writeFile(path.join(targetDir, "brawl.css"), postCss, "utf8");
|
await fs.writeFile(path.join(targetDir, "brawl.css"), postCss, "utf8");
|
||||||
|
// write appcache manifest
|
||||||
|
const manifestLines = [
|
||||||
|
`CACHE MANIFEST`,
|
||||||
|
`# v${version}`,
|
||||||
|
"brawl.js",
|
||||||
|
"brawl.css",
|
||||||
|
"index.html",
|
||||||
|
""
|
||||||
|
];
|
||||||
|
await fs.writeFile(path.join(targetDir, "manifest.appcache"), manifestLines.join("\n"), "utf8");
|
||||||
|
console.log(`built brawl ${version} successfully`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeDirIfExists(targetDir) {
|
async function removeDirIfExists(targetDir) {
|
||||||
@ -51,8 +90,9 @@ async function removeDirIfExists(targetDir) {
|
|||||||
await Promise.all(files.map(filename => fs.unlink(path.join(targetDir, filename))));
|
await Promise.all(files.map(filename => fs.unlink(path.join(targetDir, filename))));
|
||||||
await fs.rmdir(targetDir);
|
await fs.rmdir(targetDir);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// err.code === ENOENT
|
if (err.code !== "ENOENT") {
|
||||||
console.log(err);
|
throw err;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user