/
index.ts
63 lines (58 loc) · 1.55 KB
/
index.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
58
59
60
61
62
63
import {
AutoComplete,
Confirm,
IInquirerInput,
Input,
InputValidate,
List,
} from "@webpack-cli/webpack-scaffold";
import { existsSync } from "fs";
import { resolve } from "path";
import {
searchProps,
} from "../index";
/**
* Returns Inquirer question for given action
* @param action string
*/
export const manualOrListInput: (action: string) => IInquirerInput = (action: string) => {
const actionQuestion = `What do you want to add to ${action}?`;
return Input("actionAnswer", actionQuestion);
};
export const actionTypeQuestion = AutoComplete(
"actionType",
"What property do you want to add to?",
{
pageSize: 7,
source: searchProps,
suggestOnly: false,
},
);
export const entryTypeQuestion = Confirm(
"entryType",
"Will your application have multiple bundles?",
false,
);
export const topScopeQuestion = Input(
"topScope",
"What do you want to add to topScope?",
);
const mergeFileQuestionFunction = () => {
const question = "What is the location of webpack configuration with which you want to merge current configuration?";
const validator = (path: string) => {
const resolvedPath = resolve(process.env.PWD, path);
if (existsSync(resolvedPath)) {
if (/\.js$/.test(path)) {
if (typeof require(resolvedPath) !== "object") {
return "Given file doesn't export an Object";
}
return true;
} else {
return "Path doesn't corresponds to a javascript file";
}
}
return "Invalid path provided";
};
return InputValidate("mergeFile", question, validator);
};
export const mergeFileQuestion = mergeFileQuestionFunction();