From e1164ce775122705fbea03b5c27c574eb3ed8b63 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Fri, 17 Mar 2017 20:45:59 +0100 Subject: [PATCH 01/10] fix: remove unneeded code --- lib/inquirer-prompt.js | 4 ++-- lib/parser/index.js | 22 +++++++++++++--------- lib/parser/init-transform.js | 6 ++++++ 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 lib/parser/init-transform.js diff --git a/lib/inquirer-prompt.js b/lib/inquirer-prompt.js index 6f4380cf08c..ad4d110d643 100644 --- a/lib/inquirer-prompt.js +++ b/lib/inquirer-prompt.js @@ -18,11 +18,11 @@ module.exports = function prompt(questions, config) { .reduce(function (newOpts, ans) { return attachAnswers(newOpts, ans); }, Object.assign(config, require('./utils/initial-config'))) - .flatMap(newOpts => { + .map(newOpts => { const parser = require('./parser/index'); return parser(null, checkEmptyAnswers(newOpts)); }) - .subscribeOnError( (err) => process.stdout.write(err.toString())); + .subscribeOnError( (err) => console.log(err)); }; /* diff --git a/lib/parser/index.js b/lib/parser/index.js index 0cc5ddcfa28..bd95aa36a5d 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -1,9 +1,9 @@ -const resolveTransform = require('./resolve-transform'); -const validateOptions = require('./validate-options'); +const resolveDependency = require('./resolve-transform'); const validateSchema = require('./utils/validateSchema.js'); const webpackOptionsSchema = require('./utils/webpackOptionsSchema.json'); const WebpackOptionsValidationError = require('./utils/WebpackOptionsValidationError'); - +const initTransform = require('./init-transform'); +const chalk = require('chalk'); /* * @function parser * @@ -14,11 +14,11 @@ const WebpackOptionsValidationError = require('./utils/WebpackOptionsValidationE * * TODO: This is going to be changed, as we need to build up transformation rules, * and then check with validation. We should also make sure @validateOptions -* aren't being run for every object, as some objects in webpackOptions aren't filepaths. +* aren't being run for every object, as some objects in webpackOptions aren't filepaths. * * @param { Array } pkg - A package to be checked * @param { } opts - An object containing webpackOptions or nothing -* @returns { } validateOptions|resolveTransform - +* @returns { } validateOptions|resolveDependency - * Reruns inquirer or validates the given option paths if it matches the schema */ @@ -26,12 +26,16 @@ module.exports = function parser(pkg,opts) { // null, config -> without package // addon, null -> with package if(opts) { - const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, opts); - if(webpackOptionsValidationErrors.length) { + initTransform(opts); + /* + const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, initialWebpackConfig); + if (webpackOptionsValidationErrors.length) { throw new WebpackOptionsValidationError(webpackOptionsValidationErrors); + } else { + process.stdout.write('\n' + chalk.green('Congratulations! Your new webpack config file is created!') + '\n'); } - validateOptions(opts); + */ } else { - resolveTransform(pkg); + resolveDependency(pkg); } }; diff --git a/lib/parser/init-transform.js b/lib/parser/init-transform.js new file mode 100644 index 00000000000..b52d375ca6e --- /dev/null +++ b/lib/parser/init-transform.js @@ -0,0 +1,6 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = function initTransform(opts) { + console.log(opts); +}; From d066facb62c88c5a4cf1c61c64fac5c32f9d65b4 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 21 Mar 2017 09:17:33 +0100 Subject: [PATCH 02/10] feat: initial work on new init structure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes the structure to the init feature a bit. We’re now making the parser validate everything, as we can later run the inquirer prompt after running yeoman, reading from a json file. This will allow us to have a more fluid process and removes a lot of «trash» code. Disabled listing for now, as this is work in progress. --- .eslintignore | 1 + .yo-rc.json | 41 +++++++++++++++++++++++++++++++++ bin/webpack.js | 3 +++ lib/initialize.js | 7 ++---- lib/inquirer-prompt.js | 5 +++- lib/parser/generators/index.js | 29 +++++++++++++++++++++++ lib/parser/index.js | 19 +++++++++++---- lib/parser/init-transform.js | 14 ++++++++++- lib/parser/resolve-transform.js | 9 +++----- lib/utils/initial-config.js | 12 ---------- lib/utils/initial-questions.js | 31 ------------------------- lib/utils/initial-types.spec.js | 30 ------------------------ lib/utils/resolve-packages.js | 4 ++-- package.json | 5 +++- 14 files changed, 117 insertions(+), 93 deletions(-) create mode 100644 .yo-rc.json create mode 100644 lib/parser/generators/index.js delete mode 100644 lib/utils/initial-config.js delete mode 100644 lib/utils/initial-questions.js delete mode 100644 lib/utils/initial-types.spec.js diff --git a/.eslintignore b/.eslintignore index 2eee14cbe2a..bd3761ca476 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ **/__testfixtures__/* coverage +lib diff --git a/.yo-rc.json b/.yo-rc.json new file mode 100644 index 00000000000..53f08353b37 --- /dev/null +++ b/.yo-rc.json @@ -0,0 +1,41 @@ +{ + "webpack": { + "inquirer": [ + { + "type": "input", + "name": "entry", + "message": "What is the name of the entry point in your application?" + }, + { + "type": "input", + "name": "output", + "message": "What is the name of the output directory in your application?" + } + ], + "config": { + "entry": " ", + "output": " " + } + }, + "webpack-cli": { + "inquirer": [ + { + "type": "input", + "name": "entry", + "message": "What is the name of the entry point in your application?" + }, + { + "type": "input", + "name": "output", + "message": "What is the name of the output directory in your application?" + } + ], + "config": { + "entry": " ", + "output": " " + }, + "childDependencies": [ + "webpack-addons-preact" + ] + } +} \ No newline at end of file diff --git a/bin/webpack.js b/bin/webpack.js index eddebcb3998..b2877a802de 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -7,6 +7,9 @@ var path = require('path'); // var fs = require('fs'); // Local version replace global one + +process.title = 'webpack'; + try { var localWebpack = require.resolve(path.join(process.cwd(), 'node_modules', 'webpack-cli', 'bin', 'webpack.js')); if(localWebpack && path.relative(localWebpack, __filename) !== '') { diff --git a/lib/initialize.js b/lib/initialize.js index 60276d2b00f..c64964effd2 100644 --- a/lib/initialize.js +++ b/lib/initialize.js @@ -1,8 +1,5 @@ -const questions = require('./utils/initial-questions'); const npmPackagesExists = require('./utils/npm-packages-exists'); -const prompt = require('./inquirer-prompt'); -const initialConfig = require('./utils/initial-config'); -const Rx = require('rx'); +const parser = require('./parser/index'); /* * @function initializeInquirer @@ -17,7 +14,7 @@ const Rx = require('rx'); module.exports = function initializeInquirer(pkg) { if(pkg.length == 0) { - return prompt(Rx.Observable.from(questions), initialConfig); + return parser(); } else { return npmPackagesExists(pkg); diff --git a/lib/inquirer-prompt.js b/lib/inquirer-prompt.js index ad4d110d643..b1ac1149d3b 100644 --- a/lib/inquirer-prompt.js +++ b/lib/inquirer-prompt.js @@ -17,7 +17,10 @@ module.exports = function prompt(questions, config) { inquirer.prompt(questions).ui.process .reduce(function (newOpts, ans) { return attachAnswers(newOpts, ans); - }, Object.assign(config, require('./utils/initial-config'))) + }, Object.assign(config, { + entry: ' ', + output: ' ' + })) .map(newOpts => { const parser = require('./parser/index'); return parser(null, checkEmptyAnswers(newOpts)); diff --git a/lib/parser/generators/index.js b/lib/parser/generators/index.js new file mode 100644 index 00000000000..051fb8af18e --- /dev/null +++ b/lib/parser/generators/index.js @@ -0,0 +1,29 @@ +const Generator = require('yeoman-generator'); +const {Input} = require('webpack-addons'); + +class WebpackGenerator extends Generator { + constructor(args, opts) { + super(args, opts); + } + Inquirer() { + this.config.set('inquirer', [ + Input('entry','What is the name of the entry point in your application?'), + Input('output','What is the name of the output directory in your application?') + ] + ); + } + Config() { + this.config.set('config', { + entry: ' ', + output: ' ' + }); + } + childDependencies() { + this.config.set('childDependencies', [ + 'webpack-addons-preact' + ]); + } + inject() {} +} + +module.exports = WebpackGenerator; diff --git a/lib/parser/index.js b/lib/parser/index.js index bd95aa36a5d..c9fd9b7d5db 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -25,8 +25,21 @@ const chalk = require('chalk'); module.exports = function parser(pkg,opts) { // null, config -> without package // addon, null -> with package - if(opts) { - initTransform(opts); + + // we're dealing with init, we need to change this later, as it may have been emptied by yeoman + if(!pkg && !opts) { + let webpackOptions = { + entry: ' ', + output: ' ' + }; + initTransform(webpackOptions); + } + else if(pkg) { + // this example app actually needs a refactor in order for it to work + initTransform(); + } + else if(!pkg && opts) { + console.log('You\'re done!'); /* const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, initialWebpackConfig); if (webpackOptionsValidationErrors.length) { @@ -35,7 +48,5 @@ module.exports = function parser(pkg,opts) { process.stdout.write('\n' + chalk.green('Congratulations! Your new webpack config file is created!') + '\n'); } */ - } else { - resolveDependency(pkg); } }; diff --git a/lib/parser/init-transform.js b/lib/parser/init-transform.js index b52d375ca6e..2e7825179d4 100644 --- a/lib/parser/init-transform.js +++ b/lib/parser/init-transform.js @@ -1,6 +1,18 @@ const fs = require('fs'); const path = require('path'); +const yeoman = require('yeoman-environment'); +const Gen = require('./generators/index'); +const generator = require('yeoman-generator'); +const resolveTransform = require('./resolve-transform'); module.exports = function initTransform(opts) { - console.log(opts); + + // async, needs some hickup + const env = yeoman.createEnv(); + env.register(require.resolve('./generators/index'), 'npm:app'); + env.run('npm:app'); + // to run below code. Also, we're testing locally now, might change + + const configFile = require(process.cwd() + '/.yo-rc.json'); + resolveTransform(configFile); }; diff --git a/lib/parser/resolve-transform.js b/lib/parser/resolve-transform.js index c02443ad8f8..312473754e4 100644 --- a/lib/parser/resolve-transform.js +++ b/lib/parser/resolve-transform.js @@ -1,12 +1,9 @@ 'use strict'; -//TODO: Get the inq prompt and return the parser once again until there's no packages left to validate. + const Rx = require('rx'); const prompt = require('../inquirer-prompt'); -const questions = require('../utils/initial-questions'); module.exports = function resolveTransform(pkg) { - const pkgQuestions = questions.concat(pkg.inquirer); - const pkgAddon = Rx.Observable.from(pkgQuestions); - - return prompt(pkgAddon, pkg.config); + const pkgAddon = Rx.Observable.from(pkg.webpack.inquirer); + return prompt(pkgAddon, pkg.webpack.config); }; diff --git a/lib/utils/initial-config.js b/lib/utils/initial-config.js deleted file mode 100644 index bd8e85a9d71..00000000000 --- a/lib/utils/initial-config.js +++ /dev/null @@ -1,12 +0,0 @@ -/* -* @object module.exports -* -* The initial objects later containing the information -* about entry and output paths in webpack -* -*/ - -module.exports = { - entry: {}, - output: {} -}; diff --git a/lib/utils/initial-questions.js b/lib/utils/initial-questions.js deleted file mode 100644 index 69dc1e51b95..00000000000 --- a/lib/utils/initial-questions.js +++ /dev/null @@ -1,31 +0,0 @@ -/* -* @function inquirerInput -* -* Utility function for inquirer to add an question to a inquirer -* instance -* -* @param { String } name - The name of the question -* @param { String } message - The question to be asked -* @returns { } - returns an inquirer question -*/ - -function inquirerInput(name, message) { - return ({ - type: 'input', - name: name, - message: message - }); -} -/* -* @array questions -* -* Adds the initial questions from the utility function above as an array. -* -*/ - -const questions = [ - inquirerInput('entry','What is the name of the entry point in your application?'), - inquirerInput('output','What is the name of the output directory in your application?') -]; - -module.exports = questions; diff --git a/lib/utils/initial-types.spec.js b/lib/utils/initial-types.spec.js deleted file mode 100644 index 4cad6e14cf3..00000000000 --- a/lib/utils/initial-types.spec.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -describe('initial-types', () => { - - const questions = require('./initial-questions'); - const config = require('./initial-config'); - - it('should return the initial questions', () => { - expect(questions).toMatchObject([ - { - 'message': 'What is the name of the entry point in your application?', - 'name': 'entry', - 'type': 'input' - }, - { - 'message': - 'What is the name of the output directory in your application?', - 'name': 'output', - 'type': 'input' - } - ]); - }); - it('should return the initial configuration objects', () => { - expect(config).toMatchObject({ - entry: {}, - output: {} - }); - }); - -}); diff --git a/lib/utils/resolve-packages.js b/lib/utils/resolve-packages.js index b8168b16663..3c94ecf4aea 100644 --- a/lib/utils/resolve-packages.js +++ b/lib/utils/resolve-packages.js @@ -29,8 +29,8 @@ function processPromise(child) { */ function spawnChild(pkg) { - //return spawn('npm', ['install', '--save', pkg], { stdio: 'inherit', customFds: [0, 1, 2] }); - return spawn('npm', ['install', '--save', pkg]); + return spawn('npm', ['install', '--save', pkg], { stdio: 'inherit', customFds: [0, 1, 2] }); + //return spawn('npm', ['install', '--save', pkg]); } /* diff --git a/package.json b/package.json index 870a5c6e5b0..d8e0ae37bf1 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,11 @@ "rx": "^4.1.0", "supports-color": "^3.1.2", "webpack": "^2.2.0-rc.0", + "webpack-addons": "0.0.20", "webpack-addons-ylvis": "0.0.27", - "yargs": "^6.5.0" + "yargs": "^6.5.0", + "yeoman-environment": "^1.6.6", + "yeoman-generator": "^1.1.1" }, "devDependencies": { "ajv": "^4.11.3", From cc18385fc36b1d94f400b358c4a2638b53799793 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Tue, 21 Mar 2017 22:09:10 +0100 Subject: [PATCH 03/10] feat: Generate yeoman instance from a package Makes it possible to make a inquirer prompt with a remote package. --- .yo-rc.json | 22 +++++---------------- lib/inquirer-prompt.js | 5 +---- lib/parser/generators/index.js | 1 + lib/parser/index.js | 9 ++------- lib/parser/init-transform.js | 34 +++++++++++++++++++++------------ lib/parser/resolve-transform.js | 6 +++--- lib/parser/transform.js | 3 --- lib/utils/resolve-packages.js | 4 +--- package.json | 2 +- 9 files changed, 36 insertions(+), 50 deletions(-) delete mode 100644 lib/parser/transform.js diff --git a/.yo-rc.json b/.yo-rc.json index 53f08353b37..96c2176c546 100644 --- a/.yo-rc.json +++ b/.yo-rc.json @@ -1,5 +1,5 @@ { - "webpack": { + "webpack-addons-ylvis": { "inquirer": [ { "type": "input", @@ -10,29 +10,17 @@ "type": "input", "name": "output", "message": "What is the name of the output directory in your application?" - } - ], - "config": { - "entry": " ", - "output": " " - } - }, - "webpack-cli": { - "inquirer": [ - { - "type": "input", - "name": "entry", - "message": "What is the name of the entry point in your application?" }, { "type": "input", - "name": "output", - "message": "What is the name of the output directory in your application?" + "name": "resolve", + "message": "This is resolve peeps" } ], "config": { "entry": " ", - "output": " " + "output": " ", + "resolve": " " }, "childDependencies": [ "webpack-addons-preact" diff --git a/lib/inquirer-prompt.js b/lib/inquirer-prompt.js index b1ac1149d3b..fbe7a79a25d 100644 --- a/lib/inquirer-prompt.js +++ b/lib/inquirer-prompt.js @@ -17,10 +17,7 @@ module.exports = function prompt(questions, config) { inquirer.prompt(questions).ui.process .reduce(function (newOpts, ans) { return attachAnswers(newOpts, ans); - }, Object.assign(config, { - entry: ' ', - output: ' ' - })) + }, Object.assign(config)) .map(newOpts => { const parser = require('./parser/index'); return parser(null, checkEmptyAnswers(newOpts)); diff --git a/lib/parser/generators/index.js b/lib/parser/generators/index.js index 051fb8af18e..f1df0573b48 100644 --- a/lib/parser/generators/index.js +++ b/lib/parser/generators/index.js @@ -1,6 +1,7 @@ const Generator = require('yeoman-generator'); const {Input} = require('webpack-addons'); + class WebpackGenerator extends Generator { constructor(args, opts) { super(args, opts); diff --git a/lib/parser/index.js b/lib/parser/index.js index c9fd9b7d5db..de0ffeac146 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -25,18 +25,13 @@ const chalk = require('chalk'); module.exports = function parser(pkg,opts) { // null, config -> without package // addon, null -> with package - // we're dealing with init, we need to change this later, as it may have been emptied by yeoman if(!pkg && !opts) { - let webpackOptions = { - entry: ' ', - output: ' ' - }; - initTransform(webpackOptions); + initTransform(); } else if(pkg) { // this example app actually needs a refactor in order for it to work - initTransform(); + initTransform(pkg); } else if(!pkg && opts) { console.log('You\'re done!'); diff --git a/lib/parser/init-transform.js b/lib/parser/init-transform.js index 2e7825179d4..9fa7d43d4e4 100644 --- a/lib/parser/init-transform.js +++ b/lib/parser/init-transform.js @@ -1,18 +1,28 @@ const fs = require('fs'); const path = require('path'); const yeoman = require('yeoman-environment'); -const Gen = require('./generators/index'); -const generator = require('yeoman-generator'); +const Generator = require('yeoman-generator'); const resolveTransform = require('./resolve-transform'); +const initGenerator = require('./generators/index'); -module.exports = function initTransform(opts) { - - // async, needs some hickup - const env = yeoman.createEnv(); - env.register(require.resolve('./generators/index'), 'npm:app'); - env.run('npm:app'); - // to run below code. Also, we're testing locally now, might change - - const configFile = require(process.cwd() + '/.yo-rc.json'); - resolveTransform(configFile); +module.exports = function initTransform(options) { + if(options) { + const env = yeoman.createEnv(); + env.register(require.resolve(options), 'npm:app'); + env.run('npm:app'); + try { + const configFile = require(process.cwd() + '/.yo-rc.json'); + let name = path.basename(options) + resolveTransform(configFile, name); + } catch (e) {} + } + else if(!options) { + const env = yeoman.createEnv(); + env.registerStub(initGenerator, 'npm:app'); + env.run('npm:app'); + try { + const configFile = require(process.cwd() + '/.yo-rc.json'); + resolveTransform(configFile); + } catch (e) {} + } }; diff --git a/lib/parser/resolve-transform.js b/lib/parser/resolve-transform.js index 312473754e4..d1c3566fe0c 100644 --- a/lib/parser/resolve-transform.js +++ b/lib/parser/resolve-transform.js @@ -3,7 +3,7 @@ const Rx = require('rx'); const prompt = require('../inquirer-prompt'); -module.exports = function resolveTransform(pkg) { - const pkgAddon = Rx.Observable.from(pkg.webpack.inquirer); - return prompt(pkgAddon, pkg.webpack.config); +module.exports = function resolveTransform(pkg, pkgName) { + const pkgAddon = Rx.Observable.from(pkg[pkgName].inquirer); + return prompt(pkgAddon, pkg[pkgName].config); }; diff --git a/lib/parser/transform.js b/lib/parser/transform.js deleted file mode 100644 index 2483ae3e4f8..00000000000 --- a/lib/parser/transform.js +++ /dev/null @@ -1,3 +0,0 @@ -// Hook up transformations with our options -module.exports = function transform(n) { //eslint-disable-line -}; diff --git a/lib/utils/resolve-packages.js b/lib/utils/resolve-packages.js index 3c94ecf4aea..03ce73f4eb4 100644 --- a/lib/utils/resolve-packages.js +++ b/lib/utils/resolve-packages.js @@ -47,11 +47,9 @@ function spawnChild(pkg) { module.exports = function resolvePackages(pkg) { Error.stackTraceLimit = 30; return processPromise(spawnChild(pkg)).then( () => { - let packageModule; try { let loc = path.join('..', '..', 'node_modules', pkg); - packageModule = require(loc); - parser(packageModule, null); + parser(loc, null); } catch(err) { console.log('Package wasn\'t validated correctly..'); console.log('Submit an issue for', pkg, 'if this persists'); diff --git a/package.json b/package.json index d8e0ae37bf1..3ebec04cce4 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "supports-color": "^3.1.2", "webpack": "^2.2.0-rc.0", "webpack-addons": "0.0.20", - "webpack-addons-ylvis": "0.0.27", + "webpack-addons-ylvis": "0.0.32", "yargs": "^6.5.0", "yeoman-environment": "^1.6.6", "yeoman-generator": "^1.1.1" From fd018e0f76cb3e5434a647016c0d545ed9303c80 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 22 Mar 2017 13:15:23 +0100 Subject: [PATCH 04/10] feat: try using webpack-chain for obj-creation --- lib/parser/index.js | 6 ++++++ lib/parser/myConfig.js | 13 +++++++++++++ webpack.config.js | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 lib/parser/myConfig.js create mode 100644 webpack.config.js diff --git a/lib/parser/index.js b/lib/parser/index.js index de0ffeac146..15b77894b0b 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -34,7 +34,13 @@ module.exports = function parser(pkg,opts) { initTransform(pkg); } else if(!pkg && opts) { + const fs = require('fs'); + try { + const logicPath = process.cwd() + '/webpack.config.js'; + const myconfig = require('./myconfig')(opts) + fs.writeFileSync(logicPath, myconfig, 'utf-8'); console.log('You\'re done!'); + } catch(e) {} /* const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, initialWebpackConfig); if (webpackOptionsValidationErrors.length) { diff --git a/lib/parser/myConfig.js b/lib/parser/myConfig.js new file mode 100644 index 00000000000..a9b2c506093 --- /dev/null +++ b/lib/parser/myConfig.js @@ -0,0 +1,13 @@ +const Config = require('webpack-chain'); +const config = new Config(); + +module.exports = (opts) => { +config + .entry('app') + .add(opts.entry) + .end() + .output + .filename(opts.output) + return `module.exports = + ${JSON.stringify(config.toConfig())}` +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 00000000000..07102c0089c --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,8 @@ +module.exports = { + 'output':{ + 'filename':'b' + }, + 'entry':{ + 'app':['a'] + } +}; From af84d429ccb1371c0aabfb7a8db58bda016bab2a Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 29 Mar 2017 16:30:39 +0200 Subject: [PATCH 05/10] feat: get build ready for refactor --- __mocks__/inquirer/initialize.mock.js | 32 --------------------------- __mocks__/inquirer/prompt.mock.js | 32 --------------------------- lib/inquirer-prompt.spec.js | 20 ----------------- lib/parser/generators/index.js | 16 ++++++++------ lib/parser/index.js | 30 ++++++++----------------- lib/parser/init-transform.js | 16 +++++++++----- lib/parser/myConfig.js | 13 ----------- lib/parser/resolve-transform.js | 9 -------- lib/utils/npm-packages-exists.spec.js | 13 ----------- webpack.config.js | 8 ------- 10 files changed, 29 insertions(+), 160 deletions(-) delete mode 100644 __mocks__/inquirer/initialize.mock.js delete mode 100644 __mocks__/inquirer/prompt.mock.js delete mode 100644 lib/inquirer-prompt.spec.js delete mode 100644 lib/parser/myConfig.js delete mode 100644 lib/parser/resolve-transform.js delete mode 100644 lib/utils/npm-packages-exists.spec.js delete mode 100644 webpack.config.js diff --git a/__mocks__/inquirer/initialize.mock.js b/__mocks__/inquirer/initialize.mock.js deleted file mode 100644 index e90feccfab6..00000000000 --- a/__mocks__/inquirer/initialize.mock.js +++ /dev/null @@ -1,32 +0,0 @@ -/* eslint node/no-unsupported-features: 0 */ -'use strict'; -const Rx = require('rx'); -const questions = require('../../lib/utils/initial-questions'); -const exists = require('../../lib/utils/npm-exists'); -const initialConfig = require('../../lib/utils/initial-config'); - -//eslint-disable-next-line -const prompt = require('./prompt.mock'); - -async function npmPackagesExists(addon) { - let arr = []; - for(let k of addon) { - arr.push(await exists(k)); - } - return arr; -} - -function init(pkg, answer) { - // In the regular module, this is automatically an empty array, becomes `pkg.length == 0` - // We're adding manually the answers here as an argument for testing - if(!pkg) { - return prompt(Rx.Observable.from(questions), initialConfig, answer); - } - else { /* noop for now, manually testing addons */ } -} - - -module.exports = { - npmPackagesExists, - init -}; diff --git a/__mocks__/inquirer/prompt.mock.js b/__mocks__/inquirer/prompt.mock.js deleted file mode 100644 index cfe33f62789..00000000000 --- a/__mocks__/inquirer/prompt.mock.js +++ /dev/null @@ -1,32 +0,0 @@ -'use strict'; - -function prompt(questions, config, testAnswer) { - return questions.reduce( function(newOpts) { - return attachAnswers(newOpts, testAnswer); - }, Object.assign(config, require('../../lib/utils/initial-config'))) - .map(newOpts => checkEmptyAnswers(newOpts)); -} - -function attachAnswers(config, answer) { - let newConfig; - Object.keys(config).forEach( (configName) => { - if(answer[configName]) { - newConfig = Object.assign(config, { - [configName]: answer[configName] - }); - } - }); - return newConfig; -} - -function checkEmptyAnswers(config) { - for(let key in config) { - if(!config[key]) { - throw new Error('\nFound no answer given to property ' + - key + '\n'); - } - } - return config; -} - -module.exports = prompt; diff --git a/lib/inquirer-prompt.spec.js b/lib/inquirer-prompt.spec.js deleted file mode 100644 index ed61002e696..00000000000 --- a/lib/inquirer-prompt.spec.js +++ /dev/null @@ -1,20 +0,0 @@ -/* eslint node/no-unsupported-features: 0 */ -'use strict'; - -describe('inquirer-prompt', () => { - //eslint-disable-next-line - const {init} = require('../__mocks__/inquirer/initialize.mock'); - - it('should provide with basic options if no argument is supplied to init', async () => { - let itInits = await init(null, { - entry: '1', output: '2' - }); - let matchObj = { - entry: '1', - output: '2' - }; - itInits.subscribe(function(answers) { - expect(answers).toMatchObject(matchObj); - }); - }); -}); diff --git a/lib/parser/generators/index.js b/lib/parser/generators/index.js index f1df0573b48..09e24b8410a 100644 --- a/lib/parser/generators/index.js +++ b/lib/parser/generators/index.js @@ -5,24 +5,26 @@ const {Input} = require('webpack-addons'); class WebpackGenerator extends Generator { constructor(args, opts) { super(args, opts); + this.myConfig = { + inquirer: [], + config: {}, + childDependencies: [] + } } Inquirer() { - this.config.set('inquirer', [ + this.myConfig.inquirer = [ Input('entry','What is the name of the entry point in your application?'), Input('output','What is the name of the output directory in your application?') ] - ); } Config() { - this.config.set('config', { + this.myConfig.config = { entry: ' ', output: ' ' - }); + }; } childDependencies() { - this.config.set('childDependencies', [ - 'webpack-addons-preact' - ]); + this.myConfig.childDependencies = ['webpack-addons-preact']; } inject() {} } diff --git a/lib/parser/index.js b/lib/parser/index.js index 15b77894b0b..e6a281e74c0 100644 --- a/lib/parser/index.js +++ b/lib/parser/index.js @@ -1,4 +1,3 @@ -const resolveDependency = require('./resolve-transform'); const validateSchema = require('./utils/validateSchema.js'); const webpackOptionsSchema = require('./utils/webpackOptionsSchema.json'); const WebpackOptionsValidationError = require('./utils/WebpackOptionsValidationError'); @@ -10,37 +9,26 @@ const chalk = require('chalk'); * Main function to build up a webpack configuration. * Either throws an error if it doesn't match the webpack schema, * or validates the filepaths of the options given. -* If a package is supplied, it finds the package and runs inquirer +* If a package is supplied, it finds the path of the package and runs inquirer * -* TODO: This is going to be changed, as we need to build up transformation rules, -* and then check with validation. We should also make sure @validateOptions -* aren't being run for every object, as some objects in webpackOptions aren't filepaths. -* -* @param { Array } pkg - A package to be checked +* @param { Array } pkgPaths - An Array of packages to run * @param { } opts - An object containing webpackOptions or nothing -* @returns { } validateOptions|resolveDependency - -* Reruns inquirer or validates the given option paths if it matches the schema +* @returns { } initTransform - Initializes the scaffold in yeoman */ -module.exports = function parser(pkg,opts) { +module.exports = function parser(pkgPaths,opts) { // null, config -> without package // addon, null -> with package // we're dealing with init, we need to change this later, as it may have been emptied by yeoman - if(!pkg && !opts) { + if(!pkgPaths && !opts) { initTransform(); } - else if(pkg) { + else if(pkgPaths) { // this example app actually needs a refactor in order for it to work - initTransform(pkg); + initTransform(pkgPaths); } - else if(!pkg && opts) { - const fs = require('fs'); - try { - const logicPath = process.cwd() + '/webpack.config.js'; - const myconfig = require('./myconfig')(opts) - fs.writeFileSync(logicPath, myconfig, 'utf-8'); - console.log('You\'re done!'); - } catch(e) {} + else if(!pkgPaths && opts) { + // scaffold is done /* const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, initialWebpackConfig); if (webpackOptionsValidationErrors.length) { diff --git a/lib/parser/init-transform.js b/lib/parser/init-transform.js index 9fa7d43d4e4..656fa0dd133 100644 --- a/lib/parser/init-transform.js +++ b/lib/parser/init-transform.js @@ -2,18 +2,25 @@ const fs = require('fs'); const path = require('path'); const yeoman = require('yeoman-environment'); const Generator = require('yeoman-generator'); -const resolveTransform = require('./resolve-transform'); const initGenerator = require('./generators/index'); +/* +* @function initTransform +* +* Runs yeoman and in the future lets us grab the answers from the generators +* +* @param { Array } options - An Array of paths to match generators for +* @returns { } +*/ + module.exports = function initTransform(options) { if(options) { const env = yeoman.createEnv(); env.register(require.resolve(options), 'npm:app'); env.run('npm:app'); try { - const configFile = require(process.cwd() + '/.yo-rc.json'); let name = path.basename(options) - resolveTransform(configFile, name); + console.log("Done!") } catch (e) {} } else if(!options) { @@ -21,8 +28,7 @@ module.exports = function initTransform(options) { env.registerStub(initGenerator, 'npm:app'); env.run('npm:app'); try { - const configFile = require(process.cwd() + '/.yo-rc.json'); - resolveTransform(configFile); + console.log("Done!") } catch (e) {} } }; diff --git a/lib/parser/myConfig.js b/lib/parser/myConfig.js deleted file mode 100644 index a9b2c506093..00000000000 --- a/lib/parser/myConfig.js +++ /dev/null @@ -1,13 +0,0 @@ -const Config = require('webpack-chain'); -const config = new Config(); - -module.exports = (opts) => { -config - .entry('app') - .add(opts.entry) - .end() - .output - .filename(opts.output) - return `module.exports = - ${JSON.stringify(config.toConfig())}` -} diff --git a/lib/parser/resolve-transform.js b/lib/parser/resolve-transform.js deleted file mode 100644 index d1c3566fe0c..00000000000 --- a/lib/parser/resolve-transform.js +++ /dev/null @@ -1,9 +0,0 @@ -'use strict'; - -const Rx = require('rx'); -const prompt = require('../inquirer-prompt'); - -module.exports = function resolveTransform(pkg, pkgName) { - const pkgAddon = Rx.Observable.from(pkg[pkgName].inquirer); - return prompt(pkgAddon, pkg[pkgName].config); -}; diff --git a/lib/utils/npm-packages-exists.spec.js b/lib/utils/npm-packages-exists.spec.js deleted file mode 100644 index dd839b0fb61..00000000000 --- a/lib/utils/npm-packages-exists.spec.js +++ /dev/null @@ -1,13 +0,0 @@ -/* eslint node/no-unsupported-features: 0 */ -'use strict'; - -describe('npm-packages-exists', () => { - //eslint-disable-next-line - const {npmPackagesExists} = require('../../__mocks__/inquirer/initialize.mock'); - - it('should validate multiple packages if supplied', async () => { - let itValidatesAddon = await npmPackagesExists(['webpack-addons-ylvis', 'webpack-addons-noop']); - // BUG: We are making the values strings, so the tests pass - expect(itValidatesAddon.toString()).toBe([true, false].toString()); - }); -}); diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 07102c0089c..00000000000 --- a/webpack.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - 'output':{ - 'filename':'b' - }, - 'entry':{ - 'app':['a'] - } -}; From 9182aefbe0f97269f99e9d942e2ebcfbcd5b3f86 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 29 Mar 2017 16:37:43 +0200 Subject: [PATCH 06/10] fix: rename parser to creator --- __mocks__/{parser => creator}/validate-options.mock.js | 0 lib/{parser => creator}/generators/index.js | 0 lib/{parser => creator}/index.js | 4 ++-- lib/{parser => creator}/init-transform.js | 0 .../utils/WebpackOptionsValidationError.js | 0 lib/{parser => creator}/utils/validateSchema.js | 0 lib/{parser => creator}/utils/webpackOptionsSchema.json | 0 lib/{parser => creator}/validate-options.js | 0 lib/{parser => creator}/validate-options.spec.js | 2 +- lib/initialize.js | 4 ++-- lib/utils/resolve-packages.js | 8 ++++---- 11 files changed, 9 insertions(+), 9 deletions(-) rename __mocks__/{parser => creator}/validate-options.mock.js (100%) rename lib/{parser => creator}/generators/index.js (100%) rename lib/{parser => creator}/index.js (95%) rename lib/{parser => creator}/init-transform.js (100%) rename lib/{parser => creator}/utils/WebpackOptionsValidationError.js (100%) rename lib/{parser => creator}/utils/validateSchema.js (100%) rename lib/{parser => creator}/utils/webpackOptionsSchema.json (100%) rename lib/{parser => creator}/validate-options.js (100%) rename lib/{parser => creator}/validate-options.spec.js (82%) diff --git a/__mocks__/parser/validate-options.mock.js b/__mocks__/creator/validate-options.mock.js similarity index 100% rename from __mocks__/parser/validate-options.mock.js rename to __mocks__/creator/validate-options.mock.js diff --git a/lib/parser/generators/index.js b/lib/creator/generators/index.js similarity index 100% rename from lib/parser/generators/index.js rename to lib/creator/generators/index.js diff --git a/lib/parser/index.js b/lib/creator/index.js similarity index 95% rename from lib/parser/index.js rename to lib/creator/index.js index e6a281e74c0..1a2e61c2aaf 100644 --- a/lib/parser/index.js +++ b/lib/creator/index.js @@ -4,7 +4,7 @@ const WebpackOptionsValidationError = require('./utils/WebpackOptionsValidationE const initTransform = require('./init-transform'); const chalk = require('chalk'); /* -* @function parser +* @function creator * * Main function to build up a webpack configuration. * Either throws an error if it doesn't match the webpack schema, @@ -16,7 +16,7 @@ const chalk = require('chalk'); * @returns { } initTransform - Initializes the scaffold in yeoman */ -module.exports = function parser(pkgPaths,opts) { +module.exports = function creator(pkgPaths,opts) { // null, config -> without package // addon, null -> with package // we're dealing with init, we need to change this later, as it may have been emptied by yeoman diff --git a/lib/parser/init-transform.js b/lib/creator/init-transform.js similarity index 100% rename from lib/parser/init-transform.js rename to lib/creator/init-transform.js diff --git a/lib/parser/utils/WebpackOptionsValidationError.js b/lib/creator/utils/WebpackOptionsValidationError.js similarity index 100% rename from lib/parser/utils/WebpackOptionsValidationError.js rename to lib/creator/utils/WebpackOptionsValidationError.js diff --git a/lib/parser/utils/validateSchema.js b/lib/creator/utils/validateSchema.js similarity index 100% rename from lib/parser/utils/validateSchema.js rename to lib/creator/utils/validateSchema.js diff --git a/lib/parser/utils/webpackOptionsSchema.json b/lib/creator/utils/webpackOptionsSchema.json similarity index 100% rename from lib/parser/utils/webpackOptionsSchema.json rename to lib/creator/utils/webpackOptionsSchema.json diff --git a/lib/parser/validate-options.js b/lib/creator/validate-options.js similarity index 100% rename from lib/parser/validate-options.js rename to lib/creator/validate-options.js diff --git a/lib/parser/validate-options.spec.js b/lib/creator/validate-options.spec.js similarity index 82% rename from lib/parser/validate-options.spec.js rename to lib/creator/validate-options.spec.js index 06ea826334b..e817c5b1ef1 100644 --- a/lib/parser/validate-options.spec.js +++ b/lib/creator/validate-options.spec.js @@ -2,7 +2,7 @@ describe('validate-options', () => { //eslint-disable-next-line - const {validateOptions} = require('../../__mocks__/parser/validate-options.mock'); + const {validateOptions} = require('../../__mocks__/creator/validate-options.mock'); it('should throw on fake paths', () => { expect(() => { diff --git a/lib/initialize.js b/lib/initialize.js index c64964effd2..2985a8f8188 100644 --- a/lib/initialize.js +++ b/lib/initialize.js @@ -1,5 +1,5 @@ const npmPackagesExists = require('./utils/npm-packages-exists'); -const parser = require('./parser/index'); +const creator = require('./creator/index'); /* * @function initializeInquirer @@ -14,7 +14,7 @@ const parser = require('./parser/index'); module.exports = function initializeInquirer(pkg) { if(pkg.length == 0) { - return parser(); + return creator(); } else { return npmPackagesExists(pkg); diff --git a/lib/utils/resolve-packages.js b/lib/utils/resolve-packages.js index 03ce73f4eb4..8f8f5587272 100644 --- a/lib/utils/resolve-packages.js +++ b/lib/utils/resolve-packages.js @@ -1,5 +1,5 @@ const spawn = require('cross-spawn'); -const parser = require('../parser/index'); +const creator = require('../creator/index'); const path = require('path'); const chalk = require('chalk'); @@ -36,11 +36,11 @@ function spawnChild(pkg) { /* * @function resolvePackages * -* Resolves the package after it is validated, later sending it to the parser +* Resolves the package after it is validated, later sending it to the creator * to be validated * * @param { String } pkg - The dependency to be installed -* @returns { } parser - Validates the dependency and builds +* @returns { } creator - Validates the dependency and builds * the webpack configuration */ @@ -49,7 +49,7 @@ module.exports = function resolvePackages(pkg) { return processPromise(spawnChild(pkg)).then( () => { try { let loc = path.join('..', '..', 'node_modules', pkg); - parser(loc, null); + creator(loc, null); } catch(err) { console.log('Package wasn\'t validated correctly..'); console.log('Submit an issue for', pkg, 'if this persists'); From 01d83e29c26719065d88a51c5bb4e50e96fa0c32 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 29 Mar 2017 16:40:49 +0200 Subject: [PATCH 07/10] fix: enable listing for lib library and fix issues --- .eslintignore | 1 - lib/creator/generators/index.js | 5 +++-- lib/creator/init-transform.js | 8 +++++--- lib/inquirer-prompt.js | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.eslintignore b/.eslintignore index bd3761ca476..2eee14cbe2a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,2 @@ **/__testfixtures__/* coverage -lib diff --git a/lib/creator/generators/index.js b/lib/creator/generators/index.js index 09e24b8410a..6510404632c 100644 --- a/lib/creator/generators/index.js +++ b/lib/creator/generators/index.js @@ -1,4 +1,5 @@ const Generator = require('yeoman-generator'); +// eslint-disable-next-line const {Input} = require('webpack-addons'); @@ -9,13 +10,13 @@ class WebpackGenerator extends Generator { inquirer: [], config: {}, childDependencies: [] - } + }; } Inquirer() { this.myConfig.inquirer = [ Input('entry','What is the name of the entry point in your application?'), Input('output','What is the name of the output directory in your application?') - ] + ]; } Config() { this.myConfig.config = { diff --git a/lib/creator/init-transform.js b/lib/creator/init-transform.js index 656fa0dd133..62fd90308f2 100644 --- a/lib/creator/init-transform.js +++ b/lib/creator/init-transform.js @@ -19,8 +19,9 @@ module.exports = function initTransform(options) { env.register(require.resolve(options), 'npm:app'); env.run('npm:app'); try { - let name = path.basename(options) - console.log("Done!") + let name = path.basename(options); + console.log('Done!'); + //eslint-disable-next-line } catch (e) {} } else if(!options) { @@ -28,7 +29,8 @@ module.exports = function initTransform(options) { env.registerStub(initGenerator, 'npm:app'); env.run('npm:app'); try { - console.log("Done!") + console.log('Done!'); + // eslint-disable-next-line } catch (e) {} } }; diff --git a/lib/inquirer-prompt.js b/lib/inquirer-prompt.js index fbe7a79a25d..d1dcf442a07 100644 --- a/lib/inquirer-prompt.js +++ b/lib/inquirer-prompt.js @@ -9,7 +9,7 @@ const chalk = require('chalk'); * @param { Object } questions - questions to be prompted in RxJS format * @param { Object } config - Configuration passed from an addon to be included in * answers, later sent down to the parser -* @returns { Function } Parser function that validates the answers, later transforming +* @returns { Function } Creator function that validates the answers, later transforming * the answers to an webpack configuration */ @@ -19,8 +19,8 @@ module.exports = function prompt(questions, config) { return attachAnswers(newOpts, ans); }, Object.assign(config)) .map(newOpts => { - const parser = require('./parser/index'); - return parser(null, checkEmptyAnswers(newOpts)); + const creator = require('./creator/index'); + return creator(null, checkEmptyAnswers(newOpts)); }) .subscribeOnError( (err) => console.log(err)); }; From 1207ad82f76ef964605ea654cfa70fc3bcbcb5d7 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Wed, 29 Mar 2017 16:49:07 +0200 Subject: [PATCH 08/10] fix: don't disable lint for destructuring --- lib/creator/generators/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/creator/generators/index.js b/lib/creator/generators/index.js index 6510404632c..d650f6d43f9 100644 --- a/lib/creator/generators/index.js +++ b/lib/creator/generators/index.js @@ -1,6 +1,5 @@ const Generator = require('yeoman-generator'); -// eslint-disable-next-line -const {Input} = require('webpack-addons'); +const Input = require('webpack-addons').Input; class WebpackGenerator extends Generator { From c7cae5b243a8d991007faa2e9faaf463344d6059 Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Thu, 30 Mar 2017 19:52:43 +0200 Subject: [PATCH 09/10] fix: remove inquirer prompt and fix minor issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes inquirer, we’re not using it explicitly anymore. Fixed some review mistakes. --- lib/creator/generators/index.js | 6 +-- lib/creator/index.js | 2 +- lib/creator/init-transform.js | 6 +-- lib/initialize.js | 4 +- lib/inquirer-prompt.js | 77 --------------------------------- 5 files changed, 6 insertions(+), 89 deletions(-) delete mode 100644 lib/inquirer-prompt.js diff --git a/lib/creator/generators/index.js b/lib/creator/generators/index.js index d650f6d43f9..8433e0a06ee 100644 --- a/lib/creator/generators/index.js +++ b/lib/creator/generators/index.js @@ -2,7 +2,7 @@ const Generator = require('yeoman-generator'); const Input = require('webpack-addons').Input; -class WebpackGenerator extends Generator { +module.exports = class WebpackGenerator extends Generator { constructor(args, opts) { super(args, opts); this.myConfig = { @@ -27,6 +27,4 @@ class WebpackGenerator extends Generator { this.myConfig.childDependencies = ['webpack-addons-preact']; } inject() {} -} - -module.exports = WebpackGenerator; +}; diff --git a/lib/creator/index.js b/lib/creator/index.js index 1a2e61c2aaf..4741ce342b7 100644 --- a/lib/creator/index.js +++ b/lib/creator/index.js @@ -16,7 +16,7 @@ const chalk = require('chalk'); * @returns { } initTransform - Initializes the scaffold in yeoman */ -module.exports = function creator(pkgPaths,opts) { +module.exports = function creator(pkgPaths, opts) { // null, config -> without package // addon, null -> with package // we're dealing with init, we need to change this later, as it may have been emptied by yeoman diff --git a/lib/creator/init-transform.js b/lib/creator/init-transform.js index 62fd90308f2..8e6d601081f 100644 --- a/lib/creator/init-transform.js +++ b/lib/creator/init-transform.js @@ -14,8 +14,8 @@ const initGenerator = require('./generators/index'); */ module.exports = function initTransform(options) { + const env = yeoman.createEnv(); if(options) { - const env = yeoman.createEnv(); env.register(require.resolve(options), 'npm:app'); env.run('npm:app'); try { @@ -23,9 +23,7 @@ module.exports = function initTransform(options) { console.log('Done!'); //eslint-disable-next-line } catch (e) {} - } - else if(!options) { - const env = yeoman.createEnv(); + } else { env.registerStub(initGenerator, 'npm:app'); env.run('npm:app'); try { diff --git a/lib/initialize.js b/lib/initialize.js index 2985a8f8188..81a107ff32b 100644 --- a/lib/initialize.js +++ b/lib/initialize.js @@ -16,7 +16,5 @@ module.exports = function initializeInquirer(pkg) { if(pkg.length == 0) { return creator(); } - else { - return npmPackagesExists(pkg); - } + return npmPackagesExists(pkg); }; diff --git a/lib/inquirer-prompt.js b/lib/inquirer-prompt.js deleted file mode 100644 index d1dcf442a07..00000000000 --- a/lib/inquirer-prompt.js +++ /dev/null @@ -1,77 +0,0 @@ -const inquirer = require('inquirer'); -const chalk = require('chalk'); - -/* -* @function prompt -* -* Initializes an inquirer instance with questions provided from the --init feature -* -* @param { Object } questions - questions to be prompted in RxJS format -* @param { Object } config - Configuration passed from an addon to be included in -* answers, later sent down to the parser -* @returns { Function } Creator function that validates the answers, later transforming -* the answers to an webpack configuration -*/ - -module.exports = function prompt(questions, config) { - inquirer.prompt(questions).ui.process - .reduce(function (newOpts, ans) { - return attachAnswers(newOpts, ans); - }, Object.assign(config)) - .map(newOpts => { - const creator = require('./creator/index'); - return creator(null, checkEmptyAnswers(newOpts)); - }) - .subscribeOnError( (err) => console.log(err)); -}; - -/* -* @function attachAnswers -* -* Adds the answers from the inquirer instance if the type of the question is -* equal to the configuration property -* -* @param { Object } config - initial questions provided from --init -* @param { Object } answers - The answers passed from the inquirer instance -* @returns { Object } newConfig - An new object with the answers added to it -*/ - -function attachAnswers(config, answers) { - let newConfig; - Object.keys(config).forEach( (configName) => { - if(configName == answers.name) { - newConfig = Object.assign(config, { - [configName]: answers.answer - }); - } - }); - return newConfig; -} - -/* -* @function checkEmptyAnswers -* -* Checks for empty answers that didn't get attached from the prompt because it didn't match -* the given configuration property. If it finds an empty answer, it throws an error after logging -* each error to the console -* -* @param { Object } config - initial questions provided from --init -* @returns { Object } config - returns the configuration, -* as RxJS needs to have a return value to keep track of its context -*/ - -function checkEmptyAnswers(config) { - let errors = []; - for(let key in config) { - if(!config[key]) { - errors[key] = chalk.gray.bold('\nFound no answer given to property ') + - chalk.red.bold(key) + '\n'; - } - } - Object.keys(errors).map( (err) => { - console.error(errors[err]); - }).filter( () => { - process.exit(1); - }); - return config; -} From aec044a9c1ff37e3b39912a9859e1fe88d94661d Mon Sep 17 00:00:00 2001 From: Even Stensberg Date: Thu, 30 Mar 2017 19:56:14 +0200 Subject: [PATCH 10/10] fix: remove destruct and local import in some tests --- lib/creator/validate-options.spec.js | 4 ++-- lib/utils/resolve-packages.spec.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/creator/validate-options.spec.js b/lib/creator/validate-options.spec.js index e817c5b1ef1..5ffa642da2a 100644 --- a/lib/creator/validate-options.spec.js +++ b/lib/creator/validate-options.spec.js @@ -1,8 +1,8 @@ 'use strict'; +const validateOptions = require('../../__mocks__/creator/validate-options.mock').validateOptions; + describe('validate-options', () => { - //eslint-disable-next-line - const {validateOptions} = require('../../__mocks__/creator/validate-options.mock'); it('should throw on fake paths', () => { expect(() => { diff --git a/lib/utils/resolve-packages.spec.js b/lib/utils/resolve-packages.spec.js index f1a870a32fa..8ee4d39bd50 100644 --- a/lib/utils/resolve-packages.spec.js +++ b/lib/utils/resolve-packages.spec.js @@ -1,8 +1,8 @@ 'use strict'; +const getLoc = require('../../__mocks__/inquirer/resolve.mock'); + describe('resolve-packages', () => { - // eslint-disable-next-line - const getLoc = require('../../__mocks__/inquirer/resolve.mock'); let moduleLoc; afterEach(() => {