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 new file mode 100644 index 0000000000..f7b72087a3 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,18 @@ +environment: + matrix: + - nodejs_version: "5" + - nodejs_version: "6" + +install: + - ps: Install-Product node $env:nodejs_version + - npm install + +test_script: + - node --version + - npm --version + - npm test + +cache: + - node_modules -> yarn.lock + +build: off 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..f489bcc71c --- /dev/null +++ b/lib/local-path.js @@ -0,0 +1,13 @@ +var path = require('path') + +module.exports = { + isLocalPath: function (templatePath) { + return /^[./]|(^[a-zA-Z]:)/.test(templatePath) + }, + + getTemplatePath: function (templatePath) { + return path.isAbsolute(templatePath) + ? templatePath + : path.normalize(path.join(process.cwd(), templatePath)) + } +} 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/test/e2e/mock-meta-json/template/.gitkeep b/test/e2e/mock-meta-json/template/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/e2e/test.js b/test/e2e/test.js index cbdabdf017..e59a5918cd 100644 --- a/test/e2e/test.js +++ b/test/e2e/test.js @@ -10,12 +10,13 @@ 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' +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 @@ -67,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) @@ -199,4 +200,27 @@ 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('webpack')).to.equal(false) + 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')) + }) }) 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"