-
Notifications
You must be signed in to change notification settings - Fork 3
/
features.ts
44 lines (43 loc) · 1.6 KB
/
features.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
import path from "path";
import { Path } from "../../common/src/project/path.js";
import { ProjectStructure } from "../../common/src/project/structure.js";
import { getTemplateFilepaths } from "../../common/src/template/internal/getTemplateFilepaths.js";
import { loadTemplateModules } from "../../common/src/template/internal/loader.js";
import { createFeaturesJson } from "./createFeaturesJson.js";
import { Command } from "commander";
export const featureCommand = (program: Command) => {
program
.command("features")
.description("Generates features.json file")
.option(
"--scope <string>",
"The subfolder to scope the served templates from"
)
.action(async (options, command) => {
const scope = options.scope;
const projectStructure = new ProjectStructure();
const templatesRoot = projectStructure.templatesRoot.path;
const sitesConfigRoot = projectStructure.sitesConfigRoot.path;
const templateRootAbsolutePath = path.join(process.cwd(), templatesRoot);
const templateFilepaths = getTemplateFilepaths(
scope
? [
new Path(path.join(templateRootAbsolutePath, scope)),
new Path(templateRootAbsolutePath),
]
: [new Path(templateRootAbsolutePath)]
);
const templateModules = await loadTemplateModules(
templateFilepaths,
true,
false
);
const featuresFilepath = path.join(
process.cwd(),
sitesConfigRoot,
scope ?? "",
"features.json"
);
await createFeaturesJson(templateModules, featuresFilepath);
});
};