(tokens) add JS generator and re-organize the repo

Added JsGenerator which to implied to reorganize a bit the
repo in order to extract generator-specific test into specific
standalone files.
This commit is contained in:
Nathan Vasse
2022-12-30 17:45:35 +01:00
committed by NathanVss
parent 3e98429d04
commit 2876d29025
12 changed files with 188 additions and 70 deletions

View File

@@ -1,19 +1,27 @@
import { program } from "commander";
import chalk from "chalk";
import figlet from "figlet";
import { cssGenerator } from "Generators/CssGenerator";
import { getConfig } from "ConfigLoader";
import { tokensGenerator } from "TokensGenerator";
import { workPath } from "Paths";
import { Generators } from "Generators";
export const buildTheme = async () => {
const options = program.opts();
const config = await getConfig();
const tokens = tokensGenerator(config);
await cssGenerator(tokens, {
path: options.output,
selector: options.selector,
});
const { generators } = options;
await Promise.allSettled(
generators.map((generator: string) => {
if (!Generators[generator]) {
throw new Error('The generator "' + generator + '" does not exist.');
}
return Generators[generator](tokens, {
path: options.output,
selector: options.selector,
});
})
);
};
export const run = async (args: string[]) => {
@@ -21,6 +29,10 @@ export const run = async (args: string[]) => {
chalk.red(figlet.textSync("Cunningham", { horizontalLayout: "full" }))
);
const commaSeparatedList = (value: string) => {
return value.split(",");
};
program
.description("Cunningham's CLI tool.")
.option(
@@ -33,6 +45,11 @@ export const run = async (args: string[]) => {
"Specify the css root selector element.",
":root"
)
.requiredOption(
"-g, --generators <generators>",
"Specify the generators to use.",
commaSeparatedList
)
.parse(args);
await buildTheme();