mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-09-07 02:19:49 +08:00
add
This commit is contained in:
parent
8c091ce980
commit
580b5157c8
26
plop-templates/component/index.hbs
Normal file
26
plop-templates/component/index.hbs
Normal file
@ -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}}
|
@ -1,13 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
div
|
|
||||||
{{banana}}
|
|
||||||
</template>
|
|
||||||
<script lang="ts">
|
|
||||||
import Vue from 'vue'
|
|
||||||
export default Vue.extend({
|
|
||||||
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
|
|
||||||
</style>
|
|
55
plop-templates/component/prompt.js
Normal file
55
plop-templates/component/prompt.js
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
9
plop-templates/utils.js
Normal file
9
plop-templates/utils.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
exports.notEmpty = name => {
|
||||||
|
return v => {
|
||||||
|
if (!v || v.trim === '') {
|
||||||
|
return `${name} is required`
|
||||||
|
} else {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
26
plop-templates/view/index.hbs
Normal file
26
plop-templates/view/index.hbs
Normal file
@ -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}}
|
55
plop-templates/view/prompt.js
Normal file
55
plop-templates/view/prompt.js
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
62
plopfile.js
62
plopfile.js
@ -1,61 +1,7 @@
|
|||||||
const notEmpty = name => {
|
const viewGenerator = require('./plop-templates/view/prompt')
|
||||||
return v => {
|
const componentGenerator = require('./plop-templates/component/prompt')
|
||||||
if (!v || v.trim === '') {
|
|
||||||
return `${name} is required`
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function(plop) {
|
module.exports = function(plop) {
|
||||||
const name = '{{ properCase name }}'
|
plop.setGenerator('view', viewGenerator)
|
||||||
plop.setGenerator('component', {
|
plop.setGenerator('component', componentGenerator)
|
||||||
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: [{
|
|
||||||
type: 'add',
|
|
||||||
path: `src/components/${name}/index.vue`,
|
|
||||||
templateFile: 'plop-templates/component/index.vue',
|
|
||||||
data: {
|
|
||||||
banana: 'banana'
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
})
|
|
||||||
|
|
||||||
plop.setGenerator('none', {})
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user