2022-12-01 12:03:37 +01:00
|
|
|
import { program } from "commander";
|
|
|
|
|
import chalk from "chalk";
|
|
|
|
|
import figlet from "figlet";
|
2022-12-30 12:12:04 +01:00
|
|
|
import { getConfig } from "ConfigLoader";
|
|
|
|
|
import { tokensGenerator } from "TokensGenerator";
|
2022-12-30 17:45:35 +01:00
|
|
|
import { Generators } from "Generators";
|
2023-01-04 15:46:56 +01:00
|
|
|
import { workPath } from "Paths";
|
2022-12-01 12:03:37 +01:00
|
|
|
|
|
|
|
|
export const buildTheme = async () => {
|
|
|
|
|
const options = program.opts();
|
|
|
|
|
const config = await getConfig();
|
|
|
|
|
const tokens = tokensGenerator(config);
|
2022-12-30 17:45:35 +01:00
|
|
|
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, {
|
2023-01-04 15:46:56 +01:00
|
|
|
path: options.output ?? workPath(),
|
2022-12-30 17:45:35 +01:00
|
|
|
selector: options.selector,
|
2023-02-16 17:06:33 +01:00
|
|
|
utilityClasses: options.utilityClasses,
|
2022-12-30 17:45:35 +01:00
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
);
|
2022-12-01 12:03:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const run = async (args: string[]) => {
|
|
|
|
|
console.log(
|
|
|
|
|
chalk.red(figlet.textSync("Cunningham", { horizontalLayout: "full" }))
|
|
|
|
|
);
|
|
|
|
|
|
2022-12-30 17:45:35 +01:00
|
|
|
const commaSeparatedList = (value: string) => {
|
|
|
|
|
return value.split(",");
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-01 12:03:37 +01:00
|
|
|
program
|
|
|
|
|
.description("Cunningham's CLI tool.")
|
|
|
|
|
.option(
|
|
|
|
|
"-s, --selector <selector>",
|
|
|
|
|
"Specify the css root selector element.",
|
|
|
|
|
":root"
|
|
|
|
|
)
|
2023-01-04 15:46:56 +01:00
|
|
|
.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."
|
|
|
|
|
)
|
2023-02-16 17:06:33 +01:00
|
|
|
.option("--utility-classes", "Generate CSS utility classes.")
|
2022-12-30 17:45:35 +01:00
|
|
|
.requiredOption(
|
|
|
|
|
"-g, --generators <generators>",
|
|
|
|
|
"Specify the generators to use.",
|
|
|
|
|
commaSeparatedList
|
|
|
|
|
)
|
2022-12-01 12:03:37 +01:00
|
|
|
.parse(args);
|
|
|
|
|
|
|
|
|
|
await buildTheme();
|
|
|
|
|
};
|