show custom CSS in --help

feature/server
Talon Poole 2 years ago
parent 888be61458
commit 15f3538fe8
  1. 2
      .editorconfig
  2. 6
      cli.js
  3. 64
      css.js
  4. 2
      package-lock.json
  5. 2
      package.json

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

@ -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

@ -79,52 +79,32 @@ export function rootVariables(rules) {
function reduceVariables(rules, options) {
const defaultVariables = rootVariables(rules);
const CSS_VAR = /(^var\((?<key>.+)\)|(?<val>.+))/;
const reduce = (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,
});
}),
}
: {}
);
return 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,
});
}),
}
: {}
)
)
.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

@ -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": {

@ -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",

Loading…
Cancel
Save