forked from PanJiaChen/vue-element-admin
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plop new generate store (PanJiaChen#2805)
- Loading branch information
1 parent
e1554fd
commit 65d8c45
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{#if state}} | ||
const state = {} | ||
{{/if}} | ||
|
||
{{#if mutations}} | ||
const mutations = {} | ||
{{/if}} | ||
|
||
{{#if actions}} | ||
const actions = {} | ||
{{/if}} | ||
|
||
export default { | ||
namespaced: true, | ||
{{options}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
const viewGenerator = require('./plop-templates/view/prompt') | ||
const componentGenerator = require('./plop-templates/component/prompt') | ||
const storeGenerator = require('./plop-templates/store/prompt.js') | ||
|
||
module.exports = function(plop) { | ||
plop.setGenerator('view', viewGenerator) | ||
plop.setGenerator('component', componentGenerator) | ||
plop.setGenerator('store', storeGenerator) | ||
} |