Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"webpack-addons-ylvis": {
"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?"
},
{
"type": "input",
"name": "resolve",
"message": "This is resolve peeps"
}
],
"config": {
"entry": " ",
"output": " ",
"resolve": " "
},
"childDependencies": [
"webpack-addons-preact"
]
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is deleted.

32 changes: 0 additions & 32 deletions __mocks__/inquirer/initialize.mock.js

This file was deleted.

32 changes: 0 additions & 32 deletions __mocks__/inquirer/prompt.mock.js

This file was deleted.

3 changes: 3 additions & 0 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) !== '') {
Expand Down
30 changes: 30 additions & 0 deletions lib/creator/generators/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const Generator = require('yeoman-generator');
const Input = require('webpack-addons').Input;


module.exports = class WebpackGenerator extends Generator {
constructor(args, opts) {
super(args, opts);
this.myConfig = {
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 = {
entry: ' ',
output: ' '
};
}
childDependencies() {
this.myConfig.childDependencies = ['webpack-addons-preact'];
}
inject() {}
};
41 changes: 41 additions & 0 deletions lib/creator/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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 creator
*
* 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 path of the package and runs inquirer
*
* @param { Array } pkgPaths - An Array of packages to run
* @param { <object|null> } opts - An object containing webpackOptions or nothing
* @returns { <Function|Error> } initTransform - Initializes the scaffold in yeoman
*/

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
if(!pkgPaths && !opts) {
initTransform();
}
else if(pkgPaths) {
// this example app actually needs a refactor in order for it to work
initTransform(pkgPaths);
}
else if(!pkgPaths && opts) {
// scaffold is done
/*
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');
}
*/
}
};
34 changes: 34 additions & 0 deletions lib/creator/init-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs');
const path = require('path');
const yeoman = require('yeoman-environment');
const Generator = require('yeoman-generator');
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 { <Void> }
*/

module.exports = function initTransform(options) {
const env = yeoman.createEnv();
if(options) {
env.register(require.resolve(options), 'npm:app');
env.run('npm:app');
try {
let name = path.basename(options);
console.log('Done!');
//eslint-disable-next-line
} catch (e) {}
} else {
env.registerStub(initGenerator, 'npm:app');
env.run('npm:app');
try {
console.log('Done!');
// eslint-disable-next-line
} catch (e) {}
}
};
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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__/parser/validate-options.mock');

it('should throw on fake paths', () => {
expect(() => {
Expand Down
11 changes: 3 additions & 8 deletions lib/initialize.js
Original file line number Diff line number Diff line change
@@ -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 creator = require('./creator/index');

/*
* @function initializeInquirer
Expand All @@ -17,9 +14,7 @@ const Rx = require('rx');

module.exports = function initializeInquirer(pkg) {
if(pkg.length == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if pkg is Array? Otherwise this will be a run-time error.

Copy link
Member Author

@evenstensberg evenstensberg Mar 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is default in yargs, in the future, when we're revamping the ui, perhaps.

return prompt(Rx.Observable.from(questions), initialConfig);
}
else {
return npmPackagesExists(pkg);
return creator();
}
return npmPackagesExists(pkg);
};
77 changes: 0 additions & 77 deletions lib/inquirer-prompt.js

This file was deleted.

20 changes: 0 additions & 20 deletions lib/inquirer-prompt.spec.js

This file was deleted.

37 changes: 0 additions & 37 deletions lib/parser/index.js

This file was deleted.

12 changes: 0 additions & 12 deletions lib/parser/resolve-transform.js

This file was deleted.

Loading