Skip to content

Commit

Permalink
add support for enum props too
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed Dec 15, 2017
1 parent ce31e81 commit 3a49e16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 39 additions & 3 deletions lib/generators/add-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,51 @@ module.exports = class AddGenerator extends Generator {
* https://github.com/webpack/webpack/blob/next/schemas/WebpackOptions.json
* Find the properties directly in the properties prop, or the anyOf prop
*/
const defOrPropDescription = webpackSchemaProp
let defOrPropDescription = webpackSchemaProp
? webpackSchemaProp.properties
: webpackSchema.properties[action].properties
? webpackSchema.properties[action].properties
: webpackSchema.properties[action].anyOf
? webpackSchema.properties[action].anyOf.filter(
p => p.properties
)[0].properties
p => p.properties || p.enum
)
: null;
if (Array.isArray(defOrPropDescription)) {
// Todo: Generalize these to go through the array, then merge enum with props if needed
if (
defOrPropDescription[0].hasOwnProperty("properties") ||
defOrPropDescription[1].hasOwnProperty("properties")
) {
defOrPropDescription = defOrPropDescription[0].hasOwnProperty(
"properties"
)
? defOrPropDescription[0].properties
: defOrPropDescription[1].properties;
} else if (
defOrPropDescription[0].hasOwnProperty("enum") ||
defOrPropDescription[1].hasOwnProperty("enum")
) {
const originalPropDesc = defOrPropDescription[0].enum;
// Array -> Object -> Merge objects into one for compat in manualOrListInput
defOrPropDescription = Object.keys(defOrPropDescription[0].enum)
.map(p => {
return Object.assign(
{},
{
[originalPropDesc[p]]: "noop"
}
);
})
.reduce((result, currentObject) => {
for (let key in currentObject) {
if (currentObject.hasOwnProperty(key)) {
result[key] = currentObject[key];
}
}
return result;
}, {});
}
}
const webpackDevserverSchemaProp =
action === "devServer" ? webpackDevServerSchema : null;
// If we've got a schema prop or devServer Schema Prop
Expand Down
6 changes: 6 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
const webpack = require('webpack');
const webpack = require('webpack');
const webpack = require('webpack');
const webpack = require('webpack');
module.exports = {
externals: {
undefined: '',
undefined: 'a'
},

performance: {
0: ''
}
};

0 comments on commit 3a49e16

Please sign in to comment.