-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-report.js
More file actions
executable file
·113 lines (89 loc) · 3.75 KB
/
Copy pathgenerate-report.js
File metadata and controls
executable file
·113 lines (89 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env node
/**
* Run this to parse acss-live.js, which will look for the config data.
* After loading the config, this generates the CSS report to standard
* out and also checks for errors.
*/
"use strict";
const fsPromises = require('fs').promises;
function sortDeepValue(a, b) {
return a[1][0].localeCompare(b[1][0]);
}
function sortShallowValue(a, b) {
return a[1].localeCompare(b[1]);
}
fsPromises.readFile('./acss-live.js').then((data) => data.toString()).then((data) => {
data = data.split('var config = ')[1];
data = data.split(';\n')[0];
let config;
// eslint-disable-next-line no-eval
eval(`config = ${data}`);
console.log("Supported CSS");
console.log("=============");
console.log("");
console.log("This is a list of all supported CSS in the current version of the library.");
console.log("");
console.log("Global Default Values");
console.log("---------------------");
console.log("");
console.log("These can be used for any CSS rule.");
console.log("");
for (const [k, v] of Object.entries(config.values).sort(sortShallowValue)) {
console.log("* `" + k + "` → `" + v + "`");
}
console.log("");
console.log("");
console.log("CSS Classes");
console.log("-----------");
console.log("");
for (const [shortcut, def] of Object.entries(config.classes).sort(sortDeepValue)) {
const cssRules = def.shift().split(';').map((x) => x.indexOf(':') < 0 ? `${x}:$_` : x);
console.log("* `" + shortcut + "(…)` → `" + cssRules.join(";") + "`");
const allowed = new Map();
for (const lookup of def) {
let lookupActual = lookup;
if (typeof lookupActual === "string") {
lookupActual = config[lookupActual];
}
if (!lookup) {
console.error(`Invalid lookup value found for "${shortcut}", was trying to find "${lookup}"`);
throw new Error("Abort - problem with config");
}
for (const [lookupKey, lookupValue] of Object.entries(config[lookup] || lookup)) {
if (config.values[lookupKey]) {
console.error(`Conflict - "${shortcut}" has a value "${lookupKey}" that conflicts with a global value`);
throw new Error("Abort - conflict with global default value");
}
if (allowed.has(lookupKey) && allowed.get(lookupKey) !== lookupValue) {
console.error(`Conflict - "${shortcut}" has conflicting values for shortcut "${lookupKey}": ${allowed.get(lookupKey)} and ${lookupValue}`);
throw new Error("Abort - conflict with config");
}
allowed.set(lookupKey, lookupValue);
}
}
for (const [allowedKey, allowedValue] of Array.from(allowed).sort(sortShallowValue)) {
console.log(" * `" + allowedKey + "` → `" + allowedValue + "`");
}
}
console.log("");
console.log("Pseudo Classes");
console.log("--------------");
console.log("");
for (const [k, v] of Object.entries(config.pseudoClasses).sort(sortShallowValue)) {
console.log("* `:" + k + "` → `:" + v + "`");
}
console.log("");
console.log("Pseudo Elements");
console.log("---------------");
console.log("");
for (const [k, v] of Object.entries(config.pseudoElements).sort(sortShallowValue)) {
console.log("* `::" + k + "` → `::" + v + "`");
}
console.log("");
console.log("At Rules (Media Queries)");
console.log("------------------------");
console.log("");
for (const [k, v] of Object.entries(config.atRules).sort(sortShallowValue)) {
console.log("* `--" + k + "` → `" + v + " { ... }`");
}
});