Skip to content

Commit

Permalink
fix: processing of cli flags
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed May 21, 2021
1 parent 5de4eea commit 55c7baa
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const normalizeOption = (option) => (typeof option === 'object' ? option : {});

module.exports = {
devServer: [
{
Expand Down Expand Up @@ -47,7 +49,7 @@ module.exports = {
],
description: 'Directory for static contents.',
processor(opts) {
opts.static = opts.static || {};
opts.static = normalizeOption(opts.static);
opts.static.directory = opts.staticDirectory;
delete opts.staticDirectory;
},
Expand All @@ -64,7 +66,7 @@ module.exports = {
'The bundled files will be available in the browser under this path.',
multiple: true,
processor(opts) {
opts.static = opts.static || {};
opts.static = normalizeOption(opts.static);
opts.static.publicPath = opts.staticPublicPath;
delete opts.staticPublicPath;
},
Expand All @@ -82,7 +84,7 @@ module.exports = {
'Do not tell dev-server to use serveIndex middleware.',
negative: true,
processor(opts) {
opts.static = opts.static || {};
opts.static = normalizeOption(opts.static);
opts.static.serveIndex = opts.staticServeIndex;
delete opts.staticServeIndex;
},
Expand All @@ -99,7 +101,7 @@ module.exports = {
negatedDescription: 'Do not watch for files in static content directory.',
negative: true,
processor(opts) {
opts.static = opts.static || {};
opts.static = normalizeOption(opts.static);
opts.static.watch = opts.staticWatch;
delete opts.staticWatch;
},
Expand Down Expand Up @@ -138,7 +140,7 @@ module.exports = {
],
description: 'Passphrase for a pfx file.',
processor(opts) {
opts.https = typeof opts.https === 'object' ? opts.https : {};
opts.https = normalizeOption(opts.https);
opts.https.passphrase = opts.httpsPassphrase;
delete opts.httpsPassphrase;
},
Expand All @@ -153,7 +155,7 @@ module.exports = {
],
description: 'Path to an SSL key.',
processor(opts) {
opts.https = typeof opts.https === 'object' ? opts.https : {};
opts.https = normalizeOption(opts.https);
opts.https.key = opts.httpsKey;
delete opts.httpsKey;
},
Expand All @@ -168,7 +170,7 @@ module.exports = {
],
description: 'Path to an SSL pfx file.',
processor(opts) {
opts.https = typeof opts.https === 'object' ? opts.https : {};
opts.https = normalizeOption(opts.https);
opts.https.pfx = opts.httpsPfx;
delete opts.httpsPfx;
},
Expand All @@ -183,7 +185,7 @@ module.exports = {
],
description: 'Path to an SSL certificate.',
processor(opts) {
opts.https = typeof opts.https === 'object' ? opts.https : {};
opts.https = normalizeOption(opts.https);
opts.https.cert = opts.httpsCert;
delete opts.httpsCert;
},
Expand All @@ -198,7 +200,7 @@ module.exports = {
],
description: 'Path to an SSL CA certificate.',
processor(opts) {
opts.https = typeof opts.https === 'object' ? opts.https : {};
opts.https = normalizeOption(opts.https);
opts.https.cacert = opts.httpsCacert;
delete opts.httpsCacert;
},
Expand All @@ -214,7 +216,7 @@ module.exports = {
description: 'Request for an SSL certificate.',
negatedDescription: 'Do not request for an SSL certificate.',
processor(opts) {
opts.https = typeof opts.https === 'object' ? opts.https : {};
opts.https = normalizeOption(opts.https);
opts.https.requestCert = opts.httpsRequestCert;
delete opts.httpsRequestCert;
},
Expand Down Expand Up @@ -257,7 +259,7 @@ module.exports = {
'Do not tell devServer to inject a Hot Module Replacement entry.',
negative: true,
processor(opts) {
opts.client = opts.client || {};
opts.client = normalizeOption(opts.client);
opts.client.hotEntry = opts.clientHotEntry;
delete opts.clientHotEntry;
},
Expand All @@ -275,7 +277,7 @@ module.exports = {
'Do not print compilation progress in percentage in the browser.',
negative: true,
processor(opts) {
opts.client = opts.client || {};
opts.client = normalizeOption(opts.client);
opts.client.progress = opts.clientProgress;
delete opts.clientProgress;
},
Expand All @@ -294,11 +296,27 @@ module.exports = {
'Do not show a full-screen overlay in the browser when there are compiler errors or warnings.',
negative: true,
processor(opts) {
opts.client = opts.client || {};
opts.client = normalizeOption(opts.client);
opts.client.overlay = opts.clientOverlay;
delete opts.clientOverlay;
},
},
{
name: 'client-logging',
type: String,
configs: [
{
type: 'string',
},
],
description:
'Log level in the browser (none, error, warn, info, log, verbose).',
processor(opts) {
opts.client = normalizeOption(opts.client);
opts.client.logging = opts.clientLogging;
delete opts.clientLogging;
},
},
{
name: 'open',
type: [Boolean, String],
Expand All @@ -325,7 +343,7 @@ module.exports = {
],
description: 'Open specified browser.',
processor(opts) {
opts.open = opts.open || {};
opts.open = normalizeOption(opts.open);
opts.open.app = opts.openApp;
delete opts.openApp;
},
Expand All @@ -343,30 +361,14 @@ module.exports = {
],
description: 'Open specified route in browser.',
processor(opts) {
opts.open = opts.open || {};
opts.open = normalizeOption(opts.open);
opts.open.target = opts.openTarget;
delete opts.openTarget;
},
negatedDescription: 'Do not open specified route in browser.',
multiple: true,
negative: true,
},
{
name: 'client-logging',
type: String,
configs: [
{
type: 'string',
},
],
description:
'Log level in the browser (none, error, warn, info, log, verbose).',
processor(opts) {
opts.client = opts.client || {};
opts.client.logging = opts.clientLogging;
delete opts.clientLogging;
},
},
{
name: 'history-api-fallback',
type: Boolean,
Expand Down

0 comments on commit 55c7baa

Please sign in to comment.