File tree Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Expand file tree Collapse file tree 3 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 1+ {{ #if state }}
2+ const state = {}
3+ {{ /if }}
4+
5+ {{ #if mutations }}
6+ const mutations = {}
7+ {{ /if }}
8+
9+ {{ #if actions }}
10+ const actions = {}
11+ {{ /if }}
12+
13+ export default {
14+ namespaced: true,
15+ {{ options }}
16+ }
Original file line number Diff line number Diff line change 1+ const { notEmpty } = require ( '../utils.js' )
2+
3+ module . exports = {
4+ description : 'generate store' ,
5+ prompts : [ {
6+ type : 'input' ,
7+ name : 'name' ,
8+ message : 'store name please' ,
9+ validate : notEmpty ( 'name' )
10+ } ,
11+ {
12+ type : 'checkbox' ,
13+ name : 'blocks' ,
14+ message : 'Blocks:' ,
15+ choices : [ {
16+ name : 'state' ,
17+ value : 'state' ,
18+ checked : true
19+ } ,
20+ {
21+ name : 'mutations' ,
22+ value : 'mutations' ,
23+ checked : true
24+ } ,
25+ {
26+ name : 'actions' ,
27+ value : 'actions' ,
28+ checked : true
29+ }
30+ ] ,
31+ validate ( value ) {
32+ if ( ! value . includes ( 'state' ) || ! value . includes ( 'mutations' ) ) {
33+ return 'store require at least state and mutations'
34+ }
35+ return true
36+ }
37+ }
38+ ] ,
39+ actions ( data ) {
40+ const name = '{{name}}'
41+ const { blocks } = data
42+ const options = [ 'state' , 'mutations' ]
43+ const joinFlag = `,
44+ `
45+ if ( blocks . length === 3 ) {
46+ options . push ( 'actions' )
47+ }
48+
49+ const actions = [ {
50+ type : 'add' ,
51+ path : `src/store/modules/${ name } .js` ,
52+ templateFile : 'plop-templates/store/index.hbs' ,
53+ data : {
54+ options : options . join ( joinFlag ) ,
55+ state : blocks . includes ( 'state' ) ,
56+ mutations : blocks . includes ( 'mutations' ) ,
57+ actions : blocks . includes ( 'actions' )
58+ }
59+ } ]
60+ return actions
61+ }
62+ }
Original file line number Diff line number Diff line change 11const viewGenerator = require ( './plop-templates/view/prompt' )
22const componentGenerator = require ( './plop-templates/component/prompt' )
3+ const storeGenerator = require ( './plop-templates/store/prompt.js' )
34
45module . exports = function ( plop ) {
56 plop . setGenerator ( 'view' , viewGenerator )
67 plop . setGenerator ( 'component' , componentGenerator )
8+ plop . setGenerator ( 'store' , storeGenerator )
79}
You can’t perform that action at this time.
0 commit comments