Skip to content

Commit 0a648f7

Browse files
committedMay 28, 2019
feat(webpack-scaffold): adds Input defaults, doc & tests
1 parent 99304c4 commit 0a648f7

File tree

4 files changed

+63
-25
lines changed

4 files changed

+63
-25
lines changed
 

‎packages/webpack-scaffold/README.md

+28-23
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ npm i -D webpack-cli @webpack-cli/webpack-scaffold
1111
```
1212

1313
# API
14-
15-
- [parseValue](#parsevalue)
16-
- [createArrowFunction](#createarrowfunction)
17-
- [createRegularFunction](#createregularfunction)
18-
- [createDynamicPromise](#createdynamicpromise)
19-
- [createAssetFilterFunction](#createassetfilterfunction)
20-
- [createExternalFunction](#createexternalfunction)
21-
- [createRequire](#createrequire)
22-
- [Inquirer](#inquirer) - [List](#list) - [RawList](#rawlist) - [CheckList](#checklist) - [Input](#input) - [InputValidate](#inputvalidate) - [Confirm](#confirm)
14+
- [parseValue](#parsevalue)
15+
- [createArrowFunction](#createarrowfunction)
16+
- [createRegularFunction](#createregularfunction)
17+
- [createDynamicPromise](#createdynamicpromise)
18+
- [createAssetFilterFunction](#createassetfilterfunction)
19+
- [createExternalFunction](#createexternalfunction)
20+
- [createRequire](#createrequire)
21+
- [Inquirer](#inquirer)
22+
- [List](#list)
23+
- [RawList](#rawlist)
24+
- [CheckList](#checklist)
25+
- [Input](#input)
26+
- [InputValidate](#inputvalidate)
27+
- [Confirm](#confirm)
2328

2429
## parseValue
2530

@@ -163,38 +168,38 @@ CheckList("entry", "what kind of entry do you want?", ["Array", "Function"]);
163168

164169
### Input
165170

166-
Param: `name<String>, message<String>`
171+
Param: `name<String>, message<String>, [default<String>]`
167172

168173
Creates an Input from Inquirer
169174

170175
```js
171176
const Input = require("@webpack-cli/webpack-scaffold").Input;
172177

173-
Input("entry", "what is your entry point?");
178+
Input('entry', 'what is your entry point?', 'src/index')
174179
```
175180

176181
### InputValidate
177182

178-
Param: `name<String>, message<String>, validate<Function>`
183+
Param: `name<String>, message<String>, [validate<Function>, default<String>]`
179184

180185
Creates an Input from Inquirer
181186

182187
```js
183-
const InputValidate = require("@webpack-cli/webpack-scaffold").InputValidate;
184-
185-
const validation = value => {
186-
if (value.length > 4) {
187-
return true;
188-
} else {
189-
return "Wow, that was short!";
190-
}
191-
};
192-
InputValidate("entry", "what is your entry point?", validation);
188+
const InputValidate = require('@webpack-cli/webpack-scaffold').InputValidate;
189+
190+
const validation = (value) => {
191+
if(value.length > 4) {
192+
return true;
193+
} else {
194+
return 'Wow, that was short!'
195+
}
196+
}
197+
InputValidate('entry', 'what is your entry point?', validation, 'src/index')
193198
```
194199

195200
### Confirm
196201

197-
Param: `name<String>, message<String>, default<?Boolean>`
202+
Param: `name<String>, message<String>, [default<Boolean>]`
198203

199204
Creates an Input from Inquirer
200205

‎packages/webpack-scaffold/__tests__/__snapshots__/index.test.ts.snap

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
exports[`utils Inquirer should make an Input object with validation 1`] = `
44
Object {
5+
"default": undefined,
6+
"message": "what is your plugin?",
7+
"name": "plugins",
8+
"type": "input",
9+
"validate": [Function],
10+
}
11+
`;
12+
13+
exports[`utils Inquirer should make an Input object with validation and default value 1`] = `
14+
Object {
15+
"default": "my-plugin",
516
"message": "what is your plugin?",
617
"name": "plugins",
718
"type": "input",

‎packages/webpack-scaffold/__tests__/index.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ describe("utils", () => {
7676
});
7777
it("should make an Input object", () => {
7878
expect(utils.Input("plugins", "what is your plugin?")).toEqual({
79+
default: undefined,
80+
message: "what is your plugin?",
81+
name: "plugins",
82+
type: "input",
83+
});
84+
});
85+
it("should make an Input object", () => {
86+
expect(utils.Input("plugins", "what is your plugin?", "my-plugin")).toEqual({
87+
default: "my-plugin",
7988
message: "what is your plugin?",
8089
name: "plugins",
8190
type: "input",
@@ -102,5 +111,10 @@ describe("utils", () => {
102111
utils.InputValidate("plugins", "what is your plugin?", () => true),
103112
).toMatchSnapshot();
104113
});
114+
it("should make an Input object with validation and default value", () => {
115+
expect(
116+
utils.InputValidate("plugins", "what is your plugin?", () => true, "my-plugin"),
117+
).toMatchSnapshot();
118+
});
105119
});
106120
});

‎packages/webpack-scaffold/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,24 @@ export function CheckList(name: string, message: string, choices: string[]): Gen
7676
};
7777
}
7878

79-
export function Input(name: string, message: string): Generator.Question {
79+
export function Input(name: string, message: string, defaultChoice?: string): Generator.Question {
8080
return {
81+
default: defaultChoice,
8182
message,
8283
name,
8384
type: "input"
8485
};
8586
}
8687

87-
export function InputValidate(name: string, message: string, cb?: (input: string) => string | boolean): Generator.Question {
88+
export function InputValidate(
89+
name: string,
90+
message: string,
91+
cb?: (input: string) => string | boolean,
92+
defaultChoice?: string,
93+
): Generator.Question {
94+
8895
return {
96+
default: defaultChoice,
8997
message,
9098
name,
9199
type: "input",

0 commit comments

Comments
 (0)
Please sign in to comment.