-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): rework of init command finished & fix #137
- Loading branch information
1 parent
7ccc211
commit 0108054
Showing
9 changed files
with
605 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"solidui-cli": minor | ||
--- | ||
|
||
complete rework of the init command to be more inline with shadcn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,60 @@ | ||
import path from "node:path" | ||
|
||
import { loadConfig } from "tsconfig-paths" | ||
import * as v from "valibot" | ||
|
||
import { resolveImport } from "~/utils/resolve-import" | ||
|
||
export const DEFAULT_COMPONENTS = "~/components" | ||
export const DEFAULT_UTILS = "~/lib/utils" | ||
export const DEFAULT_CSS_FILE = "src/app.css" | ||
export const DEFAULT_TAILWIND_CONFIG = "tailwind.config.cjs" | ||
export const DEFAULT_TAILWIND_PREFIX = "" | ||
|
||
export const ConfigSchema = v.object({ | ||
export const RawConfigSchema = v.object({ | ||
$schema: v.optional(v.string()), | ||
tsx: v.boolean(), | ||
tailwind: v.object({ | ||
css: v.string(), | ||
config: v.string() | ||
config: v.string(), | ||
prefix: v.optional(v.string(), "") | ||
}), | ||
aliases: v.object({ | ||
components: v.string(), | ||
utils: v.string() | ||
}) | ||
}) | ||
|
||
export type RawConfig = v.InferOutput<typeof RawConfigSchema> | ||
|
||
export const ConfigSchema = v.object({ | ||
...RawConfigSchema.entries, | ||
resolvedPaths: v.object({ | ||
tailwindConfig: v.string(), | ||
tailwindCss: v.string(), | ||
utils: v.string(), | ||
components: v.string() | ||
}) | ||
}) | ||
|
||
export type Config = v.InferOutput<typeof ConfigSchema> | ||
|
||
export async function resolveConfigPaths(cwd: string, config: RawConfig) { | ||
const tsConfig = await loadConfig(cwd) | ||
|
||
if (tsConfig.resultType === "failed") { | ||
throw new Error( | ||
`Failed to load ${config.tsx ? "tsconfig" : "jsconfig"}.json. ${tsConfig.message ?? ""}`.trim() | ||
) | ||
} | ||
|
||
return v.parse(ConfigSchema, { | ||
...config, | ||
resolvedPaths: { | ||
tailwindConfig: path.resolve(cwd, config.tailwind.config), | ||
tailwindCss: path.resolve(cwd, config.tailwind.css), | ||
utils: await resolveImport(config.aliases.utils, tsConfig), | ||
components: await resolveImport(config.aliases.components, tsConfig) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { detect } from "@antfu/ni" | ||
|
||
export async function getPackageManager( | ||
targetDir: string | ||
): Promise<"yarn" | "pnpm" | "bun" | "npm"> { | ||
const packageManager = await detect({ programmatic: true, cwd: targetDir }) | ||
|
||
if (packageManager === "yarn@berry") return "yarn" | ||
if (packageManager === "pnpm@6") return "pnpm" | ||
if (packageManager === "bun") return "bun" | ||
|
||
return packageManager ?? "npm" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { createMatchPath, type ConfigLoaderSuccessResult } from "tsconfig-paths" | ||
|
||
export async function resolveImport( | ||
importPath: string, | ||
config: Pick<ConfigLoaderSuccessResult, "absoluteBaseUrl" | "paths"> | ||
) { | ||
return createMatchPath(config.absoluteBaseUrl, config.paths)(importPath, undefined, () => true, [ | ||
".ts", | ||
".tsx" | ||
]) | ||
} |
Oops, something went wrong.