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 +}