Skip to content

Commit 065e87e

Browse files
committedAug 28, 2019
chore: abstract validation
1 parent 55b770c commit 065e87e

File tree

4 files changed

+34
-17
lines changed

4 files changed

+34
-17
lines changed
 

‎bin/utils/convert-argv.js

+2-17
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ const fs = require("fs");
33
fs.existsSync = fs.existsSync || path.existsSync;
44
const interpret = require("interpret");
55
const prepareOptions = require("./prepareOptions");
6-
const webpackConfigurationSchema = require("../config/webpackConfigurationSchema.json");
7-
const validateSchema = require("webpack").validateSchema;
86
const findup = require("findup-sync");
7+
const validateOptions = require("./validate-options");
98

109
module.exports = function(...args) {
1110
const argv = args[1] || args[0];
@@ -136,21 +135,7 @@ module.exports = function(...args) {
136135

137136
function processConfiguredOptions(options) {
138137
if (options) {
139-
let error;
140-
try {
141-
const errors = validateSchema(webpackConfigurationSchema, options);
142-
if (errors && errors.length > 0) {
143-
const { WebpackOptionsValidationError } = require("webpack");
144-
error = new WebpackOptionsValidationError(errors);
145-
}
146-
} catch (err) {
147-
error = err;
148-
}
149-
150-
if (error) {
151-
console.error(error.message);
152-
process.exit(-1);
153-
}
138+
validateOptions(options);
154139
} else {
155140
options = {};
156141
}

‎bin/utils/validate-options.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const webpackConfigurationSchema = require("../config/webpackConfigurationSchema.json");
2+
const validateSchema = require("webpack").validateSchema;
3+
4+
module.exports = function validateOptions(options) {
5+
let error;
6+
try {
7+
const errors = validateSchema(webpackConfigurationSchema, options);
8+
if (errors && errors.length > 0) {
9+
const { WebpackOptionsValidationError } = require("webpack");
10+
error = new WebpackOptionsValidationError(errors);
11+
}
12+
} catch (err) {
13+
error = err;
14+
}
15+
16+
if (error) {
17+
console.error(error.message);
18+
process.exit(-1);
19+
}
20+
};

‎package-lock.json

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"babel-preset-jest": "24.6.0",
144144
"codecov": "3.5.0",
145145
"commitizen": "4.0.3",
146+
"commitlint": "^8.1.0",
146147
"commitlint-config-cz": "0.12.0",
147148
"conventional-changelog-cli": "2.0.21",
148149
"cz-customizable": "6.2.0",

0 commit comments

Comments
 (0)
Please sign in to comment.