diff --git a/README.md b/README.md index d0cef04d59..4a32c15a54 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,9 @@ You can also create your own template from scratch: - 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). + +While developing your template you can test via `vue-cli` with: + +``` bash +vue init ~/fs/path/to-custom-template my-project +``` diff --git a/bin/vue-init b/bin/vue-init index e14289af9b..88551cb9d5 100755 --- a/bin/vue-init +++ b/bin/vue-init @@ -61,27 +61,39 @@ var to = resolve(name) if (exists(to)) logger.fatal('"%s" already exists.', name) /** - * Detect official template. + * Detect if template on file system. */ -if (!~template.indexOf('/')) { - template = 'vuejs-templates/' + template -} - -/** - * Download and generate. - */ - -var tmp = '/tmp/vue-template-' + uid() -download(template, tmp, function (err) { - if (err) logger.fatal(err) - generate(tmp, to, function (err) { +if (exists(template)) { + generate(template, to, function (err) { if (err) logger.fatal(err) - rm(tmp) console.log() logger.success('Generated "%s".', name) }) -}) +} else { + /** + * Detect official template. + */ + + if (!~template.indexOf('/')) { + template = 'vuejs-templates/' + template + } + + /** + * Download and generate. + */ + + var tmp = '/tmp/vue-template-' + uid() + download(template, tmp, function (err) { + if (err) logger.fatal(err) + generate(tmp, to, function (err) { + if (err) logger.fatal(err) + rm(tmp) + console.log() + logger.success('Generated "%s".', name) + }) + }) +} /** * Generate a template given a `src` and `dest`.