@caweb/cli 1.15.3 → 1.15.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,121 @@
1
+ // This file is auto-generated via "npm run update:webpack:flags"
2
+ const buildFlags = [
3
+ "-c",
4
+ "--config",
5
+ "--config-name",
6
+ "-m",
7
+ "--merge",
8
+ "--disable-interpret",
9
+ "--env",
10
+ "--node-env",
11
+ "--config-node-env",
12
+ "--analyze",
13
+ "--progress",
14
+ "-j",
15
+ "--json",
16
+ "--fail-on-warnings",
17
+ "-d",
18
+ "--devtool",
19
+ "--no-devtool",
20
+ "--entry",
21
+ "-e",
22
+ "--extends",
23
+ "--mode",
24
+ "--name",
25
+ "-o",
26
+ "--output-path",
27
+ "--stats",
28
+ "--no-stats",
29
+ "-t",
30
+ "--target",
31
+ "--no-target",
32
+ "-w",
33
+ "--watch",
34
+ "--no-watch",
35
+ "--watch-options-stdin",
36
+ "--no-watch-options-stdin",
37
+ "--color",
38
+ "--no-color",
39
+ "-v",
40
+ "--version",
41
+ "-h",
42
+ "--help"
43
+ ];
44
+
45
+ const serveFlags = [
46
+ "--allowed-hosts",
47
+ "--allowed-hosts-reset",
48
+ "--bonjour",
49
+ "--no-bonjour",
50
+ "--no-client",
51
+ "--client-logging",
52
+ "--client-overlay",
53
+ "--no-client-overlay",
54
+ "--client-overlay-errors",
55
+ "--no-client-overlay-errors",
56
+ "--client-overlay-warnings",
57
+ "--no-client-overlay-warnings",
58
+ "--client-overlay-runtime-errors",
59
+ "--no-client-overlay-runtime-errors",
60
+ "--client-overlay-trusted-types-policy-name",
61
+ "--client-progress",
62
+ "--no-client-progress",
63
+ "--client-reconnect",
64
+ "--no-client-reconnect",
65
+ "--client-web-socket-transport",
66
+ "--client-web-socket-url",
67
+ "--client-web-socket-url-hostname",
68
+ "--client-web-socket-url-pathname",
69
+ "--client-web-socket-url-password",
70
+ "--client-web-socket-url-port",
71
+ "--client-web-socket-url-protocol",
72
+ "--client-web-socket-url-username",
73
+ "--compress",
74
+ "--no-compress",
75
+ "--history-api-fallback",
76
+ "--no-history-api-fallback",
77
+ "--host",
78
+ "--hot",
79
+ "--no-hot",
80
+ "--ipc",
81
+ "--live-reload",
82
+ "--no-live-reload",
83
+ "--open",
84
+ "--no-open",
85
+ "--open-target",
86
+ "--open-app-name",
87
+ "--open-reset",
88
+ "--open-target-reset",
89
+ "--open-app-name-reset",
90
+ "--port",
91
+ "--server-type",
92
+ "--server-options-passphrase",
93
+ "--server-options-request-cert",
94
+ "--no-server-options-request-cert",
95
+ "--server-options-ca",
96
+ "--server-options-ca-reset",
97
+ "--server-options-cert",
98
+ "--server-options-cert-reset",
99
+ "--server-options-crl",
100
+ "--server-options-crl-reset",
101
+ "--server-options-key",
102
+ "--server-options-key-reset",
103
+ "--server-options-pfx",
104
+ "--server-options-pfx-reset",
105
+ "--static",
106
+ "--no-static",
107
+ "--static-directory",
108
+ "--static-public-path",
109
+ "--static-serve-index",
110
+ "--no-static-serve-index",
111
+ "--static-watch",
112
+ "--no-static-watch",
113
+ "--static-reset",
114
+ "--static-public-path-reset",
115
+ "--watch-files",
116
+ "--watch-files-reset",
117
+ "--no-web-socket-server",
118
+ "--web-socket-server-type"
119
+ ];
120
+
121
+ export { buildFlags, serveFlags };
@@ -11,6 +11,7 @@ import {
11
11
  runCmd
12
12
  } from '../../lib/index.js';
13
13
 
14
+ import { buildFlags, serveFlags } from './webpack-flags.js';
14
15
 
