-
-
Notifications
You must be signed in to change notification settings - Fork 651
Feature/yeoman generators #93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e1164ce
d066fac
cc18385
fd018e0
af84d42
9182aef
01d83e2
ec0514b
1207ad8
c7cae5b
aec044a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
| ] | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
| 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() {} | ||
| }; |
| 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'); | ||
| } | ||
| */ | ||
| } | ||
| }; |
| 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) {} | ||
| } | ||
| }; |
| 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 | ||
|
|
@@ -17,9 +14,7 @@ const Rx = require('rx'); | |
|
|
||
| module.exports = function initializeInquirer(pkg) { | ||
| if(pkg.length == 0) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we check if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
| }; | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is deleted.