show custom CSS in --help
This commit is contained in:
parent
888be61458
commit
15f3538fe8
|
@ -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
6
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) => {
|
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
|
||||||
|
|
64
css.js
64
css.js
|
@ -79,52 +79,32 @@ 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>.+))/;
|
||||||
|
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
|
return rules
|
||||||
.map((rule) =>
|
.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,
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
: {}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.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
2
package-lock.json
generated
|
@ -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": {
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in a new issue