Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
feat: hook up remaining functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
johnleider committed Oct 6, 2019
1 parent 3ff4c3e commit 6f6df8e
Show file tree
Hide file tree
Showing 18 changed files with 766 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
@@ -0,0 +1,2 @@
# Vuetify CLI
Coming soon...
5 changes: 4 additions & 1 deletion generator/index.js
@@ -1,7 +1,10 @@
module.exports = api => {
api.extendPackage({
scripts: {
'create:component': 'node ./node_modules/vue-cli-plugin-vuetify-cli'
'make:component': 'vue-cli-service make:component',
'make:directive': 'vue-cli-service make:directive',
'make:mixin': 'vue-cli-service make:mixin',
'make:view': 'vue-cli-service make:view',
}
})
}
21 changes: 21 additions & 0 deletions generator/templates/component/Component.spec.js
@@ -0,0 +1,21 @@
// Component
import { Component } from './index'

// Utilities
import { shallow, createLocalVue } from '@vue/test-utils'

// Bootstrap
const localVue = createLocalVue()

describe('Component', () => {
function mountFunction(options = {}) {
return shallow(Component, {
localVue,
...options,
})
}

it('should work', () => {
const wrapper = mountFunction()
})
})
15 changes: 15 additions & 0 deletions generator/templates/component/Component.vue
@@ -0,0 +1,15 @@
<template>
<div>
<!-- -->
</div>
</template>

<script>
export default {
name: 'Component',
}
</script>

<style lang="sass">
//
</style>
1 change: 1 addition & 0 deletions generator/templates/component/index.js
@@ -0,0 +1 @@
export { Component } from './Component'
35 changes: 35 additions & 0 deletions generator/templates/directive/directive.spec.js
@@ -0,0 +1,35 @@
// Directive
import { directive } from './index'

// Utilities
import { shallow, createLocalVue } from '@vue/test-utils'

// Variables
const Mock = {
directives: { directive },

render (h) {
return h('div', {
directives: [{
name: 'directive',
value: false,
}],
})
},
}

// Bootstrap
function mountFunction(options = {}) {
return shallow(Mock, {
localVue,
...options,
})
}

const localVue = createLocalVue()

describe('directive', () => {
it('should work', () => {
const wrapper = mountFunction()
})
})
27 changes: 27 additions & 0 deletions generator/templates/directive/index.js
@@ -0,0 +1,27 @@
function bind (el, binding, vnode, oldVnode) {
//
}

function inserted (el) {
//
}

function update (el, binding, vnode, oldVnode) {
//
}

function componentUpdated (el, binding, vnode, oldVnode) {
//
}

function unbind (el, binding, vnode, oldVnode) {
//
}

export default {
bind,
inserted,
update,
componentUpdated,
unbind
}
3 changes: 3 additions & 0 deletions generator/templates/mixin/index.js
@@ -0,0 +1,3 @@
export const Mixin = {
name: 'Mixin'
}
27 changes: 27 additions & 0 deletions generator/templates/mixin/mixin.spec.js
@@ -0,0 +1,27 @@
// Mixin
import { mixin } from './index'

// Utilities
import { shallow, createLocalVue } from '@vue/test-utils'

// Variables
const Mock = {
mixins: [mixin],
render: h => h('div'),
}

// Bootstrap
function mountFunction(options = {}) {
return shallow(Mock, {
localVue,
...options,
})
}

const localVue = createLocalVue()

describe('mixin', () => {
it('should work', () => {
const wrapper = mountFunction()
})
})
11 changes: 11 additions & 0 deletions generator/templates/view/Index.vue
@@ -0,0 +1,11 @@
<template>
<section id="view">
<!-- -->
</section>
</template>

<script>
export default {
name: 'View',
}
</script>
12 changes: 12 additions & 0 deletions index.js
@@ -0,0 +1,12 @@
const fs = require('fs')
const path = require('path')
const resolve = dir => path.resolve(__dirname, dir)

module.exports = api => {
const commands = resolve('./lib/commands')

// Import and register all commands
fs.readdirSync(commands).forEach(command => {
require(`${commands}/${command}`)(api)
})
}
74 changes: 74 additions & 0 deletions lib/commands/make-component.js
@@ -0,0 +1,74 @@
// Imports
const camelCase = require('lodash/camelCase')
const fs = require('fs')
const inquire = require('inquirer')
const upperFirst = require('lodash/upperFirst')
const { writeFiles } = require('../../util/helpers.js')

