diff --git a/bin/vue b/bin/vue index c65d1485b5..c1057bed9b 100755 --- a/bin/vue +++ b/bin/vue @@ -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) diff --git a/bin/vue-create b/bin/vue-create new file mode 100755 index 0000000000..77bd7b4f54 --- /dev/null +++ b/bin/vue-create @@ -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); + }) + +} diff --git a/lib/create-template.html b/lib/create-template.html new file mode 100755 index 0000000000..75f14deb34 --- /dev/null +++ b/lib/create-template.html @@ -0,0 +1,43 @@ + + + + +