Skip to content

Support array in skipInterpolation #282

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

Merged
merged 3 commits into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions lib/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var Handlebars = require('handlebars')
var async = require('async')
var render = require('consolidate').handlebars.render
var path = require('path')
var match = require('minimatch')
var multimatch = require('multimatch')
var getOptions = require('./options')
var ask = require('./ask')
var filter = require('./filter')
Expand Down Expand Up @@ -91,12 +91,15 @@ function filterFiles (filters) {
*/

function renderTemplateFiles (skipInterpolation) {
skipInterpolation = typeof skipInterpolation === 'string'
? [skipInterpolation]
: skipInterpolation
return function (files, metalsmith, done) {
var keys = Object.keys(files)
var metalsmithMetadata = metalsmith.metadata()
async.each(keys, function (file, next) {
// skipping files with skipInterpolation option
if (skipInterpolation && match(file, skipInterpolation, { dot: true })) {
if (skipInterpolation && multimatch([file], skipInterpolation, { dot: true }).length) {
return next()
}
var str = files[file].contents.toString()
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"inquirer": "^0.12.0",
"metalsmith": "^2.1.0",
"minimatch": "^3.0.0",
"multimatch": "^2.1.0",
"ora": "^0.2.1",
"read-metadata": "^1.0.0",
"request": "^2.67.0",
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/mock-skip-glob/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"schema": {
"name": {
"type": "string",
"required": true,
"label": "Project name"
},
"description": {
"type": "string",
"required": true,
"label": "Project description",
"default": "A Vue.js project"
},
"author": {
"type": "string",
"label": "Author"
},
"private": {
"type": "boolean",
"default": true
}
},
"skipInterpolation": [
"src/**/*.{vue,js}",
"!src/**/yes.*"
]
}
13 changes: 13 additions & 0 deletions test/e2e/mock-skip-glob/template/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "{{ name }}",
"description": "{{ description }}",
"author": "{{ author }}",
"devDependencies": {
{{#preprocessor.less}}
"less": "^2.6.1",
{{/preprocessor.less}}
{{#preprocessor.sass}}
"node-sass": "^3.4.2"
{{/preprocessor.sass}}
}
}
1 change: 1 addition & 0 deletions test/e2e/mock-skip-glob/template/src/no.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('{{ no }}')
3 changes: 3 additions & 0 deletions test/e2e/mock-skip-glob/template/src/no.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p>{{ no }}</p>
</template>
1 change: 1 addition & 0 deletions test/e2e/mock-skip-glob/template/src/yes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('yes.')
3 changes: 3 additions & 0 deletions test/e2e/mock-skip-glob/template/src/yes.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
\{{yes}} {{pick}}
</template>
26 changes: 26 additions & 0 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const MOCK_META_JSON_PATH = './test/e2e/mock-meta-json'
const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo'
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')
const MOCK_METADATA_REPO_JS_PATH = './test/e2e/mock-metadata-repo-js'
const MOCK_SKIP_GLOB = './test/e2e/mock-skip-glob'

function monkeyPatchInquirer (answers) {
// monkey patch inquirer
Expand Down Expand Up @@ -155,6 +156,31 @@ describe('vue-cli', () => {
})
})

it('support multiple globs in skipInterpolation', done => {
monkeyPatchInquirer(answers)
const binFilePath = `${MOCK_SKIP_GLOB}/template/bin.file`
const wstream = fs.createWriteStream(binFilePath)
wstream.write(crypto.randomBytes(100))
wstream.end()

generate('test', MOCK_SKIP_GLOB, MOCK_TEMPLATE_BUILD_PATH, err => {
if (err) done(err)

const originalVueFileOne = fs.readFileSync(`${MOCK_SKIP_GLOB}/template/src/no.vue`, 'utf8')
const originalVueFileTwo = fs.readFileSync(`${MOCK_SKIP_GLOB}/template/src/no.js`, 'utf8')
const generatedVueFileOne = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/src/no.vue`, 'utf8')
const generatedVueFileTwo = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/src/no.js`, 'utf8')

expect(originalVueFileOne).to.equal(generatedVueFileOne)
expect(originalVueFileTwo).to.equal(generatedVueFileTwo)
expect(exists(binFilePath)).to.equal(true)
expect(exists(`${MOCK_TEMPLATE_BUILD_PATH}/bin.file`)).to.equal(true)
rm(binFilePath)

done()
})
})

it('validate input value', done => {
// deep copy
var invalidName = extend({}, answers, { name: 'INVALID-NAME' })
Expand Down