Skip to content

Commit 1a4286d

Browse files
committed
Merge pull request #3 from zigomir/master
Load template from fs if directory exists.
2 parents c3689ea + a4924b0 commit 1a4286d

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ You can also create your own template from scratch:
5454
- 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.
5555

5656
- 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).
57+
58+
While developing your template you can test via `vue-cli` with:
59+
60+
``` bash
61+
vue init ~/fs/path/to-custom-template my-project
62+
```

bin/vue-init

+27-15
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,39 @@ var to = resolve(name)
6161
if (exists(to)) logger.fatal('"%s" already exists.', name)
6262

6363
/**
64-
* Detect official template.
64+
* Detect if template on file system.
6565
*/
6666

67-
if (!~template.indexOf('/')) {
68-
template = 'vuejs-templates/' + template
69-
}
70-
71-
/**
72-
* Download and generate.
73-
*/
74-
75-
var tmp = '/tmp/vue-template-' + uid()
76-
download(template, tmp, function (err) {
77-
if (err) logger.fatal(err)
78-
generate(tmp, to, function (err) {
67+
if (exists(template)) {
68+
generate(template, to, function (err) {
7969
if (err) logger.fatal(err)
80-
rm(tmp)
8170
console.log()
8271
logger.success('Generated "%s".', name)
8372
})
84-
})
73+
} else {
74+
/**
75+
* Detect official template.
76+
*/
77+
78+
if (!~template.indexOf('/')) {
79+
template = 'vuejs-templates/' + template
80+
}
81+
82+
/**
83+
* Download and generate.
84+
*/
85+
86+
var tmp = '/tmp/vue-template-' + uid()
87+
download(template, tmp, function (err) {
88+
if (err) logger.fatal(err)
89+
generate(tmp, to, function (err) {
90+
if (err) logger.fatal(err)
91+
rm(tmp)
92+
console.log()
93+
logger.success('Generated "%s".', name)
94+
})
95+
})
96+
}
8597

8698
/**
8799
* Generate a template given a `src` and `dest`.

0 commit comments

Comments
 (0)