From 3c84a0591db4bc218303124f6b147e712ae8e122 Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Tue, 13 Oct 2020 20:13:46 +0530 Subject: [PATCH] :sparkles: Add pre and post-process scripts --- post-process.ts | 19 +++++++++++++++++++ pre-process.ts | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 post-process.ts create mode 100644 pre-process.ts diff --git a/post-process.ts b/post-process.ts new file mode 100644 index 0000000..d983af0 --- /dev/null +++ b/post-process.ts @@ -0,0 +1,19 @@ +import { readFile, writeFile, copyFile } from "fs-extra"; +import { safeLoad } from "js-yaml"; +import { join } from "path"; + +export const preProcess = async () => { + const config = safeLoad(await readFile(join("..", ".upptimerc.yml"), "utf8")) as { + "status-website"?: { + cname?: string; + }; + }; + if (config["status-website"]?.cname) + await writeFile(join(".", "__sapper__", "export", "CNAME"), config["status-website"]?.cname); + await copyFile( + join(".", "__sapper__", "export", "service-worker-index.html"), + join(".", "__sapper__", "export", "404.html") + ); +}; + +preProcess(); diff --git a/pre-process.ts b/pre-process.ts new file mode 100644 index 0000000..4b76dc5 --- /dev/null +++ b/pre-process.ts @@ -0,0 +1,22 @@ +import { readFile, writeJson, ensureDir } from "fs-extra"; +import { safeLoad } from "js-yaml"; +import { join } from "path"; + +export const preProcess = async () => { + const i18n = safeLoad(await readFile(join(".", "i18n.yml"), "utf8")) as { + [index: string]: string; + }; + + const config = safeLoad(await readFile(join("..", ".upptimerc.yml"), "utf8")) as { + logoUrl?: string; + name?: string; + introTitle?: string; + introMessage?: string; + i18n?: { [index: string]: string }; + }; + config.i18n = { ...i18n, ...config.i18n }; + await ensureDir(join(".", "src", "data")); + await writeJson(join(".", "src", "data", "config.json"), config); +}; + +preProcess();