Giter Club home page Giter Club logo

vue-generate-component's Introduction

Vue js component generator Awesome

CLI util for easy generate Vue js component

Installation

npm install -g vue-generate-component

Usage

vgc --help

Create new component

vgc footer

Will generate five files:

footer.js

export default {
  name: 'footer',
  props: [],
  mounted() {},
  data() {
    return {};
  },
  methods: {},
  computed: {}
};

footer.spec.js

import Vue from 'vue';
import FooterComponent from './index.vue';

// Here are some Jasmine 2.0 tests, though you can
// use any test runner / assertion library combo you prefer
describe('FooterComponent', () => {
  // Inspect the raw component options
  it('has a created hook', () => {
    // expect(typeof FooterComponent.created).toBe('function');
  });
  // Evaluate the results of functions in
  // the raw component options
  it('sets the correct default data', () => {
    // expect(typeof FooterComponent.data).toBe('function')
    // const defaultData = FooterComponent.data();
    // expect(defaultData.message).toBe('hello!');
  });
  // Inspect the component instance on mount
  it('correctly sets the message when created', () => {
    // const vm = new Vue(FooterComponent).$mount();
    // expect(vm.message).toBe('bye!');
  });
  // Mount an instance and inspect the render output
  it('renders the correct message', () => {
    // const Ctor = Vue.extend(FooterComponent);
    // const vm = new Ctor().$mount();
    // expect(vm.$el.textContent).toBe('bye!');
  });
});

footer.html

<section class="footer">
  <h1>footer Component</h1>
</section>

footer.scss

.footer {
}

index.vue

<template src="./footer.component.html"></template>
<script src="./footer.component.js"></script>
<style src="./footer.component.scss" scoped lang="scss"></style>

Create new component single file

vgc -s home

will generate one vue file:

<template lang="html">
  <section class="home">
    <h1>home Component</h1>
  </section>
</template>

<script lang="js">
  export default  {
    name: 'home',
    props: [],
    mounted() {

    },
    data() {
      return {

      }
    },
    methods: {

    },
    computed: {

    }
}
</script>

<style scoped lang="scss">
  .home {

  }
</style>

Create new component single file inside new folder

vgc -s home --folder

Create new directive

vgc -d my-directive

will generate:

my-directive.directive.js

import Vue from 'vue';

Vue.directive('my-directive', {
  bind() {},
  // When the bound element is inserted into the DOM...
  inserted(el) {
    // el.focus();
  },
  update() {},
  unbind() {}
});

If you want use postfix in file name, use -- postfix

vgc footer --postfix page

Will generate files with postfix:

  • footer.page.js
  • footer.page.css
  • footer.page.html
  • footer.page.spec.js

Change the default file types for html, style, script, and spec

sudo vgc --html jade --style less --script ts --spec ts

Contribute

If you want to fix/improve the templates you're welcome to create a PR.

vue-generate-component's People

Contributors

akleandrov avatar crispmark avatar dependabot[bot] avatar gprocks avatar harshppatel avatar izerozlu avatar jamielottering avatar javimatz avatar kinoli avatar netanelbasal avatar wwalkerlogmein avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-generate-component's Issues

Specify destination folder

Hey, your package rocks! ๐Ÿ’ฏ

Just wondering if you would accept a PR that implements a destination folder option for the generated .vue

I would use that feature since I wish to use 'vgc' inside package.json scripts such as:
... "scripts": { "component" : "vgc process.env.name --dest=./assets/js/" } ...

And call it like: npm run component --name=Home

Hope it was clear enough!

Project build is broken?

When running npm install in the directory i receive the following error:

fs.js:39
} = primordials;
    ^

ReferenceError: primordials is not defined
    at fs.js:39:5

my env:

npm --version
6.14.4

 gulp --version
[22:28:16] CLI version 1.4.0
[22:28:16] Local version 3.9.1

offer to fix the path in the file name

TemplateGenerator.js

add something like this:

...
key: '_createDirectory',
value: function _createDirectory(dirPath, data, fileTypes) {
...
name = name.split('/').slice(-1).join('').split('\'').slice(-1).join('');

so that you can generate a component with a path from the root of the project
like this:
vgc src/components/Home

this is probably not the best solution, but I really want to be able to generate components from the root of the project

Generate component in '/src/components' folder

Hello!
First of all, your plugin is very useful.
But I don't understand how can I generate new component directly in '/src/components' folder?

'vgc -c Brands' creates Brands folder into /
'vgc -c /src/components/Brands' creates /src/components/Brands/src/index.vue and components folder which contains Brands.component.js with name: 'src-components-brands'.

Maybe I am very stupid, but how can I achieve my goal? (All 5 files (*.html, *.js. *.scss, *.spec.js, *.vue) in /src/components/Brands folder)

Invalid filter "PascalCase" on line 28 in file

I can't create vue component using vgc ComponentName.

I don't know if command was changed for last two hours release but the error log is as shown down here.

**eli@eli:~/Documents/user/eLog/Onn/src/pages$ vgc chartsPage**

/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:183
  throw new Error(message + '.');
  ^

Error: Invalid filter "PascalCase" on line 28 in file /usr/local/lib/node_modules/vue-generate-component/dist/blueprints/component/temp.script.extension.
    at Object.exports.throwError (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:183:9)
    at TokenParser.parseToken (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:197:15)
    at /usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:86:12
    at Object.exports.each (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:45:11)
    at TokenParser.parse (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:76:11)
    at parseVariable (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:487:18)
    at /usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:635:15
    at Object.exports.each (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:45:11)
    at Object.exports.parse (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:624:9)
    at exports.Swig.parse (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/swig.js:354:19)


**eli@eli:~/Documents/user/eLog/Onn/src/pages$ vgc chartpage**
/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:183
  throw new Error(message + '.');
  ^

Error: Invalid filter "PascalCase" on line 28 in file /usr/local/lib/node_modules/vue-generate-component/dist/blueprints/component/temp.script.extension.
    at Object.exports.throwError (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:183:9)
    at TokenParser.parseToken (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:197:15)
    at /usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:86:12
    at Object.exports.each (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:45:11)
    at TokenParser.parse (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:76:11)
    at parseVariable (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:487:18)
    at /usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:635:15
    at Object.exports.each (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/utils.js:45:11)
    at Object.exports.parse (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/parser.js:624:9)
    at exports.Swig.parse (/usr/local/lib/node_modules/vue-generate-component/node_modules/swig/lib/swig.js:354:19)

https://github.com/NetanelBasal/vue-generate-component/blob/master/lib/blueprints/component/temp.script.extension#L28

app is installed but it does nothing

โžœ mypc sudo npm install -g vue-generate-component
npm WARN deprecated [email protected]: This package is no longer maintained
npm WARN deprecated [email protected]: ๐Ÿ™Œ Thanks for using Babel: we recommend using babel-preset-env now: please read https://babeljs.io/env to update!
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated [email protected]: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
npm WARN deprecated [email protected]: This module relies on Node.js's internals and will break at some point. Do not use it, and update to [email protected].
/usr/bin/vgc -> /usr/lib/node_modules/vue-generate-component/dist/vgc.js
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/vue-generate-component/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

โžœ mypc vgc --help

config file (and other suggestions)

This tool has sooooo much potential

one of the ting it could be done is to have a config file "default" settings like vgcrc or vgc.json that would set the defaults... I hate for example setting every time --script ts for every component (also the tool should know it is a ts project so should figure that on its own)

and the other thing is the ability to set in the config to not include the spec file
and the other thing, when creating the structure... would be also nice to have a setting that creates a component like

  • my-component.scss
  • my-component.html
  • my-component.vue
    where inside it would have the combination of index(.ts) and component.vue like
<template src="./my-component.html"></template>
<style src="./my-component.scss" scoped lang="scss"></style>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator';

@Component({
  components: {},
})
export default class MyComponent extends Vue {}
</script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.