Skip to content

Commit

Permalink
fix: fix project creation when path contains spaces (fix #742)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 29, 2018
1 parent b8f2487 commit 5be05f3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
25 changes: 11 additions & 14 deletions packages/@vue/cli/lib/GeneratorAPI.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
const fs = require('fs')
const ejs = require('ejs')
const path = require('path')
const walk = require('klaw-sync')
const globby = require('globby')
const isBinary = require('isbinaryfile')
const mergeDeps = require('./util/mergeDeps')
const errorParser = require('error-stack-parser')

const isString = val => typeof val === 'string'
const isFunction = val => typeof val === 'function'
Expand Down Expand Up @@ -52,25 +51,22 @@ module.exports = class GeneratorAPI {
const baseDir = extractCallDir()
if (isString(fileDir)) {
fileDir = path.resolve(baseDir, fileDir)
this.injectFileMiddleware(files => {
this.injectFileMiddleware(async (files) => {
const data = Object.assign({
options: this.options,
rootOptions: this.rootOptions
}, additionalData)
const _files = walk(fileDir, {
nodir: true,
filter: file => path.basename(file.path) !== '.DS_Store'
})
for (const file of _files) {
let filename = path.basename(file.path)
const _files = await globby(['**/*'], { cwd: fileDir })
for (const rawPath of _files) {
let filename = path.basename(rawPath)
// dotfiles are ignored when published to npm, therefore in templates
// we need to use underscore instead (e.g. "_gitignore")
if (filename.charAt(0) === '_') {
filename = `.${filename.slice(1)}`
}
const normalizedPath = path.join(path.dirname(file.path), filename)
const targetPath = path.relative(fileDir, normalizedPath)
const content = renderFile(file.path, data, ejsOptions)
const targetPath = path.join(path.dirname(rawPath), filename)
const sourcePath = path.resolve(fileDir, rawPath)
const content = renderFile(sourcePath, data, ejsOptions)
// only set file if it's not all whitespace, or is a Buffer (binary files)
if (Buffer.isBuffer(content) || /[^\s]/.test(content)) {
files[targetPath] = content
Expand Down Expand Up @@ -117,8 +113,9 @@ function extractCallDir () {
// extract api.render() callsite file location using error stack
const obj = {}
Error.captureStackTrace(obj)
const stack = errorParser.parse(obj)
return path.dirname(stack[2].fileName)
const callSite = obj.stack.split('\n')[3]
const fileName = callSite.match(/\s\((.*):\d+:\d+\)$/)[1]
return path.dirname(fileName)
}

function renderFile (name, data, ejsOptions) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"chalk": "^2.3.0",
"commander": "^2.12.2",
"ejs": "^2.5.7",
"error-stack-parser": "^2.0.1",
"execa": "^0.8.0",
"globby": "^7.1.1",
"import-global": "^0.1.0",
"inquirer": "^4.0.1",
"isbinaryfile": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3270,7 +3270,7 @@ error-ex@^1.2.0, error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

error-stack-parser@^2.0.0, error-stack-parser@^2.0.1:
error-stack-parser@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.1.tgz#a3202b8fb03114aa9b40a0e3669e48b2b65a010a"
dependencies:
Expand Down

0 comments on commit 5be05f3

Please sign in to comment.