show custom CSS in --help

This commit is contained in:
Talon Poole 2021-02-22 00:26:56 +00:00
parent 888be61458
commit 15f3538fe8
5 changed files with 28 additions and 48 deletions

View file

@ -6,5 +6,3 @@ indent_size = 2
indent_style = space indent_style = space
[*.scd] [*.scd]
indent_style = tab indent_style = tab
[Makefile]
indent_style = tab

6
cli.js
View file

@ -81,7 +81,9 @@ const cli = yargs(process.argv.slice(2))
}, },
}); });
const CSS_VARS = CSS.rootVariables(CSS.load({ css: "gmi-web.css" })); // TODO: checks for any .css arg, instead of parsing --css
const css = process.argv.find(arg => /\.css$/.test(arg)) || "gmi-web.css"
const CSS_VARS = CSS.rootVariables(CSS.load({ css }));
Object.keys(CSS_VARS).forEach((key) => { Object.keys(CSS_VARS).forEach((key) => {
const opt = key.replace("--", ""); const opt = key.replace("--", "");
cli.option(opt, { default: CSS_VARS[key] }); cli.option(opt, { default: CSS_VARS[key] });
@ -90,7 +92,7 @@ Object.keys(CSS_VARS).forEach((key) => {
}); });
cli.group( cli.group(
Object.keys(CSS_VARS).map((key) => key.replace("--", "")), Object.keys(CSS_VARS).map((key) => key.replace("--", "")),
"CSS:" `${css}:`
); );
const argv = cli const argv = cli

30
css.js
View file

@ -79,8 +79,7 @@ export function rootVariables(rules) {
function reduceVariables(rules, options) { function reduceVariables(rules, options) {
const defaultVariables = rootVariables(rules); const defaultVariables = rootVariables(rules);
const CSS_VAR = /(^var\((?<key>.+)\)|(?<val>.+))/; const CSS_VAR = /(^var\((?<key>.+)\)|(?<val>.+))/;
return rules const reduce = (rule) =>
.map((rule) =>
Object.assign( Object.assign(
rule, rule,
rule.declarations rule.declarations
@ -99,32 +98,13 @@ function reduceVariables(rules, options) {
}), }),
} }
: {} : {}
) );
) return rules
.map(reduce)
.map((rule) => { .map((rule) => {
if (!rule.media) return rule; if (!rule.media) return rule;
return Object.assign(rule, { return Object.assign(rule, {
rules: rule.rules.map((rule) => rules: rule.rules.map(reduce),
Object.assign(
rule,
rule.declarations
? {
declarations: rule.declarations.map((declaration) => {
let { key, val } = CSS_VAR.exec(declaration.value).groups;
// only one level of variable referencing is supported
key =
CSS_VAR.exec(options[key] || defaultVariables[key]).groups
.key || key;
return Object.assign(declaration, {
value: key
? options[key] || defaultVariables[key]
: declaration.value,
});
}),
}
: {}
)
),
}); });
}) })
.filter( .filter(

2
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "gmi-web-cli", "name": "gmi-web-cli",
"version": "1.0.2-rc.3", "version": "1.0.4-rc.3",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View file

@ -1,6 +1,6 @@
{ {
"name": "gmi-web-cli", "name": "gmi-web-cli",
"version": "1.0.2-rc.3", "version": "1.0.5-rc.3",
"description": "A bridge between HTML and Gemini", "description": "A bridge between HTML and Gemini",
"main": "html.js", "main": "html.js",
"type": "module", "type": "module",