Skip to content

Commit b33ced5

Browse files
committed
fix: some bugs
1 parent b0fc458 commit b33ced5

File tree

9 files changed

+109
-77
lines changed

9 files changed

+109
-77
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@
77
"bin": {
88
"intentui": "dist/index.js"
99
},
10-
"files": [
11-
"dist",
12-
"src/resources",
13-
"LICENSE",
14-
"README.md",
15-
"package.json"
16-
],
10+
"files": ["dist", "src/resources", "LICENSE", "README.md", "package.json"],
1711
"repository": {
1812
"type": "git",
1913
"url": "git+https://github.com/intentuilabs/cli.git"
@@ -25,19 +19,14 @@
2519
"prepare": "npx husky",
2620
"build": "bun build ./src/index.ts --outdir ./dist --target=node --minify",
2721
"format": "biome lint --fix && biome check --write",
28-
"test": "bun run build && bun link",
29-
"preview": "bun run clean && bun run build && bun link",
30-
"pr": "bun run build && git commit -a",
22+
"test": "NODE_ENV=production bun run build && bun link",
23+
"preview": "cross-env NODE_ENV=production bun run clean && bun run build && bun link",
24+
"pr": "cross-env NODE_ENV=production bun run build && git commit -a",
3125
"pre": "chmod a+x dist/index.js",
3226
"release": "export GITHUB_TOKEN=$(cat .github_token) && release-it",
3327
"typecheck": "tsc --noEmit"
3428
},
35-
"keywords": [
36-
"cli",
37-
"intentui cli",
38-
"Intent UI",
39-
"design-system"
40-
],
29+
"keywords": ["cli", "intentui cli", "Intent UI", "design-system"],
4130
"author": "Irsyad A. Panjaitan",
4231
"license": "MIT",
4332
"devDependencies": {
@@ -52,6 +41,7 @@
5241
"@types/fs-extra": "^11.0.4",
5342
"@types/inquirer": "^9.0.7",
5443
"@types/node": "^22.10.7",
44+
"cross-env": "^7.0.3",
5545
"husky": "^9.1.7",
5646
"release-it": "^18.1.1",
5747
"rimraf": "^6.0.1",

src/commands/add.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { additionalDeps } from "@/utils/additional-deps"
55
import { type Config, configManager, getWriteComponentPath } from "@/utils/config"
66
import { getPackageManager } from "@/utils/get-package-manager"
77
import { error, grayText, highlight, warn, warningText } from "@/utils/logging"
8-
import { getRepoUrlForComponent, getUtilsFolder } from "@/utils/repo"
8+
import { getHooksFolder, getRepoUrlForComponent } from "@/utils/repo"
99
import { checkbox } from "@inquirer/prompts"
1010
import chalk from "chalk"
1111
import ora from "ora"
@@ -132,12 +132,12 @@ export async function add(options: {
132132
)
133133
) {
134134
const mediaQueryFile = path.join(
135-
config.utils,
135+
config.hooks,
136136
`use-media-query.${config.language === "javascript" ? "js" : "ts"}`,
137137
)
138138

139139
if (!fs.existsSync(mediaQueryFile)) {
140-
const responseMediaQuery = await fetch(getUtilsFolder("use-media-query.ts"))
140+
const responseMediaQuery = await fetch(getHooksFolder("use-media-query.ts"))
141141
const fileContentMediaQuery = await responseMediaQuery.text()
142142

143143
await writeCodeFile(config, {

src/commands/init.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import {
2222
isTypescriptProject,
2323
possibilityComponentsPath,
2424
possibilityCssPath,
25-
possibilityUtilsPath,
25+
possibilityHookPath,
26+
possibilityLibPath,
2627
} from "@/utils/helpers"
2728
import { error, grayText, highlight, info } from "@/utils/logging"
2829
import { getPrimitiveComponentUrl } from "@/utils/repo"
@@ -108,16 +109,18 @@ export async function init(flags: {
108109
let componentFolder: string
109110
let twConfigStub: string
110111
let uiFolder: string
112+
let libFolder: string
113+
let hookFolder: string
111114
let cssLocation: string
112115
let themeProvider: string
113116
let providers: string
114-
let utilsFolder: string
115117
spinner.succeed("Initializing.")
116118

117119
if (flags.yes) {
118120
componentFolder = possibilityComponentsPath()
119121
uiFolder = path.join(componentFolder, "ui")
120-
utilsFolder = possibilityUtilsPath()
122+
libFolder = possibilityLibPath()
123+
hookFolder = possibilityHookPath()
121124
cssLocation = possibilityCssPath()
122125
} else {
123126
componentFolder = await input({
@@ -129,9 +132,16 @@ export async function init(flags: {
129132

130133
uiFolder = path.join(componentFolder, "ui")
131134

132-
utilsFolder = await input({
133-
message: "Utils folder:",
134-
default: possibilityUtilsPath(),
135+
libFolder = await input({
136+
message: "Lib folder:",
137+
default: possibilityLibPath(),
138+
validate: (value) =>
139+
value.trim() !== "" || "Path cannot be empty. Please enter a valid path.",
140+
})
141+
142+
hookFolder = await input({
143+
message: "Hooks folder:",
144+
default: possibilityHookPath(),
135145
validate: (value) =>
136146
value.trim() !== "" || "Path cannot be empty. Please enter a valid path.",
137147
})
@@ -180,8 +190,12 @@ export async function init(flags: {
180190
}
181191
}
182192

183-
if (!fs.existsSync(utilsFolder)) {
184-
fs.mkdirSync(utilsFolder, { recursive: true })
193+
if (!fs.existsSync(libFolder)) {
194+
fs.mkdirSync(libFolder, { recursive: true })
195+
}
196+
197+
if (!fs.existsSync(hookFolder)) {
198+
fs.mkdirSync(hookFolder, { recursive: true })
185199
}
186200

187201
if (!fs.existsSync(uiFolder)) {
@@ -252,12 +266,14 @@ export async function init(flags: {
252266
const content = fs.readFileSync(path.join(stubs, "1.x/zinc.css"), "utf8")
253267
writeFileSync(cssLocation, content, { flag: "w" })
254268
}
269+
255270
const selectedGray = isTailwind(3) ? "zinc.css" : await changeGray(cssLocation, flags)
256271

257272
const config: ConfigInput = {
258273
ui: uiFolder,
259-
utils: utilsFolder,
260-
gray: selectedGray?.replace(".css", "")!,
274+
lib: libFolder,
275+
hooks: hookFolder,
276+
gray: selectedGray?.replace(".css", "") ?? "zinc",
261277
css: cssLocation,
262278
alias: currentAlias || undefined,
263279
language,
@@ -290,12 +306,10 @@ export async function init(flags: {
290306
const action = packageManager === "npm" ? "i" : "add"
291307
const installCommand = `${packageManager} ${action} ${mainPackages} && ${packageManager} ${action} -D ${devPackages} --silent`
292308
spinner.start("Installing dependencies.")
293-
294309
const child = spawn(installCommand, {
295310
stdio: ["ignore", "ignore", "ignore"],
296311
shell: true,
297312
})
298-
299313
await new Promise<void>((resolve) => {
300314
child.on("close", () => {
301315
resolve()
@@ -308,10 +322,9 @@ export async function init(flags: {
308322
if (!response.ok) throw new Error(`Failed to fetch component: ${response.statusText}`)
309323

310324
const fileContent = await response.text()
311-
312325
await writeCodeFile(createdConfig, {
313-
writePath: path.join(uiFolder, "primitive.tsx"),
314-
ogFilename: "primitive.tsx",
326+
writePath: path.join(libFolder, "primitive.ts"),
327+
ogFilename: "primitive.ts",
315328
content: fileContent,
316329
})
317330

@@ -344,20 +357,20 @@ export async function init(flags: {
344357
if (!fs.existsSync(uiFolder)) {
345358
fs.mkdirSync(uiFolder, { recursive: true })
346359
}
347-
spinner.succeed(`UI folder created at ${highlight(`${uiFolder}`)}`)
360+
spinner.succeed(`UI folder created at ${highlight(uiFolder)}`)
348361
spinner.succeed(
349-
`Primitive file saved to ${highlight(`${uiFolder}/${getCorrectFileExtension(language, "primitive.tsx")}`)}`,
362+
`Primitive file saved to ${highlight(`${libFolder}/${getCorrectFileExtension(language, "primitive.ts")}`)}`,
350363
)
351364
if (themeProvider) {
352365
spinner.succeed(
353-
`Theme Provider file saved to ${highlight(`"${componentFolder}/${getCorrectFileExtension(language, "theme-provider.ts")}"`)}`,
366+
`Theme Provider file saved to ${highlight(`${componentFolder}/${getCorrectFileExtension(language, "theme-provider.ts")}`)}`,
354367
)
355368
spinner.succeed(
356-
`Providers file saved to ${highlight(`"${componentFolder}/${getCorrectFileExtension(language, "providers.tsx")}"`)}`,
369+
`Providers file saved to ${highlight(`${componentFolder}/${getCorrectFileExtension(language, "providers.tsx")}`)}`,
357370
)
358371
}
359372

360-
spinner.start(`Configuration saved to ${highlight(`"intentui.json"`)}`)
373+
spinner.start(`Configuration saved to ${highlight("intentui.json")}`)
361374
await new Promise((resolve) => setTimeout(resolve, 500))
362375
spinner.succeed(`Configuration saved to ${highlight("intentui.json")}`)
363376
spinner.succeed("Installation complete.")

src/commands/start-new-project/index.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "node:fs"
2-
import process from "node:process"
2+
import processer from "node:process"
33
import {
44
checkIfCommandExists,
55
checkIfDirectoryExists,
@@ -18,8 +18,6 @@ import { error, grayText, highlight } from "@/utils/logging"
1818
import { input, select } from "@inquirer/prompts"
1919
import { executeCommand } from "./partials/execute-command"
2020

21-
const isProduction = process.env.NODE_ENV === "production"
22-
2321
const frameworks: Record<FrameworkKey, Framework> = {
2422
laravel: {
2523
name: "Laravel",
@@ -70,7 +68,7 @@ export async function startNewProject(
7068
error(
7169
`The directory '${projectName}' already exists. Please choose a different name or remove the existing directory.`,
7270
)
73-
process.exit(1)
71+
processer.exit(1)
7472
}
7573

7674
const options: FrameworkOptions = {}
@@ -120,7 +118,7 @@ export async function startNewProject(
120118
error(
121119
`${packageManager} is not installed on your system. Please install ${packageManager} to proceed.`,
122120
)
123-
process.exit(1)
121+
processer.exit(1)
124122
}
125123
}
126124

@@ -133,7 +131,7 @@ export async function startNewProject(
133131

134132
await executeCommand(startCreatingApp, `Creating ${frameworks[framework].name} project.`)
135133
fs.mkdirSync(projectName, { recursive: true })
136-
process.chdir(projectName)
134+
processer.chdir(projectName)
137135
if (framework === "vite") {
138136
await executeCommand(setupTailwind(packageManager), "Setting up Tailwind CSS.")
139137
await executeCommand(["npx", "tailwindcss", "init", "-p"], "Initializing Tailwind CSS.")
@@ -153,14 +151,17 @@ export async function startNewProject(
153151
await setupBiome(packageManager)
154152
}
155153

156-
// const isDev = process.env.NODE_ENV !== "development"
157-
// const cliCommand = isDev ? "intentui-cli" : "@intentui/cli@latest"
158-
159-
// const cliCommand = "intentui-cli"
160-
const cliCommand = "@intentui/cli@latest"
154+
const isDev = process.env.NODE_ENV === "development"
155+
const cliCommand = isDev ? "intentui" : "@intentui/cli@latest"
161156
const tsOrJs = language === "typescript" ? "--ts" : "--js"
162-
const initIntentUICommand = ["npx", cliCommand, "init", tsOrJs, "--force", "--yes"]
163-
// const initIntentUICommand = ["bunx", cliCommand, "init", tsOrJs, "--force", "--yes"]
157+
const initIntentUICommand = [
158+
...(isDev ? [] : ["npx"]),
159+
cliCommand,
160+
"init",
161+
tsOrJs,
162+
"--force",
163+
"--yes",
164+
]
164165
await executeCommand(initIntentUICommand, "Finishing.")
165166

166167
console.info("\nProject setup is now complete.")
@@ -177,6 +178,6 @@ export async function startNewProject(
177178
console.info("Ready to customize your project?")
178179
console.info(`Add new components by running: ${highlight("npx @intentui/cli@latest add")}`)
179180
} else {
180-
process.exit(0)
181+
processer.exit(0)
181182
}
182183
}

src/utils/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { type } from "arktype"
66
const configType = type({
77
$schema: "string = 'https://intentui.com/schema.json'",
88
ui: "string",
9-
utils: "string",
9+
lib: "string",
10+
hooks: "string",
1011
gray: "string = 'zinc'",
1112
css: "string",
1213
"alias?": "string",

src/utils/helpers.ts

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,42 @@ export function possibilityComponentsPath(): string {
5252
return "components"
5353
}
5454

55-
export function possibilityUtilsPath(): string {
55+
export function possibilityLibPath(): string {
5656
if (isLaravel()) {
57-
return "resources/js/utils"
57+
return "resources/js/lib"
5858
}
5959
if (hasFolder("src") && !fs.existsSync("artisan") && isNextJs()) {
60-
return "src/utils"
60+
return "src/lib"
6161
}
6262
if (hasFolder("app") && isNextJs() && !fs.existsSync("artisan")) {
63-
return "utils"
63+
return "lib"
6464
}
6565
if (hasFolder("app") && !fs.existsSync("artisan") && isRemix()) {
66-
return "app/utils"
66+
return "app/lib"
6767
}
6868
if (hasFolder("src") && !fs.existsSync("artisan") && !isRemix() && !isNextJs()) {
69-
return "src/utils"
69+
return "src/lib"
7070
}
71-
return "utils"
71+
return "lib"
72+
}
73+
74+
export function possibilityHookPath(): string {
75+
if (isLaravel()) {
76+
return "resources/js/hooks"
77+
}
78+
if (hasFolder("src") && !fs.existsSync("artisan") && isNextJs()) {
79+
return "src/hooks"
80+
}
81+
if (hasFolder("app") && isNextJs() && !fs.existsSync("artisan")) {
82+
return "hooks"
83+
}
84+
if (hasFolder("app") && !fs.existsSync("artisan") && isRemix()) {
85+
return "hooks"
86+
}
87+
if (hasFolder("src") && !fs.existsSync("artisan") && !isRemix() && !isNextJs()) {
88+
return "src/hooks"
89+
}
90+
return "lib"
7291
}
7392

7493
export function possibilityRootPath(): string {
@@ -178,9 +197,7 @@ export function isTailwind(version: number): boolean {
178197
const { dependencies = {}, devDependencies = {} } = packageJson
179198

180199
const tailwindVersion = dependencies.tailwindcss || devDependencies.tailwindcss
181-
182200
if (tailwindVersion) {
183-
// Remove any non-numeric prefix (e.g., ^ or ~)
184201
const cleanVersion = tailwindVersion.replace(/^\D*/, "")
185202
const majorVersion = Number.parseInt(cleanVersion.split(".")[0], 10)
186203
return majorVersion === version

0 commit comments

Comments
 (0)