From 513a0a0841137ad7a6689f1fd2d816a8c22383ed Mon Sep 17 00:00:00 2001 From: Thorsten Date: Wed, 13 Dec 2017 11:07:56 +0100 Subject: [PATCH 1/8] close #1155 --- template/build/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/build/build.js b/template/build/build.js index 955e9defca..94a72bb051 100644 --- a/template/build/build.js +++ b/template/build/build.js @@ -22,7 +22,7 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { process.stdout.write(stats.toString({ colors: true, modules: false, - children: false, + children: false, // if you are using ts-loader, setting this to false will make tyescript errors show up during build chunks: false, chunkModules: false }) + '\n\n') From 2e094c904b48ae98b9fa389aed49cfd8f623df98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorsten=20L=C3=BCnborg?= Date: Wed, 13 Dec 2017 11:09:10 +0100 Subject: [PATCH 2/8] [WIP] Accurate CompleteMsg when not using autoInstall (fix #1157) (#1158) * try and fix #1157 --- meta.js | 101 +++++++++--------- .../e2e/custom-assertions/elementCount.js | 7 +- utils/index.js | 90 +++++++++++----- 3 files changed, 119 insertions(+), 79 deletions(-) diff --git a/meta.js b/meta.js index 1e0b798e20..4371faac45 100644 --- a/meta.js +++ b/meta.js @@ -1,37 +1,37 @@ -const path = require('path'); -const fs = require('fs'); +const path = require('path') +const fs = require('fs') const { sortDependencies, installDependencies, runLintFix, - printMessage + printMessage, } = require('./utils') module.exports = { helpers: { - if_or: function (v1, v2, options) { + if_or: function(v1, v2, options) { if (v1 || v2) { - return options.fn(this); + return options.fn(this) } - return options.inverse(this); - } + return options.inverse(this) + }, }, prompts: { name: { type: 'string', required: true, - message: 'Project name' + message: 'Project name', }, description: { type: 'string', required: false, message: 'Project description', - default: 'A Vue.js project' + default: 'A Vue.js project', }, author: { type: 'string', - message: 'Author' + message: 'Author', }, build: { type: 'list', @@ -40,22 +40,23 @@ module.exports = { { name: 'Runtime + Compiler: recommended for most users', value: 'standalone', - short: 'standalone' + short: 'standalone', }, { - name: 'Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere', + name: + 'Runtime-only: about 6KB lighter min+gzip, but templates (or any Vue-specific HTML) are ONLY allowed in .vue files - render functions are required elsewhere', value: 'runtime', - short: 'runtime' - } - ] + short: 'runtime', + }, + ], }, router: { type: 'confirm', - message: 'Install vue-router?' + message: 'Install vue-router?', }, lint: { type: 'confirm', - message: 'Use ESLint to lint your code?' + message: 'Use ESLint to lint your code?', }, lintConfig: { when: 'lint', @@ -65,23 +66,23 @@ module.exports = { { name: 'Standard (https://github.com/standard/standard)', value: 'standard', - short: 'Standard' + short: 'Standard', }, { name: 'Airbnb (https://github.com/airbnb/javascript)', value: 'airbnb', - short: 'Airbnb' + short: 'Airbnb', }, { name: 'none (configure it yourself)', value: 'none', - short: 'none' - } - ] + short: 'none', + }, + ], }, unit: { type: 'confirm', - message: 'Set up unit tests' + message: 'Set up unit tests', }, runner: { when: 'unit', @@ -91,45 +92,46 @@ module.exports = { { name: 'Jest', value: 'jest', - short: 'jest' + short: 'jest', }, { name: 'Karma and Mocha', value: 'karma', - short: 'karma' + short: 'karma', }, { name: 'none (configure it yourself)', value: 'noTest', - short: 'noTest' - } - ] + short: 'noTest', + }, + ], }, e2e: { type: 'confirm', - message: 'Setup e2e tests with Nightwatch?' + message: 'Setup e2e tests with Nightwatch?', }, autoInstall: { type: 'list', - message: 'Should we run `npm install` for you after the project has been created? (recommended)', + message: + 'Should we run `npm install` for you after the project has been created? (recommended)', choices: [ { name: 'Yes, use NPM', value: 'npm', - short: 'npm' + short: 'npm', }, { name: 'Yes, use Yarn', value: 'yarn', - short: 'yarn' + short: 'yarn', }, { name: 'No, I will handle that myself', value: false, - short: 'no' - } - ] - } + short: 'no', + }, + ], + }, }, filters: { '.eslintrc.js': 'lint', @@ -143,27 +145,28 @@ module.exports = { 'test/unit/specs/index.js': "unit && runner === 'karma'", 'test/unit/setup.js': "unit && runner === 'jest'", 'test/e2e/**/*': 'e2e', - 'src/router/**/*': 'router' + 'src/router/**/*': 'router', }, - 'complete': function (data, { chalk }) { - + complete: function(data, { chalk }) { const green = chalk.green sortDependencies(data, green) const cwd = path.join(process.cwd(), data.inPlace ? '' : data.destDirName) - + if (data.autoInstall) { installDependencies(cwd, data.autoInstall, green) - .then(() => { - return runLintFix(cwd, data, green) - }) - .then(() => { - printMessage(data, green) - }) + .then(() => { + return runLintFix(cwd, data, green) + }) + .then(() => { + printMessage(data, green) + }) + .catch(e => { + console.log(chalk.red('Error:'), e) + }) } else { printMessage(data, chalk) } - - } -}; + }, +} diff --git a/template/test/e2e/custom-assertions/elementCount.js b/template/test/e2e/custom-assertions/elementCount.js index c0d5fe00af..818e602091 100644 --- a/template/test/e2e/custom-assertions/elementCount.js +++ b/template/test/e2e/custom-assertions/elementCount.js @@ -1,11 +1,12 @@ // A custom Nightwatch assertion. -// the name of the method is the filename. -// can be used in tests like this: +// The assertion name is the filename. +// Example usage: // // browser.assert.elementCount(selector, count) // -// for how to write custom assertions see +// For more information on custom assertions see: // http://nightwatchjs.org/guide#writing-custom-assertions + exports.assertion = function (selector, count) { this.message = 'Testing if element <' + selector + '> has count: ' + count this.expected = count diff --git a/utils/index.js b/utils/index.js index 268cd5c714..a3de77c687 100644 --- a/utils/index.js +++ b/utils/index.js @@ -11,16 +11,13 @@ const lintStyles = ['standard', 'airbnb'] */ exports.sortDependencies = function sortDependencies(data) { const packageJsonFile = path.join( - data.inPlace ? "" : data.destDirName, - "package.json" + data.inPlace ? '' : data.destDirName, + 'package.json' ) const packageJson = JSON.parse(fs.readFileSync(packageJsonFile)) packageJson.devDependencies = sortObject(packageJson.devDependencies) packageJson.dependencies = sortObject(packageJson.dependencies) - fs.writeFileSync( - packageJsonFile, - JSON.stringify(packageJson, null, 2) + "\n" - ); + fs.writeFileSync(packageJsonFile, JSON.stringify(packageJson, null, 2) + '\n') } /** @@ -28,11 +25,15 @@ exports.sortDependencies = function sortDependencies(data) { * @param {string} cwd Path of the created project directory * @param {object} data Data from questionnaire */ -exports.installDependencies = function installDependencies(cwd, executable = 'npm', color) { +exports.installDependencies = function installDependencies( + cwd, + executable = 'npm', + color +) { console.log(`\n\n# ${color('Installing project dependencies ...')}`) console.log('# ========================\n') return runCommand(executable, ['install'], { - cwd + cwd, }) } @@ -43,10 +44,18 @@ exports.installDependencies = function installDependencies(cwd, executable = 'np */ exports.runLintFix = function runLintFix(cwd, data, color) { if (data.lint && lintStyles.indexOf(data.lintConfig) !== -1) { - console.log(`\n\n${color('Running eslint --fix to comply with chosen preset rules...')}`) + console.log( + `\n\n${color( + 'Running eslint --fix to comply with chosen preset rules...' + )}` + ) console.log('# ========================\n') - return runCommand('npm', ['run', 'lint', '--', '--fix'], { - cwd + const args = + data.autoInstall === 'npm' + ? ['run', 'lint', '--', '--fix'] + : ['run', 'lint', '--fix'] + return runCommand(data.autoInstall, args, { + cwd, }) } return Promise.resolve() @@ -63,7 +72,11 @@ exports.printMessage = function printMessage(data, { green, yellow }) { To get started: - ${yellow(`${data.inPlace ? '' : `cd ${data.destDirName}\n `}${requiresLint(data) ? 'npm run lint -- --fix\n ' : ''}npm run dev`)} + ${yellow( + `${data.inPlace ? '' : `cd ${data.destDirName}\n `}${installMsg( + data + )}${lintMsg(data)}npm run dev` + )} Documentation can be found at https://vuejs-templates.github.io/webpack ` @@ -71,27 +84,48 @@ Documentation can be found at https://vuejs-templates.github.io/webpack } /** - * Returns true if the user will have to run lint --fix themselves. + * If the user will have to run lint --fix themselves, it returns a string + * containing the instruction for this step. * @param {Object} data Data from questionnaire. */ -function requiresLint(data) { - return !data.autoInstall && data.lint && lintStyles.indexOf(data.lintConfig) !== -1 +function lintMsg(data) { + return !data.autoInstall && + data.lint && + lintStyles.indexOf(data.lintConfig) !== -1 + ? 'npm run lint -- --fix (or for yarn: yarn run lint --fix)\n ' + : '' +} + +/** + * If the user will have to run `npm install` or `yarn` themselves, it returns a string + * containing the instruction for this step. + * @param {Object} data Data from the questionnaire + */ +function installMsg(data) { + return !data.autoInstall ? 'npm install (or if using yarn: yarn)\n ' : '' } /** * Spawns a child process and runs the specified command * By default, runs in the CWD and inherits stdio * Options are the same as node's child_process.spawn - * @param {string} cmd - * @param {array} args + * @param {string} cmd + * @param {array} args * @param {object} options */ function runCommand(cmd, args, options) { return new Promise((resolve, reject) => { - const spwan = spawn(cmd, args, Object.assign({ - cwd: process.cwd(), - stdio: 'inherit', - }, options)) + const spwan = spawn( + cmd, + args, + Object.assign( + { + cwd: process.cwd(), + stdio: 'inherit', + }, + options + ) + ) spwan.on('exit', () => { resolve() @@ -101,9 +135,11 @@ function runCommand(cmd, args, options) { function sortObject(object) { // Based on https://github.com/yarnpkg/yarn/blob/v1.3.2/src/config.js#L79-L85 - const sortedObject = {}; - Object.keys(object).sort().forEach(item => { - sortedObject[item] = object[item]; - }); - return sortedObject; -} \ No newline at end of file + const sortedObject = {} + Object.keys(object) + .sort() + .forEach(item => { + sortedObject[item] = object[item] + }) + return sortedObject +} From 8e0e190972a66d60437c8fe9657944da0dca3392 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Wed, 13 Dec 2017 12:04:11 +0100 Subject: [PATCH 3/8] restore gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 38e1975447..3f21839306 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ node_modules .DS_Store docs/_book test/ +node_modules +.DS_Store +docs/_book +test/ \ No newline at end of file From 4f564a2715dd9ca39307c5603a3b91f0523f1f67 Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Thu, 14 Dec 2017 17:33:51 +0530 Subject: [PATCH 4/8] Set spawn opt shell as true to avoid ENOENT (#1170) --- utils/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/index.js b/utils/index.js index a3de77c687..fa8d8046f0 100644 --- a/utils/index.js +++ b/utils/index.js @@ -122,6 +122,7 @@ function runCommand(cmd, args, options) { { cwd: process.cwd(), stdio: 'inherit', + shell: true, }, options ) From 98a8064297684fab87605468afa38a3a6c37ee53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Thu, 14 Dec 2017 13:14:30 +0100 Subject: [PATCH 5/8] Remove useless code when lint is not chosen (#1165) --- template/build/webpack.base.conf.js | 4 ++-- template/config/index.js | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/template/build/webpack.base.conf.js b/template/build/webpack.base.conf.js index 1f6057d611..16e6c0ca63 100644 --- a/template/build/webpack.base.conf.js +++ b/template/build/webpack.base.conf.js @@ -8,7 +8,7 @@ function resolve (dir) { return path.join(__dirname, '..', dir) } -const createLintingRule = () => ({ +{{#lint}}const createLintingRule = () => ({ test: /\.(js|vue)$/, loader: 'eslint-loader', enforce: 'pre', @@ -17,7 +17,7 @@ const createLintingRule = () => ({ formatter: require('eslint-friendly-formatter'), emitWarning: !config.dev.showEslintErrorsInOverlay } -}) +}){{/lint}} module.exports = { context: path.resolve(__dirname, '../'), diff --git a/template/config/index.js b/template/config/index.js index 05c69c1620..2fc8572769 100644 --- a/template/config/index.js +++ b/template/config/index.js @@ -20,13 +20,14 @@ module.exports = { notifyOnErrors: true, poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- - // Use Eslint Loader? + {{#lint}}// Use Eslint Loader? // If true, your code will be linted during bundling and // linting errors and warnings will be shown in the console. useEslint: true, // If true, eslint errors and warnings will also be shown in the error overlay // in the browser. showEslintErrorsInOverlay: false, + {{/lint}} /** * Source Maps From 0d15f56dba5d6813ad53816acf9dfd046e863d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Thu, 14 Dec 2017 20:14:39 +0800 Subject: [PATCH 6/8] remove eventsource-polyfill (#1169) --- template/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/template/package.json b/template/package.json index e4e637e1d5..1cadecc957 100644 --- a/template/package.json +++ b/template/package.json @@ -94,7 +94,6 @@ "chalk": "^2.0.1", "copy-webpack-plugin": "^4.0.1", "css-loader": "^0.28.0", - "eventsource-polyfill": "^0.9.6", "extract-text-webpack-plugin": "^3.0.0", "file-loader": "^1.1.4", "friendly-errors-webpack-plugin": "^1.6.1", From 76a76c5f39dccf5a36b44c07f10256e53db35968 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Thu, 14 Dec 2017 18:18:17 +0100 Subject: [PATCH 7/8] bump version to 1.2.7 --- package.json | 2 +- template/config/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a00df3c157..8dc8968321 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-cli-template-webpack", - "version": "1.2.6", + "version": "1.2.7", "license": "MIT", "description": "A full-featured Webpack setup with hot-reload, lint-on-save, unit testing & css extraction.", "scripts": { diff --git a/template/config/index.js b/template/config/index.js index 2fc8572769..f0d536bf82 100644 --- a/template/config/index.js +++ b/template/config/index.js @@ -1,5 +1,5 @@ 'use strict' -// Template version: 1.2.6 +// Template version: 1.2.7 // see http://vuejs-templates.github.io/webpack for documentation. const path = require('path') From 2d99f8ce9fa02b962d47cb5302ef2b42423ab6d6 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Thu, 14 Dec 2017 18:19:30 +0100 Subject: [PATCH 8/8] correct wording for #1155 --- template/build/build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/build/build.js b/template/build/build.js index 94a72bb051..2b648b810c 100644 --- a/template/build/build.js +++ b/template/build/build.js @@ -22,7 +22,7 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { process.stdout.write(stats.toString({ colors: true, modules: false, - children: false, // if you are using ts-loader, setting this to false will make tyescript errors show up during build + children: false, // if you are using ts-loader, setting this to true will make tyescript errors show up during build chunks: false, chunkModules: false }) + '\n\n')