generated from pabio/template
-
Notifications
You must be signed in to change notification settings - Fork 68
/
post-process.ts
61 lines (52 loc) · 1.92 KB
/
post-process.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { readFile, writeFile, copyFile, copy, remove, pathExists } from "fs-extra";
import { load } from "js-yaml";
import { join } from "path";
import { execSync } from "child_process";
export const postProcess = async () => {
let config: {
"status-website"?: {
cname?: string;
robotsText?: string;
baseUrl?: string;
};
} = load(await readFile(join("..", ".upptimerc.yml"), "utf8")) as any;
const baseUrl = (config["status-website"] || {}).baseUrl || "/";
execSync(`sapper export --legacy --basepath ${baseUrl}`, {
stdio: "inherit",
});
if (baseUrl !== "/") {
await copy(join(".", "__sapper__", "export", baseUrl), join(".", "__sapper__", "export"));
await remove(join(".", "__sapper__", "export", baseUrl));
}
try {
if (await pathExists(join(".", "assets")))
await copy(join(".", "assets"), join(".", "__sapper__", "export"), { recursive: true });
} catch (error) {
console.log("Got an error in copying assets", error);
}
const [owner, repo] = (process.env.GITHUB_REPOSITORY || "").split("/");
if (
config["status-website"] &&
config["status-website"].cname &&
config["status-website"].cname !== "demo.upptime.js.org"
)
await writeFile(join(".", "__sapper__", "export", "CNAME"), config["status-website"].cname);
else if (
config["status-website"] &&
config["status-website"].cname &&
config["status-website"].cname === "demo.upptime.js.org" &&
owner === "upptime" &&
repo === "upptime"
)
await writeFile(join(".", "__sapper__", "export", "CNAME"), "demo.upptime.js.org");
if (config["status-website"] && config["status-website"].robotsText)
await writeFile(
join(".", "__sapper__", "export", "robots.txt"),
config["status-website"].robotsText
);
await copyFile(
join(".", "__sapper__", "export", "service-worker-index.html"),
join(".", "__sapper__", "export", "404.html")
);
};
postProcess();