-
Notifications
You must be signed in to change notification settings - Fork 3
/
dev.ts
56 lines (53 loc) · 1.71 KB
/
dev.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
import { createServer } from "./server/server.js";
import open from "open";
import { autoYextInit } from "./server/autoInit.js";
import { devServerPort } from "./server/middleware/constants.js";
import runSubProcess from "../util/runSubprocess.js";
import { Command } from "commander";
export const devCommand = (program: Command) => {
program
.command("dev")
.description(
"Creates features.json, generates test data, " +
"and runs a custom local development server that is backed by Vite."
)
.option(
"--scope <string>",
"The subfolder to scope the served templates from"
)
.option("--local", "Disables dynamically generated test data")
.option(
"--prod-url",
"Use production URLs, instead of /[template-name]/[external-id]",
true
)
.option(
"--no-prod-url",
"Use local URLs, such as /[template-name]/[external-id]",
false
)
.option(
"--open-browser",
"Automatically opens the browser on server start-up",
true
)
.option(
"--no-open-browser",
"Do not open the browser on server start-up",
false
)
.option("--noInit", "Disables automatic yext init with .yextrc file")
.option("--noGenFeatures", "Disable feature.json generation step")
.action(async (options) => {
if (!options.noInit) {
await autoYextInit();
}
if (!options.noGenFeatures)
await runSubProcess(
"pages generate features",
options.scope ? ["--scope" + " " + options.scope] : []
);
await createServer(!options.local, !!options.useProdURLs, options.scope);
if (options.openBrowser) await open(`http://localhost:${devServerPort}/`);
});
};