Nascent Personality Manifestation
Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

@calidae/vue-generate-component

1.1.1 • Public • Published

Vue js component generator

Developed upon the work of vue-generate-component.

CLI util for easy generate Vue component structure.

Installation

npm install -g @calidae/vue-generate-component

If you want to try it out without polluting your global npm, you can use npx:

npx @calidae/vue-generate-component [ARGUMENTS]

Usage

Create new component

vgc Footer

Will generate a folder called Footer in your current directory with three files :

index.js

import Footer from './Footer'
 
export default Footer

Footer.vue

<template>
  <div class="Footer">
    
  </div>
</template>
 
<script>
export default {
  name: 'Footer',
  data () {
    return {}
  }
}
</script>
 
<style lang="scss" scoped>
 
</style>
 

Footer.spec.js

import Footer from './index.js'
import { mount } from '@vue/test-utils'
 
describe('Footer.vue', () => {
  it('is a component', () => {
    const wrapper = mount(Footer)
    expect(wrapper.isVueInstance()).toBeTruthy()
  })
 
  it('renders main node', () => {
    const wrapper = mount(Footer)
    expect(wrapper.classes()).toContain('Footer')
  })
 
  it('renders a snapshot', () => {
    const wrapper = mount(Footer)
    expect(wrapper.html()).toMatchSnapshot('default')
  })
})

Creating a folder with Container Component

If you want to replicate the structure outlined above but adding a Container component, add the container flag:

vgc Footer --container

In addition to previously outlined files, this command will modify index.js:

index.js

import FooterContainer from './FooterContainer'
 
export default FooterContainer

and create 2 new files:

FooterContainer.vue

<template>
  <Footer />
</template>
 
<script>
import Footer from './Footer'
 
export default {
  name: 'FooterContainer',
  components: {
    Footer
  },
  data () {
    return {}
  }
}
</script>

FooterContainer.spec.js

import FooterContainer from './FooterContainer'
import { mount } from '@vue/test-utils'
 
describe('FooterContainer.vue', () => {
  it('is a component', () => {
    const wrapper = mount(FooterContainer)
    expect(wrapper.isVueInstance()).toBeTruthy()
  })
 
  it('renders a snapshot', () => {
    const wrapper = mount(FooterContainer)
    expect(wrapper.html()).toMatchSnapshot('default')
  })
})

Disclaimer

This project tries to solve tedious copy&paste operations from our daily workflow. Please notice that the generated files will require some external libraries such as Vue or @vue/test-utils. Make sure these libraries are available in your project.

TODO

  1. Add tests(!)
  2. Add ability to define folder path (now it only creates a folder in the current directory)
  3. ...

install

npm i @calidae/vue-generate-component

Downloadsweekly downloads

6

version

1.1.1

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
Report a vulnerability