From 753b2933768c218cfc752d773b0798278e7e5304 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 26 Dec 2015 18:10:37 -0500 Subject: [PATCH 001/160] init --- .gitignore | 2 + README.md | 42 +++++++++++++++ bin/vue | 74 +++++++++++++++++++++++++ bin/vue-init | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++ bin/vue-list | 19 +++++++ lib/logger.js | 45 ++++++++++++++++ package.json | 38 +++++++++++++ 7 files changed, 367 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100755 bin/vue create mode 100755 bin/vue-init create mode 100755 bin/vue-list create mode 100644 lib/logger.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..9daa8247da --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +node_modules diff --git a/README.md b/README.md new file mode 100644 index 0000000000..fcf197aac7 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# vue-cli + +A simple CLI for scaffolding Vue.js projects. + +### Installation + +``` bash +$ npm install -g vue-cli +``` + +### Usage + +``` bash +$ vue init webpack my-project +$ cd my-project +$ npm install +$ npm run dev +``` + +The above command pulls the template from [vuejs-templates/webpack](https://github.com/vuejs-templates/webpack), prompts for some information, and generates the project at `.my-project/`. + +When a new template is added to the `vuejs-templates` organization, you will be able to run `vue init ` to use that template. + +You can run `vue list` to see all available official templates. + +### Custom Templates + +It's unlikely to make everyone happy with the official templates. You can simply fork an official template and then use it via `vue-cli` with: + +``` bash +vue init username/repo my-project +``` + +Where `username/repo` is the GitHub repo shorthand for your fork. + +You can also create your own template from scratch: + +- A template repo **must** have a `template` directory that holds the template files. + +- All template files will be piped through Handlebars for simple templating - `vue-cli` will automatically infer the prompts based on `{{}}` interpolations found in the files. + +- A template repo **may** have a `meta.json` file that provides a schema for the prompts. The schema will be passed to [prompt-for](https://github.com/segmentio/prompt-for#prompt-for) as options. See [example](https://github.com/vuejs-templates/webpack/blob/master/meta.json). diff --git a/bin/vue b/bin/vue new file mode 100755 index 0000000000..3e0c7bb7c1 --- /dev/null +++ b/bin/vue @@ -0,0 +1,74 @@ +#!/usr/bin/env node + +var exists = require('fs').existsSync +var join = require('path').join +var logger = require('../lib/logger') +var program = require('commander') +var resolve = require('path').resolve +var spawn = require('child_process').spawn +var stat = require('fs').statSync + +/** + * Usage. + */ + +program + .version(require('../package').version) + .usage(' [options]') + +/** + * Help. + */ + +program.on('--help', function () { + console.log(' Commands:') + console.log() + console.log(' init generate a new project from a template') + console.log(' list list available official templates') + console.log() +}) + +/** + * Parse. + */ + +program.parse(process.argv) +if (!program.args.length) program.help() + +/** + * Padding. + */ + +console.log() +process.on('exit', function () { + console.log() +}) + +/** + * Settings. + */ + +var cmd = program.args[0] +var args = process.argv.slice(3) +var name = 'vue-' + cmd + +/** + * Resolve a local or remote executable. + */ + +var bin = join(__dirname, name) +if (!exists(bin)) { + bin = process.env.PATH.split(':').reduce(function (binary, path) { + path = resolve(path, bin) + return exists(path) && stat(path).isFile() ? path : binary + }, bin) +} + +if (!exists(bin)) logger.fatal('The "%s" command does not exist.', name) + +/** + * Spawn a new, forwarded child process with the executable. + */ + +spawn(bin, args, { stdio: 'inherit' }) + .on('close', process.exit.bind(process)) diff --git a/bin/vue-init b/bin/vue-init new file mode 100755 index 0000000000..a67b750a84 --- /dev/null +++ b/bin/vue-init @@ -0,0 +1,147 @@ +#!/usr/bin/env node + +var Khaos = require('khaos') +var metadata = require('read-metadata') +var download = require('download-github-repo') +var logger = require('../lib/logger') +var program = require('commander') +var exists = require('fs').existsSync +var join = require('path').join +var resolve = require('path').resolve +var rm = require('rimraf').sync +var uid = require('uid') + +/** + * Usage. + */ + +program + .usage('