@caweb/cli 1.4.2 → 1.4.4

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.
Files changed (76) hide show
  1. package/README.md +2 -180
  2. package/bin/css-audit/.editorconfig +12 -0
  3. package/bin/css-audit/.github/workflows/build-report.yml +46 -0
  4. package/bin/css-audit/.github/workflows/merge-trunk-to-report.yml +17 -0
  5. package/bin/css-audit/.github/workflows/node.yaml +32 -0
  6. package/bin/css-audit/.nvmrc +1 -0
  7. package/bin/css-audit/README.md +131 -0
  8. package/bin/css-audit/css-audit.config.js +13 -0
  9. package/bin/css-audit/index.js +38 -0
  10. package/bin/css-audit/package-lock.json +6689 -0
  11. package/bin/css-audit/package.json +56 -0
  12. package/bin/css-audit/public/.gitkeep +1 -0
  13. package/bin/css-audit/src/__tests__/alphas.js +128 -0
  14. package/bin/css-audit/src/__tests__/colors.js +115 -0
  15. package/bin/css-audit/src/__tests__/display-none.js +52 -0
  16. package/bin/css-audit/src/__tests__/important.js +88 -0
  17. package/bin/css-audit/src/__tests__/media-queries.js +84 -0
  18. package/bin/css-audit/src/__tests__/property-values.js +55 -0
  19. package/bin/css-audit/src/__tests__/run.js +25 -0
  20. package/bin/css-audit/src/__tests__/selectors.js +66 -0
  21. package/bin/css-audit/src/audits/alphas.js +70 -0
  22. package/bin/css-audit/src/audits/colors.js +83 -0
  23. package/bin/css-audit/src/audits/display-none.js +39 -0
  24. package/bin/css-audit/src/audits/important.js +60 -0
  25. package/bin/css-audit/src/audits/media-queries.js +96 -0
  26. package/bin/css-audit/src/audits/property-values.js +65 -0
  27. package/bin/css-audit/src/audits/selectors.js +67 -0
  28. package/bin/css-audit/src/audits/typography.js +41 -0
  29. package/bin/css-audit/src/formats/cli-table.js +81 -0
  30. package/bin/css-audit/src/formats/html/_audit-alpha.twig +23 -0
  31. package/bin/css-audit/src/formats/html/_audit-colors.twig +23 -0
  32. package/bin/css-audit/src/formats/html/_audit-default.twig +24 -0
  33. package/bin/css-audit/src/formats/html/index.twig +88 -0
  34. package/bin/css-audit/src/formats/html/style.css +341 -0
  35. package/bin/css-audit/src/formats/html.js +52 -0
  36. package/bin/css-audit/src/formats/json.js +9 -0
  37. package/bin/css-audit/src/run.js +76 -0
  38. package/bin/css-audit/src/utils/__tests__/cli.js +70 -0
  39. package/bin/css-audit/src/utils/__tests__/example-config.config.js +12 -0
  40. package/bin/css-audit/src/utils/__tests__/get-specificity.js +39 -0
  41. package/bin/css-audit/src/utils/cli.js +133 -0
  42. package/bin/css-audit/src/utils/format-report.js +37 -0
  43. package/bin/css-audit/src/utils/get-specificity.js +97 -0
  44. package/bin/css-audit/src/utils/get-values-count.js +17 -0
  45. package/commands/index.js +15 -5
  46. package/commands/test.js +0 -3
  47. package/commands/webpack/webpack.js +166 -0
  48. package/configs/webpack.config.js +151 -81
  49. package/lib/cli.js +71 -35
  50. package/lib/helpers.js +3 -1
  51. package/lib/webpack/plugins/a11y/aceconfig.js +44 -0
  52. package/lib/webpack/plugins/a11y/index.js +272 -0
  53. package/lib/webpack/plugins/a11y/package.json +12 -0
  54. package/lib/webpack/plugins/css-audit/css-audit.config.cjs +5 -0
  55. package/lib/webpack/plugins/css-audit/default.config.js +19 -0
  56. package/lib/webpack/plugins/css-audit/index.js +297 -0
  57. package/lib/webpack/plugins/css-audit/package.json +12 -0
  58. package/lib/webpack/plugins/jshint/.jshintrc +31 -0
  59. package/lib/webpack/plugins/jshint/index.js +286 -0
  60. package/lib/webpack/plugins/jshint/package-lock.json +22 -0
  61. package/lib/webpack/plugins/jshint/package.json +15 -0
  62. package/lib/webpack/plugins/jshint/reporter.cjs +663 -0
  63. package/package.json +18 -12
  64. package/assets/logo.ico +0 -0
  65. package/commands/a11y.js +0 -95
  66. package/commands/build.js +0 -80
  67. package/commands/serve.js +0 -95
  68. package/configs/aceconfig.js +0 -28
  69. package/docs/CREDITS.MD +0 -27
  70. package/docs/ISSUES.MD +0 -7
  71. package/docs/OVERRIDES.md +0 -53
  72. package/docs/ROADMAP.MD +0 -19
  73. package/docs/SYNC.MD +0 -29
  74. package/docs/tool/index.js +0 -45
  75. package/gen/parser.js +0 -166
  76. package/gen/site-generator.js +0 -144
