diff --git a/src/commands/init.ts b/src/commands/init.ts index 66e1ebc..0eb214d 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -20,7 +20,7 @@ const __dirname = path.dirname(__filename) const stubs = path.resolve(__dirname, "../src/resources/stubs") -export async function init(flags: { force?: boolean }) { +export async function init(flags: { force?: boolean; yes?: boolean }) { if (!flags.force) { const checkingGit = ora(`Checking.`).start() if (isRepoDirty()) { @@ -48,25 +48,33 @@ export async function init(flags: { force?: boolean }) { let componentFolder: string, uiFolder: string, cssLocation: string, themeProvider: string, providers: string, utilsFolder: string spinner.succeed("Initializing.") - componentFolder = await input({ - message: "Components folder:", - default: possibilityComponentsPath(), - validate: (value) => value.trim() !== "" || "Path cannot be empty. Please enter a valid path.", - }) - uiFolder = path.join(componentFolder, "ui") + if (flags.yes) { + componentFolder = possibilityComponentsPath() + uiFolder = path.join(componentFolder, "ui") + utilsFolder = possibilityUtilsPath() + cssLocation = possibilityCssPath() + } else { + componentFolder = await input({ + message: "Components folder:", + default: possibilityComponentsPath(), + validate: (value) => value.trim() !== "" || "Path cannot be empty. Please enter a valid path.", + }) - utilsFolder = await input({ - message: "Utils folder:", - default: possibilityUtilsPath(), - validate: (value) => value.trim() !== "" || "Path cannot be empty. Please enter a valid path.", - }) + uiFolder = path.join(componentFolder, "ui") - cssLocation = await input({ - message: "Where would you like to place the CSS file?", - default: possibilityCssPath(), - validate: (value) => value.trim() !== "" || "Path cannot be empty. Please enter a valid path.", - }) + utilsFolder = await input({ + message: "Utils folder:", + default: possibilityUtilsPath(), + validate: (value) => value.trim() !== "" || "Path cannot be empty. Please enter a valid path.", + }) + + cssLocation = await input({ + message: "Where would you like to place the CSS file?", + default: possibilityCssPath(), + validate: (value) => value.trim() !== "" || "Path cannot be empty. Please enter a valid path.", + }) + } if (isNextJs() && hasFolder("src")) { themeProvider = path.join(stubs, "next/theme-provider.stub") @@ -230,9 +238,9 @@ export async function init(flags: { force?: boolean }) { if (!fs.existsSync(uiFolder)) { fs.mkdirSync(uiFolder, { recursive: true }) } - spinner.succeed(`UI folder created at ${highlight(`"${uiFolder}"`)}`) - spinner.succeed(`Primitive file saved to ${highlight(`"${uiFolder}/primitive.tsx"`)}`) - spinner.succeed(`Classes file saved to ${highlight(`"${utilsFolder}/classes.ts"`)}`) + spinner.succeed(`UI folder created at ${highlight(`${uiFolder}`)}`) + spinner.succeed(`Primitive file saved to ${highlight(`${uiFolder}/primitive.tsx`)}`) + spinner.succeed(`Classes file saved to ${highlight(`${utilsFolder}/classes.ts`)}`) if (themeProvider) { spinner.succeed(`Theme Provider file saved to ${highlight(`"${componentFolder}/theme-provider.tsx"`)}`) spinner.succeed(`Providers file saved to ${highlight(`"${componentFolder}/providers.tsx"`)}`) diff --git a/src/commands/theme.ts b/src/commands/theme.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/index.ts b/src/index.ts index 5072f86..84bbdb0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,6 +7,7 @@ import { diff } from "./commands/diff" import { help } from "./commands/help" import { setGray } from "./commands/change-gray" import packageJson from "../package.json" +import open from "open" const version = packageJson.version @@ -31,7 +32,7 @@ program.version(version, "-v, --version", "Output the version number").descripti * This command is used to initialize your project, it will assume you have installed tailwindcss, and your main framework or library. * @param force boolean */ -program.command("init").option("--force", "Force initialization without checking Git").action(init) +program.command("init").option("--force", "Force initialization without checking Git").option("-y, --yes", "Skip prompts and use default values").action(init) /** * This command is used to add new components to your project @@ -62,6 +63,13 @@ program await setGray(options.yes, grayName) }) +program + .command("theme") + .description("Open theme customization page") + .action(async () => { + await open("https://getjustd.com/themes") + }) + /** * This command will show differences between local and remote components (justd repo) * @param components string[]