15
16
  /**
16
17
  * Build the current project
@@ -29,7 +30,8 @@ export default async function webpack({
29
30
  externals
30
31
  } ) {
31
32
  const webpackCommand = 'build' === process.argv[2] ? 'build' : 'serve' ;
32
-
33
+ const webpackAllowedFlags = 'build' === webpackCommand ? buildFlags : serveFlags ;
34
+
33
35
  // we use our default config from the @caweb/webpack
34
36
  const defaultConfigPath = path.resolve('node_modules', '@caweb', 'webpack', 'webpack.config.js' );
35
37
 
@@ -62,8 +64,39 @@ export default async function webpack({
62
64
 
63
65
  }
64
66
 
65
- // add the --merge flag to allow merging configs.
66
- webPackArgs.push( '--merge' );
67
+ // if -c or --config appears twice in the args we add the --merge flag
68
+ if( webPackArgs.filter( arg => '-c' === arg || '--config' === arg ).length > 1 ){
69
+ webPackArgs.push( '--merge' );
70
+ }
71
+
72
+ let unknown = false;
73
+ let unkownArgs = [];
74
+
75
+ // we have to filter out unknown args to avoid webpack errors
76
+ webPackArgs = webPackArgs.filter( (e) => {
77
+
78
+ if( e.startsWith('--') ){
79
+ // set unknown flag
80
+ unknown = ! webpackAllowedFlags.includes(e);
81
+
82
+ // save unknown flag
83
+ if( unknown ){
84
+ unkownArgs.push(e);
85
+ }
86
+
87
+ // return if known flag
88
+ return webpackAllowedFlags.includes(e);
89
+ }else{
90
+ // save unknown args
91
+ if( unknown ){
92
+ unkownArgs.push(e);
93
+ }
94
+
95
+ // if flag was known return the value, else false
96
+ return ! unknown ? e : false;
97
+ }
98
+ }
99
+ );
67
100
 
68
101
  // run the webpackCommand command.
69
102
  await runCmd(
@@ -74,6 +107,7 @@ export default async function webpack({
74
107
  ],
75
108
  {
76
109
  stdio: 'inherit',
110
+ argv0: unkownArgs.join(' ')
77
111
  }
78
112
  );
79
113
  };
package/lib/cli.js CHANGED
@@ -4,7 +4,7 @@
4
4
  //const wpenv_cli = require('@wordpress/env/lib/cli');
5
5
  import path from 'path';
6
6
  import fs from 'fs';
7
- import { Command, Argument, Option } from 'commander';
7
+ import { Command, Argument, Option, InvalidArgumentError } from 'commander';
8
8
 
9
9
  /**
10
10
  * Internal dependencies
@@ -62,7 +62,22 @@ function addWebpackCmds(){
62
62
  // Serve Command.
63
63
  program.command('serve')
64
64
  .description('Serves the current project using CAWebPublishing templates.')
65
- .addOption(new Option('--template <template>', 'Serves the project using templating.').choices(['default', 'blank']).default('default'))
65
+ .addOption(new Option('--template <template>', 'Serves the project using templating.').choices(['default', 'blank', '<local file>']).default('default').argParser( ( choice, t ) => {
66
+
67
+ // if choice is a valid option return it.
68
+ if( [ 'default', 'blank' ].includes( choice ) ){
69
+ return choice;
70
+ }
71
+
72
+ // if choice is a valid local file return the absolute path.
73
+ const localPath = path.resolve( choice );
74
+ if( fs.existsSync( localPath ) ){
75
+ return localPath;
76
+ }
77
+
78
+ // invalid option return error.
79
+ throw new InvalidArgumentError('Allowed choices are default, blank, <local file>.');
80
+ }))
66
81
  .addOption(new Option('--scheme <scheme>', 'Serves the project using template colorscheme.').choices([
67
82
  'delta',
68
83
  'eureka',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caweb/cli",
3
- "version": "1.15.3",
3
+ "version": "1.15.5",
4
4
  "description": "CAWebPublishing Command Line Interface.",
5
5
  "exports": "./lib/env.js",
6
6
  "type": "module",
@@ -20,7 +20,8 @@
20
20
  ],
21
21
  "scripts": {
22
22
  "caweb": "node bin/caweb.js",
23
- "doc": "node ./docs/tool/index.js",
23
+ "update:webpack:flags": "node ./scripts/webpack-flags.js",
24
+ "doc": "node ./scripts/documentation.js",
24
25
  "test": "echo \"Error: run tests from root\" && exit 0"
25
26
  },
26
27
  "homepage": "https://github.com/CAWebPublishing/cli#readme",
@@ -63,7 +64,7 @@
63
64
  }
64
65
  },
65
66
  "dependencies": {
66
- "@caweb/webpack": "^1.5.11",
67
+ "@caweb/webpack": "^1.5.12",
67
68
  "@inquirer/prompts": "^8.1.0",
68
69
  "@wordpress/create-block": "^4.80.0",
69
70
  "@wordpress/env": "^10.37.0",