Skip to content

Commit

Permalink
only look for local templates if path starts with . or / (fix #240)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 16, 2016
1 parent 8b41f67 commit e502e46
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions bin/vue-init
Expand Up @@ -64,7 +64,6 @@ process.on('exit', function () {
var template = program.args[0]
var hasSlash = template.indexOf('/') > -1
var rawName = program.args[1]
var templatePath = exists(template) ? template : path.normalize(path.join(process.cwd(), template))
var inPlace = !rawName || rawName === '.'
var name = inPlace ? path.relative('../', process.cwd()) : rawName
var to = path.resolve(rawName || '.')
Expand Down Expand Up @@ -92,12 +91,19 @@ if (exists(to)) {

function run () {
// check if template is local
if (exists(templatePath)) {
generate(name, templatePath, to, function (err) {
if (err) logger.fatal(err)
console.log()
logger.success('Generated "%s".', name)
})
if (/^[./]/.test(template)) {
var templatePath = template.charAt(0) === '/'
? template
: path.normalize(path.join(process.cwd(), template))
if (exists(templatePath)) {
generate(name, templatePath, to, function (err) {
if (err) logger.fatal(err)
console.log()
logger.success('Generated "%s".', name)
})
} else {
logger.fatal('Local template "%s" not found.', template)
}
} else {
checkVersion(function () {
if (!hasSlash) {
Expand Down

2 comments on commit e502e46

@Akryum
Copy link
Member

@Akryum Akryum commented on e502e46 Dec 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents absolute paths from working on Windows.

@yyx990803
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm yeah, would take a PR

Please sign in to comment.