-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathbuildLocalBake.ts
57 lines (53 loc) · 1.86 KB
/
buildLocalBake.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
#! /usr/bin/env node
import yargs from "yargs"
import { hideBin } from "yargs/helpers"
import { BakeStep, BakeStepConfig, bakeSteps, SiteBaker } from "./SiteBaker.js"
import fs from "fs-extra"
import { normalize } from "path"
import * as db from "../db/db.js"
import { DEFAULT_LOCAL_BAKE_DIR } from "../site/SiteConstants.js"
const bakeDomainToFolder = async (
baseUrl = "http://localhost:3000/",
dir = DEFAULT_LOCAL_BAKE_DIR,
bakeSteps?: BakeStepConfig
) => {
dir = normalize(dir)
await fs.mkdirp(dir)
const baker = new SiteBaker(dir, baseUrl, bakeSteps)
console.log(`Baking site locally with baseUrl '${baseUrl}' to dir '${dir}'`)
await db.knexReadonlyTransaction(
(trx) => baker.bakeAll(trx),
db.TransactionCloseMode.Close
)
}
void yargs(hideBin(process.argv))
.command<{ baseUrl: string; dir: string; steps?: string[] }>(
"$0 [baseUrl] [dir]",
"Bake the site to a local folder",
(yargs) => {
yargs
.positional("baseUrl", {
type: "string",
default: "http://localhost:3000/",
describe: "Base URL of the site",
})
.positional("dir", {
type: "string",
default: "localBake",
describe: "Directory to save the baked site",
})
.option("steps", {
type: "array",
choices: bakeSteps,
description: "Steps to perform during the baking process",
})
},
async ({ baseUrl, dir, steps }) => {
const bakeSteps = steps ? new Set(steps as BakeStep[]) : undefined
await bakeDomainToFolder(baseUrl, dir, bakeSteps)
process.exit(0)
}
)
.help()
.alias("help", "h")
.strict().argv