// Variables
const views = []
const types = [
{ name: 'Regular', value: '' },
{ name: 'Base', value: 'base/' },
{ name: 'Core', value: 'core/' },
]

if (fs.existsSync('src/views')) {
fs.readdirSync('src/views').forEach(dir => {
views.push(`${dir}/`)
})
}

if (views.length > 0) {
types.push({
name: 'View',
value: 'view'
})
}

const questions = [
{
type: 'list',
message: 'Component type:',
name: 'type',
choices: types
},
{
type: 'list',
message: 'Select the view',
name: 'view',
choices: views,
when: options => options.type === 'view',
},
{
type: 'input',
message: 'Component name:',
name: 'name',
filter: val => upperFirst(camelCase(val))
}
]

async function command (api) {
const make = options => {
if (options.view) {
options.type = `../views/${options.view}/components/`
}

writeFiles('component', options, api)
}

inquire
.prompt(questions)
.then(make)
}

module.exports = api => {
api.registerCommand('make:component', {
description: 'scaffold a new vue component',
usage: 'vue-cli-service make:component [options]',
options: {
'--name': 'specify component name',
'--type': 'specify component type',
}
}, () => command(api))
}
32 changes: 32 additions & 0 deletions lib/commands/make-directive.js
@@ -0,0 +1,32 @@
// Imports
const inquire = require('inquirer')
const kebabcase = require('lodash/kebabcase')
const { writeFiles } = require('../../util/helpers.js')

// Variables
const questions = [
{
type: 'input',
message: 'Directive name:',
name: 'name',
filter: kebabcase
}
]

async function command (api) {
const make = options => writeFiles('directive', options, api)

inquire
.prompt(questions)
.then(make)
}

module.exports = api => {
api.registerCommand('make:directive', {
description: 'scaffold a new vue directive',
usage: 'vue-cli-service make:directive [options]',
options: {
'--name': 'specify directive name'
}
}, () => command(api))
}
32 changes: 32 additions & 0 deletions lib/commands/make-mixin.js
@@ -0,0 +1,32 @@
// Imports
const inquire = require('inquirer')
const kebabcase = require('lodash/kebabcase')
const { writeFiles } = require('../../util/helpers.js')

// Variables
const questions = [
{
type: 'input',
message: 'Mixin name:',
name: 'name',
filter: kebabcase
}
]

async function command (api) {
const make = options => writeFiles('mixin', options, api)

inquire
.prompt(questions)
.then(make)
}

module.exports = api => {
api.registerCommand('make:mixin', {
description: 'scaffold a new vue mixin',
usage: 'vue-cli-service make:mixin [options]',
options: {
'--name': 'specify mixin name'
}
}, () => command(api))
}
32 changes: 32 additions & 0 deletions lib/commands/make-view.js
@@ -0,0 +1,32 @@
// Imports
const inquire = require('inquirer')
const kebabcase = require('lodash/kebabcase')
const { writeFiles } = require('../../util/helpers.js')

// Variables
const questions = [
{
type: 'input',
message: 'View name:',
name: 'name',
filter: kebabcase
}
]

async function command (api) {
const make = options => writeFiles('view', options, api)

inquire
.prompt(questions)
.then(make)
}

module.exports = api => {
api.registerCommand('make:view', {
description: 'scaffold a new vue view',
usage: 'vue-cli-service make:view [options]',
options: {
'--name': 'specify view name'
}
}, () => command(api))
}
10 changes: 8 additions & 2 deletions package.json
@@ -1,8 +1,14 @@
{
"name": "vuetify-cli",
"name": "vue-cli-plugin-vuetify-cli",
"version": "0.0.0",
"description": "A Scaffolding Tool for Vue / Vuetify",
"main": "index.js",
"author": "John Leider",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"inquirer": "^7.0.0",
"lodash": "^4.17.15",
"pluralize": "^8.0.0",
"shelljs": "^0.8.3"
}
}

0 comments on commit 6f6df8e

Please sign in to comment.