From c117a83f7b10a172906fcf3e3717731f086e901a Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 1 Jan 2017 13:53:43 +0100 Subject: [PATCH 1/3] Add test to support arrays in skipInterpolation --- test/e2e/mock-skip-glob/meta.json | 27 +++++++++++++++++++ test/e2e/mock-skip-glob/template/package.json | 13 +++++++++ test/e2e/mock-skip-glob/template/src/no.js | 1 + test/e2e/mock-skip-glob/template/src/no.vue | 3 +++ test/e2e/mock-skip-glob/template/src/yes.js | 1 + test/e2e/mock-skip-glob/template/src/yes.vue | 3 +++ test/e2e/test.js | 26 ++++++++++++++++++ 7 files changed, 74 insertions(+) create mode 100644 test/e2e/mock-skip-glob/meta.json create mode 100644 test/e2e/mock-skip-glob/template/package.json create mode 100644 test/e2e/mock-skip-glob/template/src/no.js create mode 100644 test/e2e/mock-skip-glob/template/src/no.vue create mode 100644 test/e2e/mock-skip-glob/template/src/yes.js create mode 100644 test/e2e/mock-skip-glob/template/src/yes.vue diff --git a/test/e2e/mock-skip-glob/meta.json b/test/e2e/mock-skip-glob/meta.json new file mode 100644 index 0000000000..dc2ce9a469 --- /dev/null +++ b/test/e2e/mock-skip-glob/meta.json @@ -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.*" + ] +} diff --git a/test/e2e/mock-skip-glob/template/package.json b/test/e2e/mock-skip-glob/template/package.json new file mode 100644 index 0000000000..7a03b5943b --- /dev/null +++ b/test/e2e/mock-skip-glob/template/package.json @@ -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}} + } +} diff --git a/test/e2e/mock-skip-glob/template/src/no.js b/test/e2e/mock-skip-glob/template/src/no.js new file mode 100644 index 0000000000..8296898a2e --- /dev/null +++ b/test/e2e/mock-skip-glob/template/src/no.js @@ -0,0 +1 @@ +console.log('{{ no }}') diff --git a/test/e2e/mock-skip-glob/template/src/no.vue b/test/e2e/mock-skip-glob/template/src/no.vue new file mode 100644 index 0000000000..1b609614c0 --- /dev/null +++ b/test/e2e/mock-skip-glob/template/src/no.vue @@ -0,0 +1,3 @@ + diff --git a/test/e2e/mock-skip-glob/template/src/yes.js b/test/e2e/mock-skip-glob/template/src/yes.js new file mode 100644 index 0000000000..1f434b2a2b --- /dev/null +++ b/test/e2e/mock-skip-glob/template/src/yes.js @@ -0,0 +1 @@ +console.log('yes.') diff --git a/test/e2e/mock-skip-glob/template/src/yes.vue b/test/e2e/mock-skip-glob/template/src/yes.vue new file mode 100644 index 0000000000..0e1e8fd2e0 --- /dev/null +++ b/test/e2e/mock-skip-glob/template/src/yes.vue @@ -0,0 +1,3 @@ + diff --git a/test/e2e/test.js b/test/e2e/test.js index 278d15e445..cbdabdf017 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -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 @@ -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' }) From d1285804eb30289404d0fb1dd3c44e9a4db840a0 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 1 Jan 2017 13:55:03 +0100 Subject: [PATCH 2/3] Support arrays in skipInterpolation Closes #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. --- lib/generate.js | 8 ++++++-- package.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/generate.js b/lib/generate.js index 63f429cb71..cc603c166a 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -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') @@ -91,12 +91,16 @@ 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() + skipInterpolation 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() diff --git a/package.json b/package.json index 1f0b4306f8..97813cfb28 100644 --- a/package.json +++ b/package.json @@ -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", From 0e0a0ea2d93ea08c6d6500415e0ec01fb2bfbf46 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Mon, 2 Jan 2017 19:53:46 +0100 Subject: [PATCH 3/3] Remove useless statement --- lib/generate.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/generate.js b/lib/generate.js index cc603c166a..26447dc8a5 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -97,7 +97,6 @@ function renderTemplateFiles (skipInterpolation) { return function (files, metalsmith, done) { var keys = Object.keys(files) var metalsmithMetadata = metalsmith.metadata() - skipInterpolation async.each(keys, function (file, next) { // skipping files with skipInterpolation option if (skipInterpolation && multimatch([file], skipInterpolation, { dot: true }).length) {