@caweb/cli 1.15.17 → 1.15.19
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.
- package/configs/webpack.plugins.js +135 -43
- package/lib/cli.js +1 -0
- package/package.json +8 -6
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import fs from 'fs';
|
|
7
|
-
import
|
|
7
|
+
import SitemapWebpackPlugin from 'sitemap-webpack-plugin';
|
|
8
8
|
|
|
9
9
|
import CAWebHTMLPlugin from "@caweb/html-webpack-plugin";
|
|
10
10
|
import CAWebA11yPlugin from '@caweb/a11y-webpack-plugin';
|
|
11
11
|
import CAWebCSSAuditPlugin from '@caweb/css-audit-webpack-plugin';
|
|
12
12
|
import CAWebJSHintPlugin from '@caweb/jshint-webpack-plugin';
|
|
13
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
14
|
+
import Handlebars from '@caweb/webpack/lib/handlebars.js';
|
|
13
15
|
|
|
14
|
-
import { flagExists, getArgVal } from '@caweb/webpack/lib/args.js';
|
|
15
|
-
|
|
16
|
+
import { flagExists, getArgVal, flags } from '@caweb/webpack/lib/args.js';
|
|
16
17
|
|
|
17
18
|
// this is the path to the current project directory
|
|
18
19
|
const appPath = process.cwd();
|
|
@@ -26,47 +27,65 @@ JSON.parse(fs.readFileSync(path.join(appPath, 'caweb.json')))
|
|
|
26
27
|
|
|
27
28
|
// argument variables
|
|
28
29
|
let template = getArgVal( 'template', path.join(templatePath, 'patterns', 'default.html') );
|
|
29
|
-
|
|
30
|
+
|
|
30
31
|
let scheme = getArgVal( 'scheme', 'oceanside' );
|
|
31
32
|
|
|
33
|
+
// Template patterns
|
|
34
|
+
let patterns = fs.readdirSync(path.join(templatePath, 'patterns'), { withFileTypes: true } )
|
|
35
|
+
.filter( dirent => dirent.isFile() && (dirent.name.endsWith('.html') ) )
|
|
36
|
+
.map( ( dirent ) => {
|
|
37
|
+
|
|
38
|
+
let fileTemplate = path.join( dirent.parentPath, dirent.name );
|
|
39
|
+
let filename = fileTemplate.replace(path.join(templatePath, 'patterns'), '').replace(/\\/g, '');
|
|
40
|
+
|
|
41
|
+
// we ignore the default and blank patterns since those are used as templates and not actual pages
|
|
42
|
+
// if there is no Google Search Id we ignore the search pattern since that is only used for the Search Results page
|
|
43
|
+
if (
|
|
44
|
+
['default.html', 'blank.html'].includes( filename ) ||
|
|
45
|
+
(filename === 'serp.html' && ! caweb?.site?.google?.search)
|
|
46
|
+
) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
file: fileTemplate,
|
|
52
|
+
filename,
|
|
53
|
+
};
|
|
54
|
+
})
|
|
55
|
+
.filter( Boolean );
|
|
56
|
+
|
|
32
57
|
// Additional pages directory
|
|
33
58
|
let basePageDir = path.join(appPath, 'content', 'pages');
|
|
59
|
+
|
|
34
60
|
let additionalPages = ! fs.existsSync( basePageDir ) ? [] :
|
|
35
61
|
fs.readdirSync( basePageDir, { withFileTypes: true, recursive: true } )
|
|
36
62
|
.filter( dirent => dirent.isFile() && (dirent.name.endsWith('.html') || dirent.name.endsWith('.handlebars')) )
|
|
37
63
|
.map( ( dirent ) => {
|
|
38
64
|
|
|
39
65
|
let fileTemplate = path.join( dirent.parentPath, dirent.name );
|
|
66
|
+
let filename = fileTemplate.replace(basePageDir, '').replace(/\\/, '');
|
|
40
67
|
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let data = {
|
|
47
|
-
...caweb.site,
|
|
48
|
-
scheme
|
|
49
|
-
};
|
|
50
|
-
let compiler = Handlebars.compile( content );
|
|
51
|
-
let compiledContent = compiler(data);
|
|
68
|
+
// if additionl pages match a pattern page we remove ours
|
|
69
|
+
let override = patterns.find( (p) => p.filename === filename );
|
|
70
|
+
if( override ){
|
|
71
|
+
patterns = patterns.filter( (p) => p.filename !== filename );
|
|
72
|
+
}
|
|
52
73
|
|
|
53
|
-
return
|
|
74
|
+
return {
|
|
75
|
+
file: fileTemplate,
|
|
76
|
+
filename,
|
|
54
77
|
template,
|
|
55
|
-
|
|
56
|
-
title,
|
|
57
|
-
templateParameters: {
|
|
58
|
-
scheme,
|
|
59
|
-
partial: compiledContent,
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
});
|
|
78
|
+
}
|
|
63
79
|
})
|
|
64
80
|
|
|
65
|
-
|
|
81
|
+
let customPages = [...patterns, ...additionalPages ].filter( Boolean );
|
|
66
82
|
|
|
83
|
+
export default {
|
|
84
|
+
|
|
67
85
|
plugins: [
|
|
68
86
|
// add custom plugins here
|
|
69
87
|
// Used for Site Generation
|
|
88
|
+
// when using the CAWebHTMLPlugin we dont have to pass the caweb.site data since that is automatically done by the plugin, we just need to pass the scheme so that it can be used in the templates
|
|
70
89
|
new CAWebHTMLPlugin({
|
|
71
90
|
template,
|
|
72
91
|
templateParameters: {
|
|
@@ -74,28 +93,101 @@ export default {
|
|
|
74
93
|
},
|
|
75
94
|
}),
|
|
76
95
|
|
|
77
|
-
// this plugin generates Search Results page using the template found in patterns/search.html
|
|
78
|
-
caweb?.site?.google?.search ? new CAWebHTMLPlugin({
|
|
79
|
-
template: searchTemplate,
|
|
80
|
-
// favicon,
|
|
81
|
-
filename: 'serp.html',
|
|
82
|
-
title: 'Search Results Page',
|
|
83
|
-
templateParameters: {
|
|
84
|
-
scheme
|
|
85
|
-
},
|
|
86
|
-
}) : false,
|
|
87
|
-
|
|
88
96
|
// Additional pages from content/pages directory
|
|
89
|
-
...
|
|
97
|
+
...customPages.map( (page) => {
|
|
98
|
+
// replace .html, uppercase the first letter of each word
|
|
99
|
+
// this is to make sure the title is readable
|
|
100
|
+
// and not just a file name
|
|
101
|
+
let title = page.filename.replace('.html', '').replace(/\b\w/g, c => c.toUpperCase());
|
|
102
|
+
let content = fs.readFileSync( page.file, 'utf-8' );
|
|
103
|
+
|
|
104
|
+
let data = {
|
|
105
|
+
...caweb.site,
|
|
106
|
+
scheme
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
let compiler = Handlebars.compile( content );
|
|
110
|
+
let compiledContent = compiler(data);
|
|
111
|
+
|
|
112
|
+
return new CAWebHTMLPlugin({
|
|
113
|
+
template: page.template ?? page.file,
|
|
114
|
+
filename: page.filename,
|
|
115
|
+
title,
|
|
116
|
+
templateParameters: {
|
|
117
|
+
scheme,
|
|
118
|
+
partial: compiledContent,
|
|
119
|
+
},
|
|
120
|
+
})
|
|
121
|
+
}) ,
|
|
122
|
+
|
|
123
|
+
// Sitemap Generation
|
|
124
|
+
( ! flagExists('sitemap') || (flagExists('sitemap') && getArgVal('sitemap'))) && new SitemapWebpackPlugin.default({
|
|
125
|
+
base: caweb?.site?.url || 'http://localhost:9000',
|
|
126
|
+
paths: ['/build/', ...customPages.map( (page) => `/${page.filename}` )],
|
|
127
|
+
options: {
|
|
128
|
+
filename: 'sitemap.html',
|
|
129
|
+
skipgzip: true, // By default, both .xml and .xml.gz are generated
|
|
130
|
+
formatter: (config) => {
|
|
131
|
+
// we remove the build/ from the url since that is the output path and proxied
|
|
132
|
+
config = config.replace(/build\//g, '');
|
|
133
|
+
|
|
134
|
+
let parser = new XMLParser();
|
|
135
|
+
let xmlDoc = parser.parse(config, true);
|
|
136
|
+
|
|
137
|
+
// we map the urls to html links
|
|
138
|
+
let partial = xmlDoc.urlset.url ?
|
|
139
|
+
xmlDoc.urlset.url.map( ({loc}) => `<a href="${loc}" class="d-block">${loc}</a>` ).join('') : '';
|
|
140
|
+
|
|
141
|
+
let content = fs.readFileSync( template ).toString();
|
|
142
|
+
|
|
143
|
+
let data = {
|
|
144
|
+
...caweb.site,
|
|
145
|
+
scheme,
|
|
146
|
+
logo: '/media/logo.png',
|
|
147
|
+
partial: `<div class="container"><div class="row"><div class="col-12"><h2>Sitemap</h2>${partial}</div></div></div>`,
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
let compiler = Handlebars.compile( content );
|
|
151
|
+
let compiledContent = compiler(data);
|
|
152
|
+
|
|
153
|
+
return compiledContent;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}),
|
|
157
|
+
|
|
158
|
+
// Custom plugin to rename the sitemap file from sitemap.html.xml to sitemap.html since the sitemap-webpack-plugin does not allow us to set the extension to .html
|
|
159
|
+
( ! flagExists('sitemap') || (flagExists('sitemap') && getArgVal('sitemap'))) && {
|
|
160
|
+
apply: (compiler) => {
|
|
161
|
+
compiler.hooks.thisCompilation.tap('RenameSitemapWebpackPlugin',(compilation) => {
|
|
162
|
+
compilation.hooks.processAssets.tapAsync(
|
|
163
|
+
{
|
|
164
|
+
name: 'RenameSitemapWebpackPlugin',
|
|
165
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE ,
|
|
166
|
+
},
|
|
167
|
+
(assets, callback) => {
|
|
168
|
+
Object.keys(compilation.assets).forEach((assetName) => {
|
|
169
|
+
if (assetName.endsWith('.html.xml')) {
|
|
170
|
+
const newName = assetName.replace('.xml', '');
|
|
171
|
+
compilation.assets[newName] = compilation.assets[assetName];
|
|
172
|
+
delete compilation.assets[assetName];
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
callback();
|
|
176
|
+
}
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
},
|
|
90
182
|
|
|
91
|
-
//
|
|
92
|
-
flagExists('a11y') && getArgVal('a11y') && new CAWebA11yPlugin(),
|
|
183
|
+
// IBM Accessibility
|
|
184
|
+
( ! flagExists('a11y') || (flagExists('a11y') && getArgVal('a11y'))) && new CAWebA11yPlugin(),
|
|
93
185
|
|
|
94
|
-
//
|
|
95
|
-
flagExists('audit') && getArgVal('audit') && new CAWebCSSAuditPlugin(),
|
|
186
|
+
// WP CSS Auditor
|
|
187
|
+
( ! flagExists('audit') || (flagExists('audit') && getArgVal('audit'))) && new CAWebCSSAuditPlugin(),
|
|
96
188
|
|
|
97
|
-
//
|
|
98
|
-
flagExists('jshint') && getArgVal('jshint') && new CAWebJSHintPlugin(),
|
|
189
|
+
// JSHint
|
|
190
|
+
( ! flagExists('jshint') || (flagExists('jshint') && getArgVal('jshint'))) && new CAWebJSHintPlugin(),
|
|
99
191
|
|
|
100
192
|
].filter( Boolean ),
|
|
101
193
|
}
|
package/lib/cli.js
CHANGED
|
@@ -96,6 +96,7 @@ function addWebpackCmds(){
|
|
|
96
96
|
.option( '--no-audit', 'Skips WordPress CSS-Audit.', false )
|
|
97
97
|
.option( '--no-a11y', 'Skips IBM Accessibility Checker.', false )
|
|
98
98
|
.option( '--no-jshint', 'Skips JSHint.', false )
|
|
99
|
+
.option( '--no-sitemap', 'Skips Sitemap generation.', false )
|
|
99
100
|
.allowUnknownOption(true)
|
|
100
101
|
.allowExcessArguments(true)
|
|
101
102
|
.action(env.webpack)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@caweb/cli",
|
|
3
|
-
"version": "1.15.
|
|
3
|
+
"version": "1.15.19",
|
|
4
4
|
"description": "CAWebPublishing Command Line Interface.",
|
|
5
5
|
"exports": "./lib/env.js",
|
|
6
6
|
"type": "module",
|
|
@@ -64,11 +64,11 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@caweb/a11y-webpack-plugin": "^2.1.
|
|
68
|
-
"@caweb/css-audit-webpack-plugin": "^2.1.
|
|
69
|
-
"@caweb/html-webpack-plugin": "^2.1.
|
|
70
|
-
"@caweb/jshint-webpack-plugin": "^2.1.
|
|
71
|
-
"@caweb/webpack": "^1.6.
|
|
67
|
+
"@caweb/a11y-webpack-plugin": "^2.1.1",
|
|
68
|
+
"@caweb/css-audit-webpack-plugin": "^2.1.1",
|
|
69
|
+
"@caweb/html-webpack-plugin": "^2.1.5",
|
|
70
|
+
"@caweb/jshint-webpack-plugin": "^2.1.1",
|
|
71
|
+
"@caweb/webpack": "^1.6.6",
|
|
72
72
|
"@inquirer/prompts": "^8.2.0",
|
|
73
73
|
"@wordpress/create-block": "^4.82.0",
|
|
74
74
|
"@wordpress/env": "^10.39.0",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"crypto": "^1.0.1",
|
|
81
81
|
"deepmerge": "^4.3.1",
|
|
82
82
|
"docker-compose": "^1.3.1",
|
|
83
|
+
"fast-xml-parser": "^5.3.5",
|
|
83
84
|
"fs-extra": "^11.3.3",
|
|
84
85
|
"html-to-json-parser": "^2.0.1",
|
|
85
86
|
"inquirer-select-pro": "^1.0.0-alpha.9",
|
|
@@ -88,6 +89,7 @@
|
|
|
88
89
|
"ora": "^9.3.0",
|
|
89
90
|
"resolve-bin": "^1.0.1",
|
|
90
91
|
"rimraf": "^6.1.2",
|
|
92
|
+
"sitemap-webpack-plugin": "^1.1.1",
|
|
91
93
|
"terminal-link": "^5.0.0"
|
|
92
94
|
}
|
|
93
95
|
}
|