UNPKG

1.68 kBPlain TextView Raw
1import inquirer from 'inquirer';
2import path from "path";
3import {Group} from "./classLibrary/Group";
4import {CyanSafe} from "./classLibrary/TargetUtil/CyanResponse";
5import {GenerateTemplate, Interrogate} from "./generator";
6import {Dependency} from "./Depedency";
7
8export async function Create(dep: Dependency, folderName: string): Promise<string> {
9
10 let root = path.resolve(__dirname, '../templates');
11 let group: Group = new Group(dep.core, dep.objex, root, dep.util);
12
13 let map: Map<string, string> = new Map(group.ListAsArray());
14
15 let answers: any = await inquirer.prompt([
16 {
17 type: "list",
18 message: "Please choose the template Group you want to use",
19 name: "group",
20 choices: map.Keys()
21 }
22 ]);
23 return await CreateTemplates(dep, group, map.get(answers["group"])!, folderName);
24}
25
26async function CreateTemplates(dep: Dependency, g: Group, group: string, folderName: string): Promise<string> {
27
28 //Find path to folder
29 let root = path.resolve(__dirname, '../templates/', group);
30
31 // Obtain template list from config file
32 const templates: Map<string, string>
33 = new Map(g.ListTemplate(group).Map(([k, v]) => [v, k] as [string, string]));
34
35 //Put up a list to see which question to return
36 let answers: any = await inquirer.prompt([
37 {
38 type: "list",
39 message: "Please choose the template to use",
40 name: "template",
41 choices: templates.Keys()
42 }
43 ]);
44 //Put up a template to see what to use
45 let templatePath = path.resolve(root, templates.get(answers["template"])!);
46
47 let settings: CyanSafe = await Interrogate(dep, dep.autoInquirer, templatePath, folderName);
48 return GenerateTemplate(dep, templatePath, folderName, settings, true);
49}
50