Skip to content

Commit c3217ee

Browse files
posvayyx990803
authored andcommitted
Support array in skipInterpolation (vuejs#282)
* Add test to support arrays in skipInterpolation * Support arrays in skipInterpolation Closes vuejs#281 Use multimatch instead of match for this purpose. The minimatch dependency has not been removed because it's still used in lib/filter.js. Filters should directly use multimatch. Once this happens, the dependency to minimatch can be removed. * Remove useless statement
1 parent 0d3f96d commit c3217ee

File tree

9 files changed

+80
-2
lines changed

9 files changed

+80
-2
lines changed

lib/generate.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var Handlebars = require('handlebars')
33
var async = require('async')
44
var render = require('consolidate').handlebars.render
55
var path = require('path')
6-
var match = require('minimatch')
6+
var multimatch = require('multimatch')
77
var getOptions = require('./options')
88
var ask = require('./ask')
99
var filter = require('./filter')
@@ -91,12 +91,15 @@ function filterFiles (filters) {
9191
*/
9292

9393
function renderTemplateFiles (skipInterpolation) {
94+
skipInterpolation = typeof skipInterpolation === 'string'
95+
? [skipInterpolation]
96+
: skipInterpolation
9497
return function (files, metalsmith, done) {
9598
var keys = Object.keys(files)
9699
var metalsmithMetadata = metalsmith.metadata()
97100
async.each(keys, function (file, next) {
98101
// skipping files with skipInterpolation option
99-
if (skipInterpolation && match(file, skipInterpolation, { dot: true })) {
102+
if (skipInterpolation && multimatch([file], skipInterpolation, { dot: true }).length) {
100103
return next()
101104
}
102105
var str = files[file].contents.toString()

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"inquirer": "^0.12.0",
4040
"metalsmith": "^2.1.0",
4141
"minimatch": "^3.0.0",
42+
"multimatch": "^2.1.0",
4243
"ora": "^0.2.1",
4344
"read-metadata": "^1.0.0",
4445
"request": "^2.67.0",

test/e2e/mock-skip-glob/meta.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"schema": {
3+
"name": {
4+
"type": "string",
5+
"required": true,
6+
"label": "Project name"
7+
},
8+
"description": {
9+
"type": "string",
10+
"required": true,
11+
"label": "Project description",
12+
"default": "A Vue.js project"
13+
},
14+
"author": {
15+
"type": "string",
16+
"label": "Author"
17+
},
18+
"private": {
19+
"type": "boolean",
20+
"default": true
21+
}
22+
},
23+
"skipInterpolation": [
24+
"src/**/*.{vue,js}",
25+
"!src/**/yes.*"
26+
]
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "{{ name }}",
3+
"description": "{{ description }}",
4+
"author": "{{ author }}",
5+
"devDependencies": {
6+
{{#preprocessor.less}}
7+
"less": "^2.6.1",
8+
{{/preprocessor.less}}
9+
{{#preprocessor.sass}}
10+
"node-sass": "^3.4.2"
11+
{{/preprocessor.sass}}
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('{{ no }}')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<p>{{ no }}</p>
3+
</template>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('yes.')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
\{{yes}} {{pick}}
3+
</template>

test/e2e/test.js

+26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const MOCK_META_JSON_PATH = './test/e2e/mock-meta-json'
1515
const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo'
1616
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')
1717
const MOCK_METADATA_REPO_JS_PATH = './test/e2e/mock-metadata-repo-js'
18+
const MOCK_SKIP_GLOB = './test/e2e/mock-skip-glob'
1819

1920
function monkeyPatchInquirer (answers) {
2021
// monkey patch inquirer
@@ -155,6 +156,31 @@ describe('vue-cli', () => {
155156
})
156157
})
157158

159+
it('support multiple globs in skipInterpolation', done => {
160+
monkeyPatchInquirer(answers)
161+
const binFilePath = `${MOCK_SKIP_GLOB}/template/bin.file`
162+
const wstream = fs.createWriteStream(binFilePath)
163+
wstream.write(crypto.randomBytes(100))
164+
wstream.end()
165+
166+
generate('test', MOCK_SKIP_GLOB, MOCK_TEMPLATE_BUILD_PATH, err => {
167+
if (err) done(err)
168+
169+
const originalVueFileOne = fs.readFileSync(`${MOCK_SKIP_GLOB}/template/src/no.vue`, 'utf8')
170+
const originalVueFileTwo = fs.readFileSync(`${MOCK_SKIP_GLOB}/template/src/no.js`, 'utf8')
171+
const generatedVueFileOne = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/src/no.vue`, 'utf8')
172+
const generatedVueFileTwo = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/src/no.js`, 'utf8')
173+
174+
expect(originalVueFileOne).to.equal(generatedVueFileOne)
175+
expect(originalVueFileTwo).to.equal(generatedVueFileTwo)
176+
expect(exists(binFilePath)).to.equal(true)
177+
expect(exists(`${MOCK_TEMPLATE_BUILD_PATH}/bin.file`)).to.equal(true)
178+
rm(binFilePath)
179+
180+
done()
181+
})
182+
})
183+
158184
it('validate input value', done => {
159185
// deep copy
160186
var invalidName = extend({}, answers, { name: 'INVALID-NAME' })

0 commit comments

Comments
 (0)