Previously, when using the cunningham bin to build tokens, the CSS file always included utility classes, resulting in duplicated CSS utility classes on the consumer side if no specific CSS optimizer is defined ( its local cunningham-tokens.css + the one from the react package ). Now, this new feature introduces a param named --utility-classes that must be provided to generate those classes. This params is henceforth only provided to the bin inside the tokens package.
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { program } from "commander";
|
|
import chalk from "chalk";
|
|
import figlet from "figlet";
|
|
import { getConfig } from "ConfigLoader";
|
|
import { tokensGenerator } from "TokensGenerator";
|
|
import { Generators } from "Generators";
|
|
import { workPath } from "Paths";
|
|
|
|
export const buildTheme = async () => {
|
|
const options = program.opts();
|
|
const config = await getConfig();
|
|
const tokens = tokensGenerator(config);
|
|
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 ?? workPath(),
|
|
selector: options.selector,
|
|
utilityClasses: options.utilityClasses,
|
|
});
|
|
})
|
|
);
|
|
};
|
|
|
|
export const run = async (args: string[]) => {
|
|
console.log(
|
|
chalk.red(figlet.textSync("Cunningham", { horizontalLayout: "full" }))
|
|
);
|
|
|
|
const commaSeparatedList = (value: string) => {
|
|
return value.split(",");
|
|
};
|
|
|
|
program
|
|
.description("Cunningham's CLI tool.")
|
|
.option(
|
|
"-s, --selector <selector>",
|
|
"Specify the css root selector element.",
|
|
":root"
|
|
)
|
|
.option(
|
|
"-cwd, --working-dir <directory>",
|
|
"Specify the working dir ( you might not need this )."
|
|
)
|
|
.option(
|
|
"-o, --output <directory>",
|
|
"Specify the output dir of generated files."
|
|
)
|
|
.option("--utility-classes", "Generate CSS utility classes.")
|
|
.requiredOption(
|
|
"-g, --generators <generators>",
|
|
"Specify the generators to use.",
|
|
commaSeparatedList
|
|
)
|
|
.parse(args);
|
|
|
|
await buildTheme();
|
|
};
|