Skip to content

cli: fix local template path for windows #104

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

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 7 additions & 3 deletions bin/vue-init
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var path = require('path')
var rm = require('rimraf').sync
var uid = require('uid')
var ora = require('ora')
var url = require('url')
var chalk = require('chalk')
var inquirer = require('inquirer')
var request = require('request')
Expand Down Expand Up @@ -61,7 +62,6 @@ process.on('exit', function () {
*/

var template = program.args[0]
var hasSlash = template.indexOf('/') > -1
var rawName = program.args[1]
var inPlace = !rawName || rawName === '.'
var name = inPlace ? path.relative('../', process.cwd()) : rawName
Expand Down Expand Up @@ -90,15 +90,15 @@ if (exists(to)) {

function run () {
// check if template is local
if (hasSlash && exists(template)) {
if (isLocal(template) && exists(template)) {
generate(name, template, to, function (err) {
if (err) logger.fatal(err)
console.log()
logger.success('Generated "%s".', name)
})
} else {
checkVersion(function () {
if (!hasSlash) {
if (!isLocal(template)) {
// use official templates
template = 'vuejs-templates/' + template
checkDistBranch(template, downloadAndGenerate)
Expand Down Expand Up @@ -158,3 +158,7 @@ function downloadAndGenerate (template) {
})
})
}

function isLocal (str) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isLocal implies more than just that str is string and not an url. In my opinion exist should also be called here.

  • you can easily add test for it ;)

return typeof str === 'string' && !url.parse(str).hostname
}