From 9fb91bc4035f3a69c9a8d140cdf0a46024d56bc4 Mon Sep 17 00:00:00 2001 From: zigomir Date: Wed, 8 Feb 2017 21:02:37 -0800 Subject: [PATCH 01/15] Extract local path logic and add tests. --- bin/vue-init | 7 +++---- lib/local-path.js | 13 +++++++++++++ test/e2e/test.js | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 lib/local-path.js diff --git a/bin/vue-init b/bin/vue-init index 874412fa9c..d9b85c17cc 100755 --- a/bin/vue-init +++ b/bin/vue-init @@ -13,6 +13,7 @@ var logger = require('../lib/logger') var generate = require('../lib/generate') var checkVersion = require('../lib/check-version') var warnings = require('../lib/warnings') +var { isLocalPath, getTemplatePath } = require('../lib/local-path') /** * Usage. @@ -97,10 +98,8 @@ if (exists(to)) { function run () { // check if template is local - if (/^[./]|(\w:)/.test(template)) { - var templatePath = template.charAt(0) === '/' || /^\w:/.test(template) - ? template - : path.normalize(path.join(process.cwd(), template)) + if (isLocalPath(template)) { + var templatePath = getTemplatePath(template) if (exists(templatePath)) { generate(name, templatePath, to, function (err) { if (err) logger.fatal(err) diff --git a/lib/local-path.js b/lib/local-path.js new file mode 100644 index 0000000000..8bba4770f1 --- /dev/null +++ b/lib/local-path.js @@ -0,0 +1,13 @@ +var path = require('path') + +module.exports = { + isLocalPath: function (templatePath) { + return /^[./]|(^[a-z|A-Z]:)/.test(templatePath) + }, + + getTemplatePath: function (templatePath) { + return path.isAbsolute(templatePath) + ? templatePath + : path.normalize(path.join(process.cwd(), templatePath)) + } +} diff --git a/test/e2e/test.js b/test/e2e/test.js index cbdabdf017..452b19aa63 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -10,6 +10,7 @@ const async = require('async') const extend = Object.assign || require('util')._extend const generate = require('../../lib/generate') const metadata = require('../../lib/options') +const { isLocalPath, getTemplatePath } = require('../../lib/local-path') const MOCK_META_JSON_PATH = './test/e2e/mock-meta-json' const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo' @@ -199,4 +200,26 @@ describe('vue-cli', () => { done() }) }) + + it('checks for local path', () => { + expect(isLocalPath('../')).to.equal(true) + expect(isLocalPath('../../')).to.equal(true) + expect(isLocalPath('../template')).to.equal(true) + expect(isLocalPath('../template/abc')).to.equal(true) + expect(isLocalPath('./')).to.equal(true) + expect(isLocalPath('.')).to.equal(true) + expect(isLocalPath('c:/')).to.equal(true) + expect(isLocalPath('D:/')).to.equal(true) + + expect(isLocalPath('username/rep')).to.equal(false) + expect(isLocalPath('bitbucket:username/rep')).to.equal(false) + }) + + it('normalizes template path', () => { + expect(getTemplatePath('/')).to.equal('/') + expect(getTemplatePath('/absolute/path')).to.equal('/absolute/path') + + expect(getTemplatePath('..')).to.equal(path.join(__dirname, '/../../..')) + expect(getTemplatePath('../template')).to.equal(path.join(__dirname, '/../../../template')) + }) }) From f105cc025533dd767e3d7f0af4def569b065b88c Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 08:18:35 -0800 Subject: [PATCH 02/15] Add official template test. --- test/e2e/test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/test.js b/test/e2e/test.js index 452b19aa63..bff8c07554 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -211,6 +211,7 @@ describe('vue-cli', () => { expect(isLocalPath('c:/')).to.equal(true) expect(isLocalPath('D:/')).to.equal(true) + expect(isLocalPath('webpack')).to.equal(false) expect(isLocalPath('username/rep')).to.equal(false) expect(isLocalPath('bitbucket:username/rep')).to.equal(false) }) From 90cb6a784302df3b06f526348eeb6f132cc234a7 Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 08:30:01 -0800 Subject: [PATCH 03/15] Add appveyor to run test on Windows. --- appveyor.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000000..1a7b345741 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,10 @@ +environment: + nodejs_version: "5" + +install: + - npm install + +test_script: + - npm test + +build: off From 1f15a0184fde38f275b538edc56b8fae91a6262f Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 17:00:25 -0800 Subject: [PATCH 04/15] Fix weird race issues. Always pass call callback function on generate. Previously tests were randomly failing when running few times in a row. --- test/e2e/test.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/e2e/test.js b/test/e2e/test.js index bff8c07554..e59a5918cd 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -12,11 +12,11 @@ const generate = require('../../lib/generate') const metadata = require('../../lib/options') const { isLocalPath, getTemplatePath } = require('../../lib/local-path') -const MOCK_META_JSON_PATH = './test/e2e/mock-meta-json' -const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo' +const MOCK_META_JSON_PATH = path.resolve('./test/e2e/mock-meta-json') +const MOCK_TEMPLATE_REPO_PATH = path.resolve('./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' +const MOCK_METADATA_REPO_JS_PATH = path.resolve('./test/e2e/mock-metadata-repo-js') +const MOCK_SKIP_GLOB = path.resolve('./test/e2e/mock-skip-glob') function monkeyPatchInquirer (answers) { // monkey patch inquirer @@ -68,16 +68,16 @@ describe('vue-cli', () => { }) }) - it('adds additional data to meta data', () => { - const data = generate('test', MOCK_META_JSON_PATH, MOCK_TEMPLATE_BUILD_PATH) + it('adds additional data to meta data', done => { + const data = generate('test', MOCK_META_JSON_PATH, MOCK_TEMPLATE_BUILD_PATH, done) expect(data.destDirName).to.equal('test') expect(data.inPlace).to.equal(false) }) - it('sets `inPlace` to true when generating in same directory', () => { + it('sets `inPlace` to true when generating in same directory', done => { const currentDir = process.cwd() process.chdir(MOCK_TEMPLATE_BUILD_PATH) - const data = generate('test', MOCK_META_JSON_PATH, MOCK_TEMPLATE_BUILD_PATH) + const data = generate('test', MOCK_META_JSON_PATH, MOCK_TEMPLATE_BUILD_PATH, done) expect(data.destDirName).to.equal('test') expect(data.inPlace).to.equal(true) process.chdir(currentDir) From a0f0dad09c5df4d333351cac115cdb228f046d78 Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 17:07:11 -0800 Subject: [PATCH 05/15] Windows will scandir for template. --- test/e2e/mock-meta-json/template/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/e2e/mock-meta-json/template/.gitkeep diff --git a/test/e2e/mock-meta-json/template/.gitkeep b/test/e2e/mock-meta-json/template/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 From 6f99a381850ceaa2bb83acc4b534def73e679c82 Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 17:19:40 -0800 Subject: [PATCH 06/15] Try with cleaned cache. npm windows issues --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 1a7b345741..883208b441 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,6 +2,7 @@ environment: nodejs_version: "5" install: + - npm cache clean - npm install test_script: From 2e1d2af789a1809902906cb343f3e61e9db9979d Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 17:26:33 -0800 Subject: [PATCH 07/15] Try cleaning up cache. --- appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 883208b441..9f02e02310 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,10 +2,12 @@ environment: nodejs_version: "5" install: - - npm cache clean - npm install test_script: - npm test +cache: + # - node_modules + build: off From 6bccb2c356e72b0971c9781b6cbaa990846bf889 Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 17:39:25 -0800 Subject: [PATCH 08/15] Add missing dev dependencies. --- package.json | 2 ++ yarn.lock | 8 ++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index fc68ee75d9..d8d89e46b8 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,8 @@ "webpack-merge": "^2.3.1" }, "devDependencies": { + "babel-preset-es2015": "^6.22.0", + "babel-preset-stage-2": "^6.22.0", "chai": "^3.5.0", "cross-env": "^1.0.7", "eslint": "^2.7.0", diff --git a/yarn.lock b/yarn.lock index 54ecdc49a1..61b983e516 100644 --- a/yarn.lock +++ b/yarn.lock @@ -747,7 +747,7 @@ babel-preset-latest@^6.16.0: babel-preset-es2016 "^6.22.0" babel-preset-es2017 "^6.22.0" -babel-preset-stage-2@^6.18.0: +babel-preset-stage-2@^6.18.0, babel-preset-stage-2@^6.22.0: version "6.22.0" resolved "https://registry.npmjs.org/babel-preset-stage-2/-/babel-preset-stage-2-6.22.0.tgz#ccd565f19c245cade394b21216df704a73b27c07" dependencies: @@ -3516,7 +3516,7 @@ minimatch@3.0.2: dependencies: brace-expansion "^1.0.0" -minimist@0.0.8: +minimist@0.0.8, minimist@~0.0.1: version "0.0.8" resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" @@ -3524,10 +3524,6 @@ minimist@^1.1.0, minimist@^1.2.0: version "1.2.0" resolved "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" -minimist@~0.0.1: - version "0.0.10" - resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" - mkdirp@0.3.0: version "0.3.0" resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz#1bbf5ab1ba827af23575143490426455f481fe1e" From 83ecf11b50a67472f6112e3c55d412424413a552 Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 17:46:51 -0800 Subject: [PATCH 09/15] Never-ending cache issue :( --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 9f02e02310..f9de383726 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,9 +5,11 @@ install: - npm install test_script: + - npm cache clean - npm test cache: # - node_modules + # - NO CACHE build: off From 5b5c67ae3364c5afa438fe73eee1a1c9519c82ea Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 18:02:32 -0800 Subject: [PATCH 10/15] Cache only on unique yarn.lock --- appveyor.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index f9de383726..1f367c7b6a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,11 +5,9 @@ install: - npm install test_script: - - npm cache clean - npm test cache: - # - node_modules - # - NO CACHE + - node_modules -> yarn.lock build: off From 97f3ce44e41526cb3b8fe13795aca87fe06978a4 Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 18:39:11 -0800 Subject: [PATCH 11/15] appveyor I have no more ideas :( --- appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 1f367c7b6a..6130b13195 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,8 @@ environment: nodejs_version: "5" install: - - npm install + - npm cache clean + - npm install --force test_script: - npm test From 51bfd2a2efae505eadf0ab73ad253564c74a7c2e Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 18:52:21 -0800 Subject: [PATCH 12/15] Let it fail on node 5. --- appveyor.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6130b13195..99d9891af2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,18 @@ environment: - nodejs_version: "5" + matrix: + - nodejs_version: "5" + - nodejs_version: "6" + +matrix: + allow_failures: + - nodejs_version: "5" # uses some bad npm version install: - - npm cache clean - - npm install --force + - npm install test_script: + - node --version + - npm --version - npm test cache: From 00b5fd4885b2c3c5fb71c44aed24589ddd1e5a1f Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 18:59:16 -0800 Subject: [PATCH 13/15] It actually fails on node 4. --- appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/appveyor.yml b/appveyor.yml index 99d9891af2..03966e3549 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,6 +8,7 @@ matrix: - nodejs_version: "5" # uses some bad npm version install: + - ps: Install-Product node $env:nodejs_version - npm install test_script: From 71964642125e7e4286a51f1d9ad8ad5d24840e0f Mon Sep 17 00:00:00 2001 From: zigomir Date: Thu, 9 Feb 2017 19:12:34 -0800 Subject: [PATCH 14/15] Node v4 will get npm v2 which fails on windows. --- README.md | 4 ++-- appveyor.yml | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1179fcd206..e979272891 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A simple CLI for scaffolding Vue.js projects. ### Installation -Prerequisites: [Node.js](https://nodejs.org/en/) (>=4.x, 6.x preferred) and [Git](https://git-scm.com/). +Prerequisites: [Node.js](https://nodejs.org/en/) (>=4.x, 6.x preferred), npm version 3+ and [Git](https://git-scm.com/). ``` bash $ npm install -g vue-cli @@ -211,7 +211,7 @@ Arguments: } } ``` - + - `helpers`: some helpers you can use to log results. - `chalk`: the `chalk` module - `logger`: [the built-in vue-cli logger](/lib/logger.js) diff --git a/appveyor.yml b/appveyor.yml index 03966e3549..f7b72087a3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,10 +3,6 @@ environment: - nodejs_version: "5" - nodejs_version: "6" -matrix: - allow_failures: - - nodejs_version: "5" # uses some bad npm version - install: - ps: Install-Product node $env:nodejs_version - npm install From adb69365929e4e81357c4ade0e7c5fcca92b0407 Mon Sep 17 00:00:00 2001 From: zigomir Date: Sat, 11 Feb 2017 11:22:19 -0800 Subject: [PATCH 15/15] Better regex. - CR feedback --- lib/local-path.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/local-path.js b/lib/local-path.js index 8bba4770f1..f489bcc71c 100644 --- a/lib/local-path.js +++ b/lib/local-path.js @@ -2,7 +2,7 @@ var path = require('path') module.exports = { isLocalPath: function (templatePath) { - return /^[./]|(^[a-z|A-Z]:)/.test(templatePath) + return /^[./]|(^[a-zA-Z]:)/.test(templatePath) }, getTemplatePath: function (templatePath) {