Skip to content
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
}