From 56da7dde4880ddb5fb6480226f530f2fb377e448 Mon Sep 17 00:00:00 2001 From: Nathan Vasse Date: Wed, 4 Jan 2023 15:46:56 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(tokens)=20add=20-cwd,=20--working-dir?= =?UTF-8?q?=20options=20to=20the=20bin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- packages/tokens/src/bin/Paths.ts | 4 +++- packages/tokens/src/bin/ThemeGenerator.ts | 17 ++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/tokens/src/bin/Paths.ts b/packages/tokens/src/bin/Paths.ts index c060dea..1bc52e6 100644 --- a/packages/tokens/src/bin/Paths.ts +++ b/packages/tokens/src/bin/Paths.ts @@ -1,3 +1,5 @@ +import { program } from "commander"; + export const workPath = () => { - return process.cwd(); + return program.opts().workingDir ?? process.cwd(); }; diff --git a/packages/tokens/src/bin/ThemeGenerator.ts b/packages/tokens/src/bin/ThemeGenerator.ts index 3f00757..d93cddf 100644 --- a/packages/tokens/src/bin/ThemeGenerator.ts +++ b/packages/tokens/src/bin/ThemeGenerator.ts @@ -3,8 +3,8 @@ import chalk from "chalk"; import figlet from "figlet"; import { getConfig } from "ConfigLoader"; import { tokensGenerator } from "TokensGenerator"; -import { workPath } from "Paths"; import { Generators } from "Generators"; +import { workPath } from "Paths"; export const buildTheme = async () => { const options = program.opts(); @@ -17,7 +17,7 @@ export const buildTheme = async () => { throw new Error('The generator "' + generator + '" does not exist.'); } return Generators[generator](tokens, { - path: options.output, + path: options.output ?? workPath(), selector: options.selector, }); }) @@ -35,16 +35,19 @@ export const run = async (args: string[]) => { program .description("Cunningham's CLI tool.") - .option( - "-o, --output ", - "Specify the output dir of generated files.", - workPath() - ) .option( "-s, --selector ", "Specify the css root selector element.", ":root" ) + .option( + "-cwd, --working-dir ", + "Specify the working dir ( you might not need this )." + ) + .option( + "-o, --output ", + "Specify the output dir of generated files." + ) .requiredOption( "-g, --generators ", "Specify the generators to use.",