-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
39 lines (34 loc) · 1.29 KB
/
build.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { FS } from "@yao/runtime";
import { Locale } from "@yao/sui";
/**
* Replace the Development Block with the Production Block
* @param root
*/
function Before(root: string) {
console.log("Build Started");
// Find the Development Block in <!-- Development --> to <!-- Development END--> \n and replace it with the Production Block
const blockRe =
/<!-- Development -->\s*\n*([\s\S]*?)\s*<!-- Development END-->/g;
const fs = new FS("data");
// backup the document
fs.Copy(root + "/__document.html", root + "/__document.html.bak");
const document = fs.ReadFile(root + "/__document.html");
// Replace the Development Block with the Production Block
const productionBlock = `<link href="@assets/css/tailwind.min.css" rel="stylesheet" />`;
const newDocument = document.replace(blockRe, productionBlock);
fs.WriteFile(root + "/__document.html", newDocument);
}
function After(root: string) {
console.log("Build Done Successfully");
// resetDocument(root);
}
function Complete(root: string) {
console.log("Build Complete");
resetDocument(root);
}
function resetDocument(root: string) {
const fs = new FS("data");
fs.Remove(root + "/__document.html");
fs.Move(root + "/__document.html.bak", root + "/__document.html");
fs.Remove(root + "/__document.html.bak");
}