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
| const { notEmpty } = require('../utils.js')
|
| module.exports = {
| description: 'generate store',
| prompts: [{
| type: 'input',
| name: 'name',
| message: 'store name please',
| validate: notEmpty('name')
| },
| {
| type: 'checkbox',
| name: 'blocks',
| message: 'Blocks:',
| choices: [{
| name: 'state',
| value: 'state',
| checked: true
| },
| {
| name: 'mutations',
| value: 'mutations',
| checked: true
| },
| {
| name: 'actions',
| value: 'actions',
| checked: true
| }
| ],
| validate(value) {
| if (!value.includes('state') || !value.includes('mutations')) {
| return 'store require at least state and mutations'
| }
| return true
| }
| }
| ],
| actions(data) {
| const name = '{{name}}'
| const { blocks } = data
| const options = ['state', 'mutations']
| const joinFlag = `,
| `
| if (blocks.length === 3) {
| options.push('actions')
| }
|
| const actions = [{
| type: 'add',
| path: `src/store/modules/${name}.js`,
| templateFile: 'plop-templates/store/index.hbs',
| data: {
| options: options.join(joinFlag),
| state: blocks.includes('state'),
| mutations: blocks.includes('mutations'),
| actions: blocks.includes('actions')
| }
| }]
| return actions
| }
| }
|
|