项目初始化
diff --git a/frontend/plop-templates/component/index.hbs b/frontend/plop-templates/component/index.hbs
new file mode 100644
index 0000000..7661055
--- /dev/null
+++ b/frontend/plop-templates/component/index.hbs
@@ -0,0 +1,26 @@
+{{#if template}}
+<template>
+ <div />
+</template>
+{{/if}}
+
+{{#if script}}
+<script>
+export default {
+ name: '{{ properCase name }}',
+ props: {},
+ data() {
+ return {}
+ },
+ created() {},
+ mounted() {},
+ methods: {}
+}
+</script>
+{{/if}}
+
+{{#if style}}
+<style lang="scss" scoped>
+
+</style>
+{{/if}}
diff --git a/frontend/plop-templates/component/prompt.js b/frontend/plop-templates/component/prompt.js
new file mode 100644
index 0000000..3723e8e
--- /dev/null
+++ b/frontend/plop-templates/component/prompt.js
@@ -0,0 +1,55 @@
+const { notEmpty } = require('../utils.js')
+
+module.exports = {
+ description: 'generate vue component',
+ prompts: [{
+ type: 'input',
+ name: 'name',
+ message: 'component name please',
+ validate: notEmpty('name')
+ },
+ {
+ type: 'checkbox',
+ name: 'blocks',
+ message: 'Blocks:',
+ choices: [{
+ name: '<template>',
+ value: 'template',
+ checked: true
+ },
+ {
+ name: '<script>',
+ value: 'script',
+ checked: true
+ },
+ {
+ name: 'style',
+ value: 'style',
+ checked: true
+ }
+ ],
+ validate(value) {
+ if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
+ return 'Components require at least a <script> or <template> tag.'
+ }
+ return true
+ }
+ }
+ ],
+ actions: data => {
+ const name = '{{properCase name}}'
+ const actions = [{
+ type: 'add',
+ path: `src/components/${name}/index.vue`,
+ templateFile: 'plop-templates/component/index.hbs',
+ data: {
+ name: name,
+ template: data.blocks.includes('template'),
+ script: data.blocks.includes('script'),
+ style: data.blocks.includes('style')
+ }
+ }]
+
+ return actions
+ }
+}
diff --git a/frontend/plop-templates/store/index.hbs b/frontend/plop-templates/store/index.hbs
new file mode 100644
index 0000000..4f8e2dc
--- /dev/null
+++ b/frontend/plop-templates/store/index.hbs
@@ -0,0 +1,16 @@
+{{#if state}}
+const state = {}
+{{/if}}
+
+{{#if mutations}}
+const mutations = {}
+{{/if}}
+
+{{#if actions}}
+const actions = {}
+{{/if}}
+
+export default {
+ namespaced: true,
+ {{options}}
+}
diff --git a/frontend/plop-templates/store/prompt.js b/frontend/plop-templates/store/prompt.js
new file mode 100644
index 0000000..bcbc11d
--- /dev/null
+++ b/frontend/plop-templates/store/prompt.js
@@ -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
+ }
+}
diff --git a/frontend/plop-templates/utils.js b/frontend/plop-templates/utils.js
new file mode 100644
index 0000000..0498753
--- /dev/null
+++ b/frontend/plop-templates/utils.js
@@ -0,0 +1,2 @@
+exports.notEmpty = name => v =>
+ !v || v.trim() === '' ? `${name} is required` : true
diff --git a/frontend/plop-templates/view/index.hbs b/frontend/plop-templates/view/index.hbs
new file mode 100644
index 0000000..7661055
--- /dev/null
+++ b/frontend/plop-templates/view/index.hbs
@@ -0,0 +1,26 @@
+{{#if template}}
+<template>
+ <div />
+</template>
+{{/if}}
+
+{{#if script}}
+<script>
+export default {
+ name: '{{ properCase name }}',
+ props: {},
+ data() {
+ return {}
+ },
+ created() {},
+ mounted() {},
+ methods: {}
+}
+</script>
+{{/if}}
+
+{{#if style}}
+<style lang="scss" scoped>
+
+</style>
+{{/if}}
diff --git a/frontend/plop-templates/view/prompt.js b/frontend/plop-templates/view/prompt.js
new file mode 100644
index 0000000..1d490ee
--- /dev/null
+++ b/frontend/plop-templates/view/prompt.js
@@ -0,0 +1,55 @@
+const { notEmpty } = require('../utils.js')
+
+module.exports = {
+ description: 'generate a view',
+ prompts: [{
+ type: 'input',
+ name: 'name',
+ message: 'view name please',
+ validate: notEmpty('name')
+ },
+ {
+ type: 'checkbox',
+ name: 'blocks',
+ message: 'Blocks:',
+ choices: [{
+ name: '<template>',
+ value: 'template',
+ checked: true
+ },
+ {
+ name: '<script>',
+ value: 'script',
+ checked: true
+ },
+ {
+ name: 'style',
+ value: 'style',
+ checked: true
+ }
+ ],
+ validate(value) {
+ if (value.indexOf('script') === -1 && value.indexOf('template') === -1) {
+ return 'View require at least a <script> or <template> tag.'
+ }
+ return true
+ }
+ }
+ ],
+ actions: data => {
+ const name = '{{name}}'
+ const actions = [{
+ type: 'add',
+ path: `src/views/${name}/index.vue`,
+ templateFile: 'plop-templates/view/index.hbs',
+ data: {
+ name: name,
+ template: data.blocks.includes('template'),
+ script: data.blocks.includes('script'),
+ style: data.blocks.includes('style')
+ }
+ }]
+
+ return actions
+ }
+}