From 15f3538fe8af72e6e705fdedc623e46a7f3c8b0e Mon Sep 17 00:00:00 2001 From: Talon Poole Date: Mon, 22 Feb 2021 00:26:56 +0000 Subject: [PATCH] show custom CSS in --help --- .editorconfig | 2 -- cli.js | 6 +++-- css.js | 64 ++++++++++++++++------------------------------- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 28 insertions(+), 48 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0a29617..4937613 100644 --- a/.editorconfig +++ b/.editorconfig @@ -6,5 +6,3 @@ indent_size = 2 indent_style = space [*.scd] indent_style = tab -[Makefile] -indent_style = tab diff --git a/cli.js b/cli.js index d4e2a41..c9d91c7 100755 --- a/cli.js +++ b/cli.js @@ -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 diff --git a/css.js b/css.js index 559bd68..0b8beca 100644 --- a/css.js +++ b/css.js @@ -79,52 +79,32 @@ export function rootVariables(rules) { function reduceVariables(rules, options) { const defaultVariables = rootVariables(rules); const CSS_VAR = /(^var\((?.+)\)|(?.+))/; + 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( diff --git a/package-lock.json b/package-lock.json index fa421f8..ffecf9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index c7b4659..f7cb0f1 100644 --- a/package.json +++ b/package.json @@ -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",