Skip to content

Commit 1892bcc

Browse files
committed
fix(generator): handle directories starting with dot
close #2222
1 parent 1e7fa2c commit 1892bcc

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

packages/@vue/cli/__tests__/Generator.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ new Vue({
2222
}).$mount('#app')
2323
`.trim())
2424

25+
// replace stubs
2526
fs.writeFileSync(path.resolve(templateDir, 'replace.js'), `
2627
---
2728
extend: '${path.resolve(templateDir, 'bar/bar.js')}'
@@ -51,6 +52,11 @@ qux($1)
5152
<%# END_REPLACE %>
5253
`.trim())
5354

55+
// dotfile stubs
56+
fs.ensureDirSync(path.resolve(templateDir, '_vscode'))
57+
fs.writeFileSync(path.resolve(templateDir, '_vscode/config.json'), `{}`)
58+
fs.writeFileSync(path.resolve(templateDir, '_gitignore'), 'foo')
59+
5460
test('api: extendPackage', async () => {
5561
const generator = new Generator('/', {
5662
pkg: {
@@ -343,6 +349,8 @@ test('api: render fs directory', async () => {
343349
expect(fs.readFileSync('/bar/bar.js', 'utf-8')).toMatch('bar(2)')
344350
expect(fs.readFileSync('/replace.js', 'utf-8')).toMatch('baz(2)')
345351
expect(fs.readFileSync('/multi-replace.js', 'utf-8')).toMatch('baz(1)\nqux(2)')
352+
expect(fs.readFileSync('/.gitignore', 'utf-8')).toMatch('foo')
353+
expect(fs.readFileSync('/.vscode/config.json', 'utf-8')).toMatch('{}')
346354
})
347355

348356
test('api: render object', async () => {

packages/@vue/cli/lib/GeneratorAPI.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,17 @@ class GeneratorAPI {
169169
const globby = require('globby')
170170
const _files = await globby(['**/*'], { cwd: source })
171171
for (const rawPath of _files) {
172-
let filename = path.basename(rawPath)
173-
// dotfiles are ignored when published to npm, therefore in templates
174-
// we need to use underscore instead (e.g. "_gitignore")
175-
if (filename.charAt(0) === '_' && filename.charAt(1) !== '_') {
176-
filename = `.${filename.slice(1)}`
177-
}
178-
if (filename.charAt(0) === '_' && filename.charAt(1) === '_') {
179-
filename = `${filename.slice(1)}`
180-
}
181-
const targetPath = path.join(path.dirname(rawPath), filename)
172+
const targetPath = rawPath.split(path.sep).map(filename => {
173+
// dotfiles are ignored when published to npm, therefore in templates
174+
// we need to use underscore instead (e.g. "_gitignore")
175+
if (filename.charAt(0) === '_' && filename.charAt(1) !== '_') {
176+
return `.${filename.slice(1)}`
177+
}
178+
if (filename.charAt(0) === '_' && filename.charAt(1) === '_') {
179+
return `${filename.slice(1)}`
180+
}
181+
return filename
182+
}).join(path.sep)
182183
const sourcePath = path.resolve(source, rawPath)
183184
const content = renderFile(sourcePath, data, ejsOptions)
184185
// only set file if it's not all whitespace, or is a Buffer (binary files)

0 commit comments

Comments
 (0)