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
[*.scd]
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) => {
const opt = key.replace("--", "");
cli.option(opt, { default: CSS_VARS[key] });
@ -90,7 +92,7 @@ Object.keys(CSS_VARS).forEach((key) => {
});
cli.group(
Object.keys(CSS_VARS).map((key) => key.replace("--", "")),
"CSS:"
`${css}:`
);
const argv = cli

30
css.js
View file

@ -79,8 +79,7 @@ export function rootVariables(rules) {
function reduceVariables(rules, options) {
const defaultVariables = rootVariables(rules);
const CSS_VAR = /(^var\((?<key>.+)\)|(?<val>.+))/;
return rules
.map((rule) =>
const reduce = (rule) =>
Object.assign(
rule,
rule.declarations
@ -99,32 +98,13 @@ function reduceVariables(rules, options) {
}),
}
: {}
)
)
);
return rules
.map(reduce)
.map((rule) => {
if (!rule.media) return rule;
return Object.assign(rule, {
rules: rule.rules.map((rule) =>
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,
});
}),
}
: {}
)
),
rules: rule.rules.map(reduce),
});
})
.filter(

2
package-lock.json generated
View file

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

View file

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