Skip to content

Load template from fs if directory exists. #3

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

Merged
merged 1 commit into from
Dec 29, 2015
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
42 changes: 27 additions & 15 deletions bin/vue-init
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down