@caweb/cli 1.4.4 → 1.5.0
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/commands/index.js +13 -19
- package/commands/webpack/webpack.js +19 -102
- package/lib/cli.js +130 -124
- package/lib/helpers.js +3 -5
- package/lib/index.js +12 -18
- package/package.json +5 -28
- package/bin/css-audit/.editorconfig +0 -12
- package/bin/css-audit/.github/workflows/build-report.yml +0 -46
- package/bin/css-audit/.github/workflows/merge-trunk-to-report.yml +0 -17
- package/bin/css-audit/.github/workflows/node.yaml +0 -32
- package/bin/css-audit/.nvmrc +0 -1
- package/bin/css-audit/README.md +0 -131
- package/bin/css-audit/css-audit.config.js +0 -13
- package/bin/css-audit/index.js +0 -38
- package/bin/css-audit/package-lock.json +0 -6689
- package/bin/css-audit/package.json +0 -56
- package/bin/css-audit/public/.gitkeep +0 -1
- package/bin/css-audit/src/__tests__/alphas.js +0 -128
- package/bin/css-audit/src/__tests__/colors.js +0 -115
- package/bin/css-audit/src/__tests__/display-none.js +0 -52
- package/bin/css-audit/src/__tests__/important.js +0 -88
- package/bin/css-audit/src/__tests__/media-queries.js +0 -84
- package/bin/css-audit/src/__tests__/property-values.js +0 -55
- package/bin/css-audit/src/__tests__/run.js +0 -25
- package/bin/css-audit/src/__tests__/selectors.js +0 -66
- package/bin/css-audit/src/audits/alphas.js +0 -70
- package/bin/css-audit/src/audits/colors.js +0 -83
- package/bin/css-audit/src/audits/display-none.js +0 -39
- package/bin/css-audit/src/audits/important.js +0 -60
- package/bin/css-audit/src/audits/media-queries.js +0 -96
- package/bin/css-audit/src/audits/property-values.js +0 -65
- package/bin/css-audit/src/audits/selectors.js +0 -67
- package/bin/css-audit/src/audits/typography.js +0 -41
- package/bin/css-audit/src/formats/cli-table.js +0 -81
- package/bin/css-audit/src/formats/html/_audit-alpha.twig +0 -23
- package/bin/css-audit/src/formats/html/_audit-colors.twig +0 -23
- package/bin/css-audit/src/formats/html/_audit-default.twig +0 -24
- package/bin/css-audit/src/formats/html/index.twig +0 -88
- package/bin/css-audit/src/formats/html/style.css +0 -341
- package/bin/css-audit/src/formats/html.js +0 -52
- package/bin/css-audit/src/formats/json.js +0 -9
- package/bin/css-audit/src/run.js +0 -76
- package/bin/css-audit/src/utils/__tests__/cli.js +0 -70
- package/bin/css-audit/src/utils/__tests__/example-config.config.js +0 -12
- package/bin/css-audit/src/utils/__tests__/get-specificity.js +0 -39
- package/bin/css-audit/src/utils/cli.js +0 -133
- package/bin/css-audit/src/utils/format-report.js +0 -37
- package/bin/css-audit/src/utils/get-specificity.js +0 -97
- package/bin/css-audit/src/utils/get-values-count.js +0 -17
- package/lib/webpack/plugins/css-audit/css-audit.config.cjs +0 -5
- package/lib/webpack/plugins/css-audit/default.config.js +0 -19
- package/lib/webpack/plugins/css-audit/index.js +0 -297
- package/lib/webpack/plugins/css-audit/package.json +0 -12
- package/lib/webpack/plugins/jshint/.jshintrc +0 -31
- package/lib/webpack/plugins/jshint/index.js +0 -286
- package/lib/webpack/plugins/jshint/package-lock.json +0 -22
- package/lib/webpack/plugins/jshint/package.json +0 -15
- package/lib/webpack/plugins/jshint/reporter.cjs +0 -663
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
const minimist = require( 'minimist' );
|
|
5
|
-
const path = require( 'path' );
|
|
6
|
-
const { cosmiconfigSync } = require( 'cosmiconfig' );
|
|
7
|
-
|
|
8
|
-
const getArgsFromCLI = ( excludePrefixes ) => {
|
|
9
|
-
const args = process.argv.slice( 2 );
|
|
10
|
-
if ( excludePrefixes ) {
|
|
11
|
-
return args.filter( ( arg ) => {
|
|
12
|
-
return ! excludePrefixes.some( ( prefix ) =>
|
|
13
|
-
arg.startsWith( prefix )
|
|
14
|
-
);
|
|
15
|
-
} );
|
|
16
|
-
}
|
|
17
|
-
return args;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getFileArgsFromCLI = () => minimist( getArgsFromCLI() )._;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get configuration using cosmiconfig.
|
|
24
|
-
*
|
|
25
|
-
* @param {string} env
|
|
26
|
-
*/
|
|
27
|
-
const getConfig = ( env ) => {
|
|
28
|
-
const moduleName = 'test' === env ? 'example-config' : 'css-audit';
|
|
29
|
-
const searchFrom =
|
|
30
|
-
'test' === env ? path.join( __dirname, '__tests__' ) : process.cwd();
|
|
31
|
-
|
|
32
|
-
const explorerSync = cosmiconfigSync( moduleName );
|
|
33
|
-
const { config } = explorerSync.search( searchFrom );
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
return config;
|
|
37
|
-
} catch ( e ) {
|
|
38
|
-
console.error( e, 'Error retrieving config file.' );
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get the argument required for running the audit,
|
|
44
|
-
*
|
|
45
|
-
* First get the argument from CLI, and fallback to the
|
|
46
|
-
* config if its not present.
|
|
47
|
-
*
|
|
48
|
-
* @param {string} arg
|
|
49
|
-
* @param {boolean} cliArgOnly
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
const getArg = ( arg, cliArgOnly = false ) => {
|
|
53
|
-
for ( const cliArg of getArgsFromCLI() ) {
|
|
54
|
-
const [ name, value ] = cliArg.split( '=' );
|
|
55
|
-
|
|
56
|
-
if ( name === arg ) {
|
|
57
|
-
return 'undefined' === typeof value ? true : value || null;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if ( true === cliArgOnly ) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const config = getConfig( process.env.NODE_ENV );
|
|
66
|
-
|
|
67
|
-
const term = arg.substr( 2 );
|
|
68
|
-
|
|
69
|
-
// This is a simple property: value arg e.g. format: json
|
|
70
|
-
const isSimplePropertyValueArg = config.hasOwnProperty( term );
|
|
71
|
-
|
|
72
|
-
if ( isSimplePropertyValueArg ) {
|
|
73
|
-
return 'undefined' === typeof config[ term ]
|
|
74
|
-
? true
|
|
75
|
-
: config[ term ] || null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if ( config.hasOwnProperty( 'audits' ) ) {
|
|
79
|
-
// Separate the basic audits from property-values.
|
|
80
|
-
const basicAudits = config.audits.filter(
|
|
81
|
-
( audit ) => term === audit && 'string' === typeof audit
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// Create an array of values of the property-value audits.
|
|
85
|
-
const propertyValueAudits = config.audits.filter(
|
|
86
|
-
( audit ) => 'object' === typeof audit && term === audit[ 0 ]
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
const propertyValueValues = ( () => {
|
|
90
|
-
if ( propertyValueAudits.length > 0 ) {
|
|
91
|
-
return propertyValueAudits
|
|
92
|
-
.flat()
|
|
93
|
-
.filter( ( item ) => 'property-values' !== item );
|
|
94
|
-
}
|
|
95
|
-
return [];
|
|
96
|
-
} )();
|
|
97
|
-
|
|
98
|
-
if ( 'undefined' !== basicAudits[ 0 ] && term === basicAudits[ 0 ] ) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if ( propertyValueValues.length > 0 ) {
|
|
103
|
-
return propertyValueValues;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// The argument cannot be retrieved from CLI or config.
|
|
108
|
-
return false;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const getHelp = () => {
|
|
112
|
-
return `Usage: css-audit -- <files...> [options]
|
|
113
|
-
|
|
114
|
-
--colors Run colors audit.
|
|
115
|
-
--important Run !important audit.
|
|
116
|
-
--display-none Run display: none audit.
|
|
117
|
-
--selectors Run selectors audit.
|
|
118
|
-
--media-queries Run media queries audit.
|
|
119
|
-
--property-values Run audit for a given set of property values, comma-separated.
|
|
120
|
-
--recommended Run recommended audits (colors, important, selectors). Default: true.
|
|
121
|
-
--all Run all audits (except property values, as it requires a value).
|
|
122
|
-
--format Format to use for displaying report.
|
|
123
|
-
--help Show this message.
|
|
124
|
-
`;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
module.exports = {
|
|
128
|
-
getArgsFromCLI,
|
|
129
|
-
getFileArgsFromCLI,
|
|
130
|
-
getArg,
|
|
131
|
-
getConfig,
|
|
132
|
-
getHelp,
|
|
133
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
const FMT_CLI_TABLE = 'cli-table';
|
|
2
|
-
const FMT_JSON = 'json';
|
|
3
|
-
const FMT_HTML = 'html';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Format the reports using the specified reporter format.
|
|
7
|
-
*
|
|
8
|
-
* @param {Array<Array<Object>>} reports The list of report data.
|
|
9
|
-
* @param {FMT_CLI_TABLE|FMT_JSON} format One of the predefined formats. Defaults to FMT_CLI_TABLE.
|
|
10
|
-
* @return {string} The formatted reports.
|
|
11
|
-
*/
|
|
12
|
-
function formatReport( reports, format = FMT_CLI_TABLE ) {
|
|
13
|
-
let formatCallback = false;
|
|
14
|
-
switch ( format ) {
|
|
15
|
-
case FMT_JSON:
|
|
16
|
-
formatCallback = require( '../formats/json' );
|
|
17
|
-
break;
|
|
18
|
-
case FMT_HTML:
|
|
19
|
-
formatCallback = require( '../formats/html' );
|
|
20
|
-
break;
|
|
21
|
-
case FMT_CLI_TABLE:
|
|
22
|
-
default:
|
|
23
|
-
formatCallback = require( '../formats/cli-table' );
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const formattedReports = formatCallback( reports );
|
|
27
|
-
if ( Array.isArray( formattedReports ) ) {
|
|
28
|
-
return formattedReports.join( '\n' );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return formattedReports;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
module.exports = {
|
|
35
|
-
formats: [ FMT_CLI_TABLE, FMT_JSON ],
|
|
36
|
-
formatReport,
|
|
37
|
-
};
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
const csstree = require( 'css-tree' );
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A recursive callback used to build up the specificity of a selector.
|
|
5
|
-
*
|
|
6
|
-
* This is intented to be used as a `reduce` callback, building up the
|
|
7
|
-
* specificity in the array accumulator as it processes each part of a selector.
|
|
8
|
-
*
|
|
9
|
-
* @param {Array<number>} specificity The specificity as an array.
|
|
10
|
-
* @param {Object} selector A selector node from the css-tree AST.
|
|
11
|
-
* @return {Array} The calculated specificity value.
|
|
12
|
-
*/
|
|
13
|
-
function calculateSpecificity( [ a, b, c ], selector ) {
|
|
14
|
-
if ( ! selector.type ) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if ( 'lang' !== selector.name && selector.children ) {
|
|
18
|
-
return selector.children
|
|
19
|
-
.toArray()
|
|
20
|
-
.reduce( calculateSpecificity, [ a, b, c ] );
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
switch ( selector.type ) {
|
|
24
|
-
case 'IdSelector':
|
|
25
|
-
a++;
|
|
26
|
-
break;
|
|
27
|
-
case 'ClassSelector':
|
|
28
|
-
case 'AttributeSelector':
|
|
29
|
-
case 'Nth':
|
|
30
|
-
b++;
|
|
31
|
-
break;
|
|
32
|
-
case 'PseudoClassSelector':
|
|
33
|
-
if ( 'not' === selector.name ) {
|
|
34
|
-
break;
|
|
35
|
-
}
|
|
36
|
-
b++;
|
|
37
|
-
break;
|
|
38
|
-
case 'TypeSelector':
|
|
39
|
-
case 'PseudoElementSelector':
|
|
40
|
-
if ( '*' === selector.name ) {
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
c++;
|
|
44
|
-
break;
|
|
45
|
-
case 'WhiteSpace':
|
|
46
|
-
case 'Combinator':
|
|
47
|
-
case 'Identifier':
|
|
48
|
-
// Whitespace, adjacent selectors (>, ~), … do not impact specificity.
|
|
49
|
-
break;
|
|
50
|
-
case 'Percentage':
|
|
51
|
-
// Part of a keyframe, not to be calculated.
|
|
52
|
-
break;
|
|
53
|
-
default:
|
|
54
|
-
console.warn( 'Unhandled selector type:', selector.type );
|
|
55
|
-
}
|
|
56
|
-
return [ a, b, c ];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Get the specificity value for a given CSS selector.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} selector A valid CSS selector.
|
|
63
|
-
* @return {number} The calculated specificity value.
|
|
64
|
-
*/
|
|
65
|
-
function getSpecificity( selector ) {
|
|
66
|
-
const node = csstree.parse( selector, { context: 'selector' } );
|
|
67
|
-
const selectorList = node.children.toArray();
|
|
68
|
-
const [ a, b, c ] = selectorList.reduce( calculateSpecificity, [
|
|
69
|
-
0,
|
|
70
|
-
0,
|
|
71
|
-
0,
|
|
72
|
-
] );
|
|
73
|
-
return 100 * a + 10 * b + c;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Get the specificity value for a given CSS selector, as an array.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} selector A valid CSS selector.
|
|
80
|
-
* @return {Array} The calculated specificity value.
|
|
81
|
-
*/
|
|
82
|
-
function getSpecificityArray( selector ) {
|
|
83
|
-
const node = csstree.parse( selector, { context: 'selector' } );
|
|
84
|
-
const selectorList = node.children.toArray();
|
|
85
|
-
const [ a, b, c ] = selectorList.reduce( calculateSpecificity, [
|
|
86
|
-
0,
|
|
87
|
-
0,
|
|
88
|
-
0,
|
|
89
|
-
] );
|
|
90
|
-
return [ a, b, c ];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
module.exports = {
|
|
94
|
-
calculateSpecificity,
|
|
95
|
-
getSpecificity,
|
|
96
|
-
getSpecificityArray,
|
|
97
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
module.exports = function ( values ) {
|
|
2
|
-
const uniqueValues = [ ...new Set( values ) ];
|
|
3
|
-
|
|
4
|
-
return uniqueValues
|
|
5
|
-
.map( ( val ) => {
|
|
6
|
-
// Count up how many times this item appears in the full list.
|
|
7
|
-
const count = values.filter( ( c ) => c === val ).length;
|
|
8
|
-
return {
|
|
9
|
-
name: val,
|
|
10
|
-
count,
|
|
11
|
-
};
|
|
12
|
-
} )
|
|
13
|
-
.sort( ( a, b ) => {
|
|
14
|
-
// Reverse sort
|
|
15
|
-
return b.count - a.count;
|
|
16
|
-
} );
|
|
17
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
format: 'html',
|
|
7
|
-
filename: 'css-audit',
|
|
8
|
-
colors: true,
|
|
9
|
-
important: true,
|
|
10
|
-
displayNone: true,
|
|
11
|
-
selectors: true,
|
|
12
|
-
mediaQueries: true,
|
|
13
|
-
typography: true,
|
|
14
|
-
propertyValues: [
|
|
15
|
-
'font-size',
|
|
16
|
-
'padding,padding-top,padding-bottom,padding-right,padding-left' ,
|
|
17
|
-
'property-values', 'margin,margin-top,marin-bottom,marin-right,marin-left',
|
|
18
|
-
]
|
|
19
|
-
};
|
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* External dependencies
|
|
5
|
-
*/
|
|
6
|
-
import { sync as resolveBin } from 'resolve-bin';
|
|
7
|
-
import spawn from 'cross-spawn';
|
|
8
|
-
import { getAllFilesSync } from 'get-all-files'
|
|
9
|
-
import EntryDependency from "webpack/lib/dependencies/EntryDependency.js";
|
|
10
|
-
|
|
11
|
-
import path from 'path';
|
|
12
|
-
import fs, { stat } from 'fs';
|
|
13
|
-
import deepmerge from 'deepmerge';
|
|
14
|
-
import chalk from 'chalk';
|
|
15
|
-
import { fileURLToPath, URL } from 'url';
|
|
16
|
-
|
|
17
|
-
// default configuration
|
|
18
|
-
import {default as DefaultConfig} from './default.config.js';
|
|
19
|
-
|
|
20
|
-
const boldWhite = chalk.bold.white;
|
|
21
|
-
const boldGreen = chalk.bold.green;
|
|
22
|
-
const boldBlue = chalk.bold.hex('#03a7fc');
|
|
23
|
-
const currentPath = path.dirname(fileURLToPath(import.meta.url));
|
|
24
|
-
|
|
25
|
-
// CSS Audit Plugin
|
|
26
|
-
class CSSAuditPlugin {
|
|
27
|
-
config = {}
|
|
28
|
-
|
|
29
|
-
constructor(opts = {}) {
|
|
30
|
-
this.config = deepmerge(DefaultConfig, opts);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
apply(compiler) {
|
|
34
|
-
const staticDir = {
|
|
35
|
-
directory: path.join(path.resolve(currentPath, '../../../../'), 'bin', 'css-audit', 'public'),
|
|
36
|
-
watch: true
|
|
37
|
-
}
|
|
38
|
-
let { devServer, output } = compiler.options;
|
|
39
|
-
let hostUrl = 'localhost' === devServer.host ? `http://${devServer.host}`: devServer.host;
|
|
40
|
-
let hostPort = devServer.port;
|
|
41
|
-
|
|
42
|
-
if( hostPort && 80 !== hostPort )
|
|
43
|
-
{
|
|
44
|
-
hostUrl = `${hostUrl}:${hostPort}`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// if dev server allows for multiple pages to be opened
|
|
48
|
-
// add css-audit.html to open property.
|
|
49
|
-
if( Array.isArray(devServer.open) ){
|
|
50
|
-
devServer.open.push(`${hostUrl}/${this.config.rewrite ? this.config.rewrite : this.config.filename}.html`)
|
|
51
|
-
}else if( 'object' === typeof devServer.open && Array.isArray(devServer.open.target) ){
|
|
52
|
-
devServer.open.target.push(`${hostUrl}/${this.config.filename}.html`)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// add our static directory
|
|
56
|
-
if( Array.isArray(devServer.static) ){
|
|
57
|
-
devServer.static.push(staticDir)
|
|
58
|
-
}else{
|
|
59
|
-
devServer.static = [].concat(devServer.static, staticDir );
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// Wait for configuration preset plugins to apply all configure webpack defaults
|
|
64
|
-
compiler.hooks.initialize.tap('CSS Audit Plugin', () => {
|
|
65
|
-
compiler.hooks.compilation.tap(
|
|
66
|
-
"CSS Audit Plugin",
|
|
67
|
-
(compilation, { normalModuleFactory }) => {
|
|
68
|
-
compilation.dependencyFactories.set(
|
|
69
|
-
EntryDependency,
|
|
70
|
-
normalModuleFactory
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const { entry, options, context } = {
|
|
76
|
-
entry: path.join(staticDir.directory, 'css-audit.update.js'),
|
|
77
|
-
options: {
|
|
78
|
-
name: 'css-audit.update'
|
|
79
|
-
},
|
|
80
|
-
context: staticDir.directory
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
const dep = new EntryDependency(entry);
|
|
84
|
-
dep.loc = {
|
|
85
|
-
name: options.name
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
fs.writeFileSync(
|
|
89
|
-
path.join(staticDir.directory, `css-audit.update.js`),
|
|
90
|
-
`` // required for hot-update to compile on our page, blank script for now
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
compiler.hooks.thisCompilation.tap('CSS Audit Plugin',
|
|
94
|
-
/**
|
|
95
|
-
* Hook into the webpack compilation
|
|
96
|
-
* @param {Compilation} compilation
|
|
97
|
-
*/
|
|
98
|
-
(compilation) => {
|
|
99
|
-
|
|
100
|
-
compiler.hooks.make.tapAsync("CSS Audit Plugin", (compilation, callback) => {
|
|
101
|
-
|
|
102
|
-
compilation.addEntry(
|
|
103
|
-
context,
|
|
104
|
-
dep,
|
|
105
|
-
options,
|
|
106
|
-
err => {
|
|
107
|
-
callback(err);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
// process assets and run the css-audit on appropriate assets.
|
|
112
|
-
compilation.hooks.processAssets.tapAsync(
|
|
113
|
-
{
|
|
114
|
-
name: 'CSS Audit Plugin',
|
|
115
|
-
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
|
|
116
|
-
},
|
|
117
|
-
/**
|
|
118
|
-
* Hook into the process assets hook
|
|
119
|
-
* @param {any} _
|
|
120
|
-
* @param {(err?: Error) => void} callback
|
|
121
|
-
*/
|
|
122
|
-
(assets, callback) => {
|
|
123
|
-
let files = [];
|
|
124
|
-
|
|
125
|
-
Object.entries(assets).forEach(([pathname, source]) => {
|
|
126
|
-
if( pathname.endsWith('.js') ){
|
|
127
|
-
if( source['_source'] && source['_source']['_children'] ){
|
|
128
|
-
source['_source']['_children'].forEach((s, i) => {
|
|
129
|
-
if(
|
|
130
|
-
'string' === typeof s && // is a string and
|
|
131
|
-
0 < s.indexOf('.css') && // has a .css reference and
|
|
132
|
-
0 > s.indexOf('node_modules') // not referencing node_modules directory
|
|
133
|
-
){
|
|
134
|
-
files.push( path.resolve(s.replace(/[\n\s\S\w]*"(.*)"[\n\s\S\w]*/, '$1')) )
|
|
135
|
-
}
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
})
|
|
140
|
-
console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running CSS Audit...')}`);
|
|
141
|
-
|
|
142
|
-
this.audit(files, this.config );
|
|
143
|
-
|
|
144
|
-
// we have to inject the css-audit.update.js file into the head in order for the webpack-dev-server scripts to load.
|
|
145
|
-
let pageContent = fs.readFileSync(path.join(staticDir.directory, `${this.config.filename}.html`))
|
|
146
|
-
|
|
147
|
-
fs.writeFileSync(
|
|
148
|
-
path.join(staticDir.directory, `${this.config.filename}.html`),
|
|
149
|
-
pageContent.toString().replace('</head>', '<script src="/css-audit.update.js"></script>\n</head>')
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
console.log(`<i> ${boldGreen('[webpack-dev-middleware] CSS Audit can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.filename}.html`).toString()) }`);
|
|
153
|
-
|
|
154
|
-
callback();
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
compiler.hooks.watchClose.tap( 'CSS Audit Plugin', () => {
|
|
159
|
-
getAllFilesSync(compiler.options.output.path).toArray().forEach(f => {
|
|
160
|
-
if(
|
|
161
|
-
f.includes('css-audit') || // delete any css-audit files
|
|
162
|
-
f.includes('.hot-update.js') // delete any HMR files
|
|
163
|
-
){
|
|
164
|
-
fs.rmSync(f)
|
|
165
|
-
}
|
|
166
|
-
})
|
|
167
|
-
})
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Run CSS Auditor
|
|
176
|
-
*
|
|
177
|
-
* @param {Array} files
|
|
178
|
-
* @param {Object} options
|
|
179
|
-
* @param {boolean} options.debug
|
|
180
|
-
* @param {boolean} options.format
|
|
181
|
-
* @param {boolean} options.filename
|
|
182
|
-
* @param {boolean} options.colors
|
|
183
|
-
* @param {boolean} options.important
|
|
184
|
-
* @param {boolean} options.displayNone
|
|
185
|
-
* @param {boolean} options.selectors
|
|
186
|
-
* @param {boolean} options.mediaQueries
|
|
187
|
-
* @param {boolean} options.typography
|
|
188
|
-
* @param {Array} options.propertyValues
|
|
189
|
-
*/
|
|
190
|
-
audit(files, {
|
|
191
|
-
debug,
|
|
192
|
-
format,
|
|
193
|
-
filename,
|
|
194
|
-
colors,
|
|
195
|
-
important,
|
|
196
|
-
displayNone,
|
|
197
|
-
selectors,
|
|
198
|
-
mediaQueries,
|
|
199
|
-
typography,
|
|
200
|
-
propertyValues
|
|
201
|
-
}){
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
let filesToBeAuditted = [];
|
|
205
|
-
let filesWithIssues = [];
|
|
206
|
-
|
|
207
|
-
files.forEach( (paths, i) => {
|
|
208
|
-
let resolvePath = path.resolve(paths);
|
|
209
|
-
|
|
210
|
-
try {
|
|
211
|
-
// if given path is a directory
|
|
212
|
-
if( fs.statSync(resolvePath).isDirectory() ){
|
|
213
|
-
|
|
214
|
-
// get all .css files
|
|
215
|
-
getAllFilesSync(resolvePath).toArray().forEach(f => {
|
|
216
|
-
if( f.endsWith('.css') ){
|
|
217
|
-
filesToBeAuditted.push(f)
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
// if given path is a file and a .css file
|
|
221
|
-
}else if( fs.statSync(paths).isFile() && paths.endsWith('.css') ){
|
|
222
|
-
filesToBeAuditted.push(paths)
|
|
223
|
-
}
|
|
224
|
-
// invalid path/file
|
|
225
|
-
} catch (error) {
|
|
226
|
-
filesWithIssues.push(paths)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
if( ! filesToBeAuditted.length ){
|
|
232
|
-
console.log('No file(s) or directory path(s) were given or default directory was not found.')
|
|
233
|
-
console.log('Auditor did not execute.');
|
|
234
|
-
return
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* the css audit uses the filename for the title, rather than the project name
|
|
239
|
-
* we fix that by passing the project name for the file name
|
|
240
|
-
* then renaming the file to the intended file name.
|
|
241
|
-
*/
|
|
242
|
-
let auditArgs = [
|
|
243
|
-
colors ? '--colors' : '',
|
|
244
|
-
important ? '--important' : '',
|
|
245
|
-
displayNone ? '--display-none' : '',
|
|
246
|
-
selectors ? '--selectors' : '',
|
|
247
|
-
mediaQueries ? '--media-queries' : '',
|
|
248
|
-
typography ? '--typography' : '',
|
|
249
|
-
format ? `--format=${format}` : '',
|
|
250
|
-
filename ? `--filename=${path.basename(process.cwd())}` : ''
|
|
251
|
-
].filter( e => e)
|
|
252
|
-
|
|
253
|
-
if( propertyValues ){
|
|
254
|
-
propertyValues.forEach((p) => {
|
|
255
|
-
auditArgs.push(`--property-values=${p.replace(' ',',')}`)
|
|
256
|
-
})
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
let { stdout, stderr } = spawn.sync(
|
|
261
|
-
'node ' + resolveBin('@caweb/cli', {executable: 'auditor'}),
|
|
262
|
-
[
|
|
263
|
-
...filesToBeAuditted,
|
|
264
|
-
...auditArgs
|
|
265
|
-
],
|
|
266
|
-
{
|
|
267
|
-
stdio: 'pipe',
|
|
268
|
-
cwd: fs.existsSync(path.join(process.cwd(), 'css-audit.config.cjs')) ? process.cwd() : currentPath
|
|
269
|
-
}
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
if( stderr && stderr.toString() ){
|
|
273
|
-
console.log( stderr.toString())
|
|
274
|
-
}
|
|
275
|
-
if( stdout ){
|
|
276
|
-
// rename the file back to the intended file name instead of the project name
|
|
277
|
-
fs.renameSync(
|
|
278
|
-
path.join(path.resolve(currentPath, '../../../../'), 'bin', 'css-audit', 'public', `${path.basename(process.cwd())}.html`),
|
|
279
|
-
path.join(path.resolve(currentPath, '../../../../'), 'bin', 'css-audit', 'public', `${filename}.html`)
|
|
280
|
-
)
|
|
281
|
-
|
|
282
|
-
let msg = stdout.toString().replace('undefined', '');
|
|
283
|
-
|
|
284
|
-
if( 'audit' === process.argv[2] ){
|
|
285
|
-
console.log( msg )
|
|
286
|
-
}else{
|
|
287
|
-
return msg;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
} // end of audit
|
|
293
|
-
|
|
294
|
-
} // end of class
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
export default CSSAuditPlugin;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@caweb/css-audit-webpack-plugin",
|
|
3
|
-
"version": "1.0.0",
|
|
4
|
-
"description": "Webpack Plugin to run WordPress CSS Audit",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "index.js",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 0"
|
|
9
|
-
},
|
|
10
|
-
"author": "Danny Guzman",
|
|
11
|
-
"license": "ISC"
|
|
12
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"boss": true,
|
|
3
|
-
"curly": true,
|
|
4
|
-
"eqeqeq": true,
|
|
5
|
-
"eqnull": true,
|
|
6
|
-
"esversion": 6,
|
|
7
|
-
"expr": true,
|
|
8
|
-
"immed": true,
|
|
9
|
-
"noarg": true,
|
|
10
|
-
"nonbsp": true,
|
|
11
|
-
"quotmark": "single",
|
|
12
|
-
"undef": true,
|
|
13
|
-
"unused": true,
|
|
14
|
-
|
|
15
|
-
"browser": true,
|
|
16
|
-
|
|
17
|
-
"globals": {
|
|
18
|
-
"_": false,
|
|
19
|
-
"Backbone": false,
|
|
20
|
-
"jQuery": false,
|
|
21
|
-
"JSON": false,
|
|
22
|
-
"wp": false,
|
|
23
|
-
"export": false,
|
|
24
|
-
"module": false,
|
|
25
|
-
"require": false,
|
|
26
|
-
"WorkerGlobalScope": false,
|
|
27
|
-
"self": false,
|
|
28
|
-
"OffscreenCanvas": false,
|
|
29
|
-
"Promise": false
|
|
30
|
-
}
|
|
31
|
-
}
|