(tokens) add -cwd, --working-dir options to the bin

This allows to modify the working dir of the bin. This will be
particularly useful when running tests, this is not especially
intended to be vastly used by end-users.
This commit is contained in:
Nathan Vasse
2023-01-04 15:46:56 +01:00
committed by NathanVss
parent 66e6aad84d
commit 56da7dde48
2 changed files with 13 additions and 8 deletions

View File

@@ -1,3 +1,5 @@
import { program } from "commander";
export const workPath = () => { export const workPath = () => {
return process.cwd(); return program.opts().workingDir ?? process.cwd();
}; };

View File

@@ -3,8 +3,8 @@ import chalk from "chalk";
import figlet from "figlet"; import figlet from "figlet";
import { getConfig } from "ConfigLoader"; import { getConfig } from "ConfigLoader";
import { tokensGenerator } from "TokensGenerator"; import { tokensGenerator } from "TokensGenerator";
import { workPath } from "Paths";
import { Generators } from "Generators"; import { Generators } from "Generators";
import { workPath } from "Paths";
export const buildTheme = async () => { export const buildTheme = async () => {
const options = program.opts(); const options = program.opts();
@@ -17,7 +17,7 @@ export const buildTheme = async () => {
throw new Error('The generator "' + generator + '" does not exist.'); throw new Error('The generator "' + generator + '" does not exist.');
} }
return Generators[generator](tokens, { return Generators[generator](tokens, {
path: options.output, path: options.output ?? workPath(),
selector: options.selector, selector: options.selector,
}); });
}) })
@@ -35,16 +35,19 @@ export const run = async (args: string[]) => {
program program
.description("Cunningham's CLI tool.") .description("Cunningham's CLI tool.")
.option(
"-o, --output <directory>",
"Specify the output dir of generated files.",
workPath()
)
.option( .option(
"-s, --selector <selector>", "-s, --selector <selector>",
"Specify the css root selector element.", "Specify the css root selector element.",
":root" ":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."
)
.requiredOption( .requiredOption(
"-g, --generators <generators>", "-g, --generators <generators>",
"Specify the generators to use.", "Specify the generators to use.",