Skip to content

Commit

Permalink
feat: add command theme and flag -y | --yes to skip questions
Browse files Browse the repository at this point in the history
  • Loading branch information
irsyadadl committed Dec 18, 2024
1 parent 7ccbd9d commit 649649d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 deletions.
48 changes: 28 additions & 20 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"`)}`)
Expand Down
Empty file added src/commands/theme.ts
Empty file.
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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[]
Expand Down

0 comments on commit 649649d

Please sign in to comment.