Skip to content

Commit 8fe0c97

Browse files
committed
feat: reset flags
1 parent 574bb47 commit 8fe0c97

File tree

2 files changed

+278
-1
lines changed

2 files changed

+278
-1
lines changed

bin/cli-flags.js

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const normalizeOption = (option) => (typeof option === 'object' ? option : {});
3+
const normalizeOption = (option) =>
4+
typeof option === 'object' && !Array.isArray(option) ? option : {};
45

56
module.exports = {
67
bonjour: {
@@ -344,6 +345,23 @@ module.exports = {
344345
simpleType: 'string',
345346
multiple: true,
346347
},
348+
'firewall-reset': {
349+
configs: [
350+
{
351+
type: 'reset',
352+
multiple: false,
353+
description: 'Clear all items provided in firewall configuration.',
354+
path: 'firewall',
355+
},
356+
],
357+
description: 'Clear all items provided in firewall configuration.',
358+
simpleType: 'boolean',
359+
multiple: false,
360+
processor(opts) {
361+
opts.firewall = opts.firewall || [];
362+
delete opts.firewallReset;
363+
},
364+
},
347365
'history-api-fallback': {
348366
configs: [
349367
{
@@ -647,6 +665,60 @@ module.exports = {
647665
delete opts.openApp;
648666
},
649667
},
668+
'open-reset': {
669+
configs: [
670+
{
671+
type: 'reset',
672+
multiple: false,
673+
description: 'Clear all items provided in open configuration.',
674+
path: 'open',
675+
},
676+
],
677+
description: 'Clear all items provided in open configuration.',
678+
simpleType: 'boolean',
679+
multiple: false,
680+
processor(opts) {
681+
opts.open = opts.open || [];
682+
delete opts.openReset;
683+
},
684+
},
685+
'open-target-reset': {
686+
configs: [
687+
{
688+
type: 'reset',
689+
multiple: false,
690+
description: 'Clear all items provided in open.target configuration.',
691+
path: 'open.target',
692+
},
693+
],
694+
description: 'Clear all items provided in open.target configuration.',
695+
simpleType: 'boolean',
696+
multiple: false,
697+
processor(opts) {
698+
opts.open = normalizeOption(opts.open);
699+
opts.open.target = opts.openTarget || [];
700+
delete opts.openTargetReset;
701+
},
702+
},
703+
'open-app-name-reset': {
704+
configs: [
705+
{
706+
type: 'reset',
707+
multiple: false,
708+
description: 'Clear all items provided in open.app.name configuration.',
709+
path: 'open.app.name',
710+
},
711+
],
712+
description: 'Clear all items provided in open.app.name configuration.',
713+
simpleType: 'boolean',
714+
multiple: false,
715+
processor(opts) {
716+
opts.open = normalizeOption(opts.open);
717+
opts.open.app = normalizeOption(opts.open.app);
718+
opts.open.app.name = opts.openAppName || [];
719+
delete opts.openAppNameReset;
720+
},
721+
},
650722
port: {
651723
configs: [
652724
{
@@ -794,6 +866,42 @@ module.exports = {
794866
delete opts.staticWatch;
795867
},
796868
},
869+
'static-reset': {
870+
configs: [
871+
{
872+
type: 'reset',
873+
multiple: false,
874+
description: 'Clear all items provided in static configuration.',
875+
path: 'static',
876+
},
877+
],
878+
description: 'Clear all items provided in static configuration.',
879+
simpleType: 'boolean',
880+
multiple: false,
881+
processor(opts) {
882+
opts.static = opts.static || [];
883+
delete opts.staticReset;
884+
},
885+
},
886+
'static-public-path-reset': {
887+
configs: [
888+
{
889+
type: 'reset',
890+
multiple: false,
891+
description:
892+
'Clear all items provided in static.publicPath configuration.',
893+
path: 'static.publicPath',
894+
},
895+
],
896+
description: 'Clear all items provided in static.publicPath configuration.',
897+
simpleType: 'boolean',
898+
multiple: false,
899+
processor(opts) {
900+
opts.static = normalizeOption(opts.static);
901+
opts.static.publicPath = opts.staticPublicPath || [];
902+
delete opts.staticPublicPathReset;
903+
},
904+
},
797905
'watch-files': {
798906
configs: [
799907
{
@@ -831,4 +939,40 @@ module.exports = {
831939
delete opts.watchFilesPaths;
832940
},
833941
},
942+
'watch-files-reset': {
943+
configs: [
944+
{
945+
type: 'reset',
946+
multiple: false,
947+
description: 'Clear all items provided in watchFiles configuration.',
948+
path: 'watchFiles',
949+
},
950+
],
951+
description: 'Clear all items provided in watchFiles configuration.',
952+
simpleType: 'boolean',
953+
multiple: false,
954+
processor(opts) {
955+
opts.watchFiles = opts.watchFiles || [];
956+
delete opts.watchFilesReset;
957+
},
958+
},
959+
'watch-files-paths-reset': {
960+
configs: [
961+
{
962+
type: 'reset',
963+
multiple: false,
964+
description:
965+
'Clear all items provided in watchFiles.paths configuration.',
966+
path: 'watchFiles.paths',
967+
},
968+
],
969+
description: 'Clear all items provided in watchFiles.paths configuration.',
970+
simpleType: 'boolean',
971+
multiple: false,
972+
processor(opts) {
973+
opts.watchFiles = normalizeOption(opts.watchFiles);
974+
opts.watchFiles.paths = opts.watchFilesPaths || [];
975+
delete opts.watchFilesPathsReset;
976+
},
977+
},
834978
};

test/cli/cli.test.js

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ describe('CLI', () => {
342342
.catch(done);
343343
});
344344

345+
it('--firewall-reset', (done) => {
346+
testBin('--firewall-reset --firewall hello.com')
347+
.then((output) => {
348+
expect(output.exitCode).toEqual(0);
349+
done();
350+
})
351+
.catch(done);
352+
});
353+
345354
it('--http2', (done) => {
346355
testBin('--http2')
347356
.then((output) => {
@@ -679,6 +688,33 @@ describe('CLI', () => {
679688
.catch(done);
680689
});
681690

691+
it('--open-reset', (done) => {
692+
testBin('--open-reset --open /third.html')
693+
.then((output) => {
694+
expect(output.exitCode).toEqual(0);
695+
done();
696+
})
697+
.catch(done);
698+
});
699+
700+
it('--open-reset --open-target', (done) => {
701+
testBin('--open-reset --open-target')
702+
.then((output) => {
703+
expect(output.exitCode).toEqual(0);
704+
done();
705+
})
706+
.catch(done);
707+
});
708+
709+
it('--open-reset --open-target <value>', (done) => {
710+
testBin('--open-reset --open-target /third.html')
711+
.then((output) => {
712+
expect(output.exitCode).toEqual(0);
713+
done();
714+
})
715+
.catch(done);
716+
});
717+
682718
it('--open-app google-chrome', (done) => {
683719
testBin('--open-app google-chrome')
684720
.then((output) => {
@@ -697,6 +733,15 @@ describe('CLI', () => {
697733
.catch(done);
698734
});
699735

736+
it('--open-app-name-reset', (done) => {
737+
testBin('--open-app-name-reset --open-app-name firefox')
738+
.then((output) => {
739+
expect(output.exitCode).toEqual(0);
740+
done();
741+
})
742+
.catch(done);
743+
});
744+
700745
it('--open-target', (done) => {
701746
testBin('--open-target')
702747
.then((output) => {
@@ -724,6 +769,15 @@ describe('CLI', () => {
724769
.catch(done);
725770
});
726771

772+
it('--open-target-reset', (done) => {
773+
testBin('--open-target-reset --open-target first.html')
774+
.then((output) => {
775+
expect(output.exitCode).toEqual(0);
776+
done();
777+
})
778+
.catch(done);
779+
});
780+
727781
it(' --open --open-target index.html', (done) => {
728782
testBin('--open --open-target index.html')
729783
.then((output) => {
@@ -830,6 +884,34 @@ describe('CLI', () => {
830884
.catch(done);
831885
});
832886

887+
it('--static-reset', (done) => {
888+
testBin(
889+
`--static-reset --static ${path.resolve(
890+
__dirname,
891+
'../fixtures/static/webpack.config.js'
892+
)}`
893+
)
894+
.then((output) => {
895+
expect(output.exitCode).toEqual(0);
896+
done();
897+
})
898+
.catch(done);
899+
});
900+
901+
it('--static-reset --static-directory <value>', (done) => {
902+
testBin(
903+
`--static-reset --static-directory ${path.resolve(
904+
__dirname,
905+
'../fixtures/static/webpack.config.js'
906+
)}`
907+
)
908+
.then((output) => {
909+
expect(output.exitCode).toEqual(0);
910+
done();
911+
})
912+
.catch(done);
913+
});
914+
833915
it('--static-directory', (done) => {
834916
testBin(
835917
`--static-directory ${path.resolve(
@@ -858,6 +940,24 @@ describe('CLI', () => {
858940
.catch(done);
859941
});
860942

943+
it('--static-public-path', (done) => {
944+
testBin('--static-public-path /public')
945+
.then((output) => {
946+
expect(output.exitCode).toEqual(0);
947+
done();
948+
})
949+
.catch(done);
950+
});
951+
952+
it('--static-public-path-reset', (done) => {
953+
testBin('--static-public-path-reset --static-public-path /new-public')
954+
.then((output) => {
955+
expect(output.exitCode).toEqual(0);
956+
done();
957+
})
958+
.catch(done);
959+
});
960+
861961
it('--static-serve-index', (done) => {
862962
testBin('--static-serve-index')
863963
.then((output) => {
@@ -929,6 +1029,28 @@ describe('CLI', () => {
9291029
.catch(done);
9301030
});
9311031

1032+
it('--watch-files-reset', (done) => {
1033+
const watchDirectory = path.resolve(__dirname, '../fixtures/static/static');
1034+
1035+
testBin(`--watch-files-reset --watch-files ${watchDirectory}`)
1036+
.then((output) => {
1037+
expect(output.exitCode).toEqual(0);
1038+
done();
1039+
})
1040+
.catch(done);
1041+
});
1042+
1043+
it('--watch-files-reset --watch-files-paths <value>', (done) => {
1044+
const watchDirectory = path.resolve(__dirname, '../fixtures/static/static');
1045+
1046+
testBin(`--watch-files-reset --watch-files-paths ${watchDirectory}`)
1047+
.then((output) => {
1048+
expect(output.exitCode).toEqual(0);
1049+
done();
1050+
})
1051+
.catch(done);
1052+
});
1053+
9321054
it('--watch-files-paths', (done) => {
9331055
const watchDirectory = path.resolve(__dirname, '../fixtures/static/static');
9341056

@@ -940,6 +1062,17 @@ describe('CLI', () => {
9401062
.catch(done);
9411063
});
9421064

1065+
it('--watch-files-paths-reset', (done) => {
1066+
const watchDirectory = path.resolve(__dirname, '../fixtures/static/static');
1067+
1068+
testBin(`--watch-files-paths-reset --watch-files-paths ${watchDirectory}`)
1069+
.then((output) => {
1070+
expect(output.exitCode).toEqual(0);
1071+
done();
1072+
})
1073+
.catch(done);
1074+
});
1075+
9431076
it('should accept the promise function of webpack.config.js', (done) => {
9441077
testBin(
9451078
false,

0 commit comments

Comments
 (0)