@@ -0,0 +1,286 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+ import spawn from 'cross-spawn';
7
+ import { getAllFilesSync } from 'get-all-files'
8
+ import EntryDependency from "webpack/lib/dependencies/EntryDependency.js";
9
+ import path from 'path';
10
+ import fs from 'fs';
11
+ import deepmerge from 'deepmerge';
12
+ import chalk from 'chalk';
13
+ import { fileURLToPath, URL } from 'url';
14
+
15
+ const boldWhite = chalk.bold.white;
16
+ const boldGreen = chalk.bold.green;
17
+ const boldBlue = chalk.bold.hex('#03a7fc');
18
+ const currentPath = path.dirname(fileURLToPath(import.meta.url));
19
+
20
+ // JSHint Plugin
21
+ class JSHintPlugin {
22
+ config = {
23
+ outputFilename: 'jshint',
24
+ outputFolder: path.join(currentPath, 'public'),
25
+ }
26
+
27
+ constructor(opts = {}) {
28
+ // outputFolder must be resolved
29
+ if( opts.outputFolder ){
30
+ opts.outputFolder = path.join(process.cwd(), opts.outputFolder);
31
+ }
32
+ this.config = deepmerge(this.config, opts);
33
+ }
34
+
35
+ apply(compiler) {
36
+ const staticDir = {
37
+ directory: this.config.outputFolder,
38
+ watch: true
39
+ }
40
+ let { devServer } = compiler.options;
41
+ let hostUrl = 'localhost' === devServer.host ? `http://${devServer.host}`: devServer.host;
42
+ let hostPort = devServer.port;
43
+
44
+ if( hostPort && 80 !== hostPort )
45
+ {
46
+ hostUrl = `${hostUrl}:${hostPort}`;
47
+ }
48
+
49
+ // if dev server allows for multiple pages to be opened
50
+ // add jshint.html to open property.
51
+ if( Array.isArray(devServer.open) ){
52
+ devServer.open.push(`${hostUrl}/${this.config.outputFilename}.html`)
53
+ }else if( 'object' === typeof devServer.open && Array.isArray(devServer.open.target) ){
54
+ devServer.open.target.push(`${hostUrl}/${this.config.outputFilename}.html`)
55
+ }
56
+
57
+ // add our static directory
58
+ if( Array.isArray(devServer.static) ){
59
+ devServer.static.push(staticDir)
60
+ }else{
61
+ devServer.static = [].concat(devServer.static, staticDir );
62
+ }
63
+
64
+ // Wait for configuration preset plugins to apply all configure webpack defaults
65
+ compiler.hooks.initialize.tap('JSHint Plugin', () => {
66
+ compiler.hooks.compilation.tap(
67
+ "JSHint Plugin",
68
+ (compilation, { normalModuleFactory }) => {
69
+ compilation.dependencyFactories.set(
70
+ EntryDependency,
71
+ normalModuleFactory
72
+ );
73
+ }
74
+ );
75
+
76
+ const { entry, options, context } = {
77
+ entry: path.join( this.config.outputFolder, 'jshint.update.js'),
78
+ options: {
79
+ name: 'jshint'
80
+ },
81
+ context: 'jshint'
82
+ };
83
+
84
+ const dep = new EntryDependency(entry);
85
+ dep.loc = {
86
+ name: options.name
87
+ };
88
+
89
+ if( ! fs.existsSync(path.resolve(this.config.outputFolder))){
90
+ fs.mkdirSync( path.resolve(this.config.outputFolder), {recursive: true} );
91
+ }
92
+
93
+ fs.writeFileSync(
94
+ path.join(this.config.outputFolder, `jshint.update.js`),
95
+ `` // required for hot-update to compile on our page, blank script for now
96
+ );
97
+
98
+
99
+ compiler.hooks.thisCompilation.tap('JSHint Plugin',
100
+ /**
101
+ * Hook into the webpack compilation
102
+ * @param {Compilation} compilation
103
+ */
104
+ (compilation) => {
105
+
106
+ compiler.hooks.make.tapAsync("JSHint Plugin", (compilation, callback) => {
107
+
108
+ compilation.addEntry(
109
+ context,
110
+ dep,
111
+ options,
112
+ err => {
113
+ callback(err);
114
+ });
115
+ });
116
+
117
+ // process assets and run the jshint on appropriate assets.
118
+ compilation.hooks.processAssets.tapAsync(
119
+ {
120
+ name: 'JSHint Plugin',
121
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL
122
+ },
123
+ /**
124
+ * Hook into the process assets hook
125
+ * @param {any} _
126
+ * @param {(err?: Error) => void} callback
127
+ */
128
+ (assets, callback) => {
129
+ let files = [];
130
+
131
+ Object.entries(assets).forEach(([pathname, source]) => {
132
+ if( pathname.endsWith('.js') ){
133
+ if( source['_source'] && source['_source']['_children'] ){
134
+ source['_source']['_children'].forEach((s, i) => {
135
+ if(
136
+ 'string' === typeof s && // is a string and
137
+ 0 < s.indexOf('.js') && // has a .js reference and
138
+ 0 > s.indexOf('node_modules') && // not referencing node_modules directory
139
+ 0 > s.indexOf('jshint.update.js') // not referencing our update javascript
140
+ ){
141
+ files.push( path.resolve(s.replace(/[\n\s\S\w]*"(.*)"[\n\s\S\w]*/, '$1')) )
142
+ }
143
+ })
144
+ }
145
+ }
146
+ })
147
+
148
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] Running JSHint...')}`);
149
+
150
+ this.hint(files, this.config);
151
+
152
+ console.log(`<i> ${boldGreen('[webpack-dev-middleware] JSHint can be viewed at')} ${ boldBlue(new URL(`${hostUrl}/${this.config.outputFilename}.html`).toString()) }`);
153
+
154
+ callback();
155
+ });
156
+
157
+
158
+ compiler.hooks.watchClose.tap( 'JSHint Plugin', () => {
159
+ getAllFilesSync(compiler.options.output.path).toArray().forEach(f => {
160
+ if(
161
+ f.includes('jshint') || // delete any jshint 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 JSHint
176
+ *
177
+ * @param {Array} files
178
+ * @param {Object} options
179
+ * @param {boolean} options.debug
180
+ * @param {boolean} options.outputFilename Filename for the scan results.
181
+ * @param {boolean} options.outputFolder Where the scan results should be saved.
182
+ */
183
+ hint(files, {
184
+ debug,
185
+ outputFolder,
186
+ outputFilename
187
+ }){
188
+
189
+ let filesToBeAuditted = [];
190
+ let filesWithIssues = [];
191
+
192
+ files.forEach( (paths, i) => {
193
+ let resolvePath = path.resolve(paths);
194
+
195
+ try {
196
+ // if given path is a directory
197
+ if( fs.statSync(resolvePath).isDirectory() ){
198
+
199
+ // get all .js files
200
+ getAllFilesSync(resolvePath).toArray().forEach(f => {
201
+ if( f.endsWith('.js') ){
202
+ filesToBeAuditted.push(f)
203
+ }
204
+ })
205
+ // if given path is a file and a .js file
206
+ }else if( fs.statSync(paths).isFile() && paths.endsWith('.js') ){
207
+ filesToBeAuditted.push(paths)
208
+ }
209
+ // invalid path/file
210
+ } catch (error) {
211
+ filesWithIssues.push(paths)
212
+ }
213
+
214
+ });
215
+
216
+ if( ! filesToBeAuditted.length ){
217
+ console.log('No file(s) or directory path(s) were given or default directory was not found.')
218
+ console.log('Hinter did not execute.');
219
+ return
220
+ }
221
+
222
+ let hintConfigFile = path.join(currentPath, '.jshintrc');
223
+
224
+ /**
225
+ * JSHint does not allow for multiple configs so we have to merge and write 1 file
226
+ */
227
+ if( fs.existsSync(path.join(process.cwd(), '.jshintrc')) ){
228
+ let hintConfig = fs.readFileSync(hintConfigFile);
229
+ let customConfig = fs.readFileSync(path.join(process.cwd(), '.jshintrc'));
230
+
231
+ hintConfig = hintConfig.toString().replace(/[\r\t\n]|\/{2}.*/g, '')
232
+ hintConfig = JSON.parse(hintConfig)
233
+
234
+ customConfig = customConfig.toString().replace(/[\r\t\n]|\/{2}.*/g, '')
235
+ customConfig = JSON.parse(customConfig)
236
+
237
+ hintConfigFile = path.join(currentPath, '.customrc');
238
+ fs.writeFileSync(
239
+ hintConfigFile ,
240
+ JSON.stringify(deepmerge(hintConfig, customConfig), null, 4)
241
+ )
242
+ }
243
+
244
+ // Set the env for our reporter.
245
+ process.env.JSHINT_OUTPUT_DIR = outputFolder;
246
+ process.env.JSHINT_OUTPUT_FILENAME = outputFilename;
247
+
248
+ let hintArgs = [
249
+ '--config',
250
+ hintConfigFile,
251
+ '--reporter',
252
+ path.join(currentPath, 'reporter.cjs')
253
+ ].filter( e => e)
254
+
255
+ let { stdout, stderr } = spawn.sync(
256
+ 'jshint',
257
+ [
258
+ ...filesToBeAuditted,
259
+ ...hintArgs
260
+ ],
261
+ {
262
+ stdio: 'pipe',
263
+ }
264
+ )
265
+
266
+ if( stderr && stderr.toString() ){
267
+ console.log( stderr.toString())
268
+ }
269
+
270
+ if( stdout ){
271
+ if( 'jshint' === process.argv[2] && debug ){
272
+ console.log( stdout.toString() );
273
+ }else{
274
+ return stdout.toString();
275
+ }
276
+ }else{
277
+ console.log( 'No output generated.')
278
+ return false;
279
+ }
280
+
281
+ } // end of hint
282
+
283
+ } // end of class
284
+
285
+
286
+ export default JSHintPlugin;
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@caweb/jshint-webpack-plugin",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@caweb/jshint-webpack-plugin",
9
+ "version": "1.0.0",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "html-format": "^1.1.7"
13
+ }
14
+ },
15
+ "node_modules/html-format": {
16
+ "version": "1.1.7",
17
+ "resolved": "https://registry.npmjs.org/html-format/-/html-format-1.1.7.tgz",
18
+ "integrity": "sha512-ba6woq8dni6HkfRFpsu27PrCM/sxEz9KrVW22xVyMbXsZHbSpJE6Z1gAl7OeqEfU92MKYb9Pn7MnIyqV5tJHKA==",
19
+ "license": "MIT"
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@caweb/jshint-webpack-plugin",
3
+ "version": "1.0.0",
4
+ "description": "Webpack Plugin to run JSHint",
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
+ "dependencies": {
13
+ "html-format": "^1.1.7"
14
+ }
15
+ }