Refactor lib/creator and integrate validation in migrate#99
Conversation
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.
|
@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('{}'); |
There was a problem hiding this comment.
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))]))) |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
Should this go to a separate PR?
There was a problem hiding this comment.
Probably not needed. Fixing the transform issues and let's merge and take it from there.
There was a problem hiding this comment.
I'm working on a fix PR and desperately need this! :)
9581031 to
77dc227
Compare
|
@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'); |
There was a problem hiding this comment.
I'd probably rename npm:app to avoid any potential collisions by other packages that may have registered a Yeoman environment. Maybe webpack:cli?
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is actually just the first integration, would need to change the generatorName through env.getGeneratorMetaData() later, could integrate it now though.
fbf8392 to
9a84b36
Compare
okonet
left a comment
There was a problem hiding this comment.
LGTM in general. See a couple of comments
| */ | ||
|
|
||
| function replaceGeneratorName(name) { | ||
| return name.replace( |
There was a problem hiding this comment.
Mind adding tests for this one?
There was a problem hiding this comment.
Sure, giveme 1h :) At school
| env.register(require.resolve(options), generatorName); | ||
|
|
||
| env.run(generatorName) | ||
| .on('end', () => { |
There was a problem hiding this comment.
Can the duplication be removed from these 2 code branches?
Also indentation is odd but this can be fixed as #102 is merged,
There was a problem hiding this comment.
Yeah, I was thinking about it actually, will do that.
|
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 commented out unused modules for now.
3833e75 to
3dee6de
Compare
Codecov Report
@@ Coverage Diff @@
## master #99 +/- ##
=========================================
Coverage ? 94.49%
=========================================
Files ? 13
Lines ? 363
Branches ? 75
=========================================
Hits ? 343
Misses ? 20
Partials ? 0Continue to review full report at Codecov.
|
| @@ -0,0 +1,15 @@ | |||
| 'use strict'; | |||
|
|
|||
| function replaceGeneratorName(name) { | |||
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
The regex looks more complex as just this test and covers more edge cases. Should we test against them?
There was a problem hiding this comment.
Just an initial commit, can add more tests later and label an issue with good first contribution
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