Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a vue file with vue-cli #339

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ require('commander')
.command('init', 'generate a new project from a template')
.command('list', 'list available official templates')
.command('build', 'prototype a new project')
.command('create', 'craete a new vue file')
.parse(process.argv)
44 changes: 44 additions & 0 deletions bin/vue-create
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node

var program = require('commander')
var logger = require('../lib/logger')
var path = require('path');
var fs = require('fs');


program
.usage('[componentName]')
.option('-f, --folder', 'Folder name')
.parse(process.argv)


var args = program.args
var cwd = process.cwd();

if (args.length) {
createComponent()
}else{
logger.fatal("You should type the component name.")
}


function createComponent() {

var componentName = args[0];
var optionFolder = args[1];

var clivTemplate = fs.readFileSync(path.join(__dirname,'..','/lib/create-template.html'), { encoding: 'utf-8' });
var componentPath = path.join(cwd,optionFolder ? optionFolder : "/src/components");

var file = path.join(componentPath , componentName + '.vue');

if (!fs.existsSync(componentPath)){
fs.mkdirSync(componentPath);
}

fs.writeFile(file,clivTemplate,function (e) {
if (e) logger.fatal(e)
console.log("Success",file);
})

}
43 changes: 43 additions & 0 deletions lib/create-template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<div class="template">
</div>
</template>

<script>
export default {
props:[],
data () {
return {

}
},
components: {

},
beforeCreate() {

},
created() {

},
beforeMount() {

},
mounted() {

},
beforeDestroy() {

},
destroyed() {

},
methods:{

}
}
</script>

<style>

</style>