generated from pabio/github-actions-starter
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathsite.ts
50 lines (47 loc) · 1.77 KB
/
site.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
import { stat } from "fs-extra";
import { cd, cp, exec, mkdir } from "shelljs";
import { getConfig } from "./helpers/config";
import { getOctokit } from "./helpers/github";
import { shouldContinue } from "./helpers/init-check";
import { getOwnerRepo } from "./helpers/secrets";
export const generateSite = async () => {
if (!(await shouldContinue())) return;
const [owner, repo] = getOwnerRepo();
const config = await getConfig();
if (config.skipGeneratingWebsite) return;
const sitePackage = config.customStatusWebsitePackage || "@upptime/status-page";
const octokit = await getOctokit();
const repoDetails = await octokit.repos.get({ owner, repo });
const siteDir = "site";
/* Configure shelljs to fail on failure */
var sh = require("shelljs");
sh.config.fatal = true;
mkdir(siteDir);
cd(siteDir);
/**
* If this is a private repository, we don't publish a status page
* by default, but can be overwritten with `publish: true`
*/
if (repoDetails.data.private && !(config["status-website"] || {}).publish) {
mkdir("-p", "status-page/__sapper__/export");
exec("echo 404 > status-page/__sapper__/export/index.html");
cd("../..");
return;
}
exec("npm init -y");
config.repo;
exec(`npm i ${sitePackage} --no-audit --no-fund --loglevel=error`);
cp("-r", `node_modules/${sitePackage}/*`, ".");
exec("npm i --no-audit --no-fund --loglevel=error");
exec("npm run export");
mkdir("-p", "status-page/__sapper__/export");
cp("-r", "__sapper__/export/*", "status-page/__sapper__/export");
let assetsExists = false;
try {
assetsExists = (await stat("../assets")).size > 0;
} catch (error) {
// Ignore errors if assets folder doesn't exist
}
if (assetsExists) cp("-r", "../assets/*", "status-page/__sapper__/export");
cd("../..");
};