Skip to content
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

Refactor lib/creator and integrate validation in migrate #99

Merged
merged 6 commits into from
Apr 7, 2017

Conversation

evenstensberg
Copy link
Member

Did you add tests for your changes?
N/A

If relevant, did you update the documentation?

N/A

Summary

Lays the groundwork for a first release. Integrated Validation to
migrate, refactored creator for the init feature to not be circular and
made a cleaner structure to the project inside lib/creator.

Does this PR introduce a breaking change?
No

Other information

Lays the groundwork for a first release. Integrated Validation to
migrate, refactored creator for the init feature to not be circular and
made a cleaner structure to the project inside lib/creator.
@evenstensberg
Copy link
Member Author

@okonet Better to open this in PR in a text editor to see the changes. Could you review once you find the time?

module.exports = function (promptOptions) {
const promptParams = Object.keys(promptOptions);
if (promptParams && promptParams.length) {
let ast = j('{}');
Copy link
Contributor

Choose a reason for hiding this comment

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

That's not the Object as you might expect. This is a block statement. See https://astexplorer.net/#/gist/8ae05b2650bc27d2c4923ef8e6f36241/0a32afa94ee7cd5ecd742958c815706d34201345

.forEach(
p => p.value.properties.push(
j.property('init', j.literal('output'),
j.objectExpression([j.property('init', j.literal('filename'), j.literal(value))])))
Copy link
Contributor

Choose a reason for hiding this comment

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

You should check out the utils we've written for migrate feature: https://github.com/webpack/webpack-cli/blob/master/lib/transformations/utils.js#L82

fs.writeFileSync(outputConfigPath, result, 'utf8');
console.log(chalk.green(`✔︎ New webpack v2 config file is at ${outputConfigPath}`));
fs.writeFile(outputConfigPath, result, 'utf8', (err) => {
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, require(outputConfigPath));
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this go to a separate PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably not needed. Fixing the transform issues and let's merge and take it from there.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm working on a fix PR and desperately need this! :)

@evenstensberg
Copy link
Member Author

@pksjce I've started the transformations, but let's move it to another seperate branch after this gets merged. I'll open a wip for you to follow along.

const env = yeoman.createEnv(null, null, new WebpackAdapter());

if(options) {
env.register(require.resolve(options), 'npm:app');

Choose a reason for hiding this comment

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

I'd probably rename npm:app to avoid any potential collisions by other packages that may have registered a Yeoman environment. Maybe webpack:cli?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's gonna be assigned to the generator name :) See previous comment.

env.register(require.resolve(options), 'npm:app');

env.run('npm:app')
.on('end', () => {

Choose a reason for hiding this comment

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

This is an arrow function, so you could either just one-line it and leave out the return, or since it's an event, you probably don't need the return at all.

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 actually just the first integration, would need to change the generatorName through env.getGeneratorMetaData() later, could integrate it now though.

Copy link
Contributor

@okonet okonet left a comment

Choose a reason for hiding this comment

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

LGTM in general. See a couple of comments

*/

function replaceGeneratorName(name) {
return name.replace(
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind adding tests for this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, giveme 1h :) At school

env.register(require.resolve(options), generatorName);

env.run(generatorName)
.on('end', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the duplication be removed from these 2 code branches?

Also indentation is odd but this can be fixed as #102 is merged,

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I was thinking about it actually, will do that.

@pksjce
Copy link

pksjce commented Apr 7, 2017

Cool. I will work on a separate PR for transformations. My previous PR was meant for feedback. I was really not sure what approach would work with yeoman.
Also could you solve these
https://www.codacy.com/app/okonet/webpack-cli/pullRequest?prid=594576
Would be good to comment them out for now.

Also commented out unused modules for now.
@evenstensberg
Copy link
Member Author

There we go @okonet @pksjce . I've started the work on the AST's @pksjce , lemme open a wip with my stuff for us to work with.

@codecov
Copy link

codecov bot commented Apr 7, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@6e93af5). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #99   +/-   ##
=========================================
  Coverage          ?   94.49%           
=========================================
  Files             ?       13           
  Lines             ?      363           
  Branches          ?       75           
=========================================
  Hits              ?      343           
  Misses            ?       20           
  Partials          ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e93af5...717b61e. Read the comment docs.

@@ -0,0 +1,15 @@
'use strict';

function replaceGeneratorName(name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be the real implementation? Export it and import here to remove code duplication, please.


it('should replace a pattern of an addon', () => {
const generatorName = replaceGeneratorName('webpack-addons-thefox');
expect(generatorName).toEqual('generator-thefox');
Copy link
Contributor

@okonet okonet Apr 7, 2017

Choose a reason for hiding this comment

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

The regex looks more complex as just this test and covers more edge cases. Should we test against them?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just an initial commit, can add more tests later and label an issue with good first contribution

@evenstensberg evenstensberg merged commit 66280b9 into master Apr 7, 2017
@evenstensberg evenstensberg deleted the feature/refactor branch April 7, 2017 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants