kira-kit 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,212 @@
1
+ import { join } from "path";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
3
+
4
+ const COMPONENTS_DIR = "./src/components/ui";
5
+ const HOOKS_DIR = "./src/hooks";
6
+ const OUTPUT_DIR = "./public/r";
7
+ const REGISTRY_NAME = "kira-kit";
8
+ const HOMEPAGE = "https://kira-kit.vercel.app";
9
+
10
+ import {
11
+ NPM_DEPENDENCY_MAP,
12
+ REGISTRY_DEPENDENCY_MAP,
13
+ } from "../lib/build-config";
14
+
15
+ interface RegistryItem {
16
+ name: string;
17
+ type: "registry:ui" | "registry:hook";
18
+ title: string;
19
+ description: string;
20
+ dependencies: string[];
21
+ registryDependencies: string[];
22
+ files: Array<{
23
+ path: string;
24
+ type: "registry:component" | "registry:hook";
25
+ content: string;
26
+ }>;
27
+ }
28
+
29
+ interface Registry {
30
+ $schema: string;
31
+ name: string;
32
+ homepage: string;
33
+ items: RegistryItem[];
34
+ }
35
+
36
+ function extractDependencies(content: string): string[] {
37
+ const deps: Set<string> = new Set();
38
+
39
+ deps.add("clsx");
40
+ deps.add("tailwind-merge");
41
+
42
+ for (const [importKey, npmDeps] of Object.entries(NPM_DEPENDENCY_MAP)) {
43
+ const regex = new RegExp(
44
+ `from\\s+["']${importKey.replace("/", "\\/")}`,
45
+ "g",
46
+ );
47
+ if (regex.test(content)) {
48
+ npmDeps.forEach((dep) => deps.add(dep));
49
+ }
50
+ }
51
+
52
+ if (
53
+ content.includes('from "class-variance-authority"') ||
54
+ content.includes("from 'class-variance-authority'")
55
+ ) {
56
+ deps.add("class-variance-authority");
57
+ }
58
+
59
+ return Array.from(deps).sort();
60
+ }
61
+
62
+ function getHookDependencies(content: string): string[] {
63
+ const hooks: Set<string> = new Set();
64
+
65
+ const hookImportRegex = /from\s+["']@\/hooks\/([^"']+)["']/g;
66
+ let match;
67
+ while ((match = hookImportRegex.exec(content)) !== null) {
68
+ const hookName = match[1].replace(".tsx", "").replace(".ts", "");
69
+ hooks.add(hookName);
70
+ }
71
+
72
+ return Array.from(hooks).sort();
73
+ }
74
+
75
+ function getRegistryDependencies(
76
+ componentName: string,
77
+ content: string,
78
+ ): string[] {
79
+ const deps: Set<string> = new Set();
80
+
81
+ if (REGISTRY_DEPENDENCY_MAP[componentName]) {
82
+ REGISTRY_DEPENDENCY_MAP[componentName].forEach((dep) => deps.add(dep));
83
+ }
84
+
85
+ const uiImportRegex = /from\s+["']@\/components\/ui\/([^"']+)["']/g;
86
+ let match;
87
+ while ((match = uiImportRegex.exec(content)) !== null) {
88
+ const importedComponent = match[1].replace(".tsx", "").replace(".ts", "");
89
+ if (importedComponent !== componentName) {
90
+ deps.add(importedComponent);
91
+ }
92
+ }
93
+
94
+ return Array.from(deps).sort();
95
+ }
96
+
97
+ function toTitleCase(str: string): string {
98
+ return str
99
+ .split("-")
100
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
101
+ .join(" ");
102
+ }
103
+
104
+ function generateRegistryItem(filePath: string): RegistryItem {
105
+ const fileName = filePath.split("/").pop()?.replace(".tsx", "") || "";
106
+ const content = readFileSync(filePath, "utf-8");
107
+
108
+ const dependencies = extractDependencies(content);
109
+ const registryDependencies = getRegistryDependencies(fileName, content);
110
+ const hookDeps = getHookDependencies(content);
111
+
112
+ const files: RegistryItem["files"] = [
113
+ {
114
+ path: `ui/${fileName}.tsx`,
115
+ type: "registry:component",
116
+ content,
117
+ },
118
+ ];
119
+
120
+ for (const hookName of hookDeps) {
121
+ const hookPath = join(HOOKS_DIR, `${hookName}.ts`);
122
+ if (existsSync(hookPath)) {
123
+ const hookContent = readFileSync(hookPath, "utf-8");
124
+ files.push({
125
+ path: `hooks/${hookName}.ts`,
126
+ type: "registry:hook",
127
+ content: hookContent,
128
+ });
129
+ }
130
+ }
131
+
132
+ return {
133
+ name: fileName,
134
+ type: "registry:ui",
135
+ title: toTitleCase(fileName),
136
+ description: `${toTitleCase(fileName)} component from Kira Kit.`,
137
+ dependencies,
138
+ registryDependencies,
139
+ files,
140
+ };
141
+ }
142
+
143
+ export function buildRegistry(): void {
144
+ console.log("🔨 Building Kira Kit registry...\n");
145
+
146
+ if (!existsSync(OUTPUT_DIR)) {
147
+ mkdirSync(OUTPUT_DIR, { recursive: true });
148
+ }
149
+
150
+ if (!existsSync(COMPONENTS_DIR)) {
151
+ console.log(`📦 Components directory not found: ${COMPONENTS_DIR}`);
152
+ console.log("Make sure you're running from the kira-kit root directory.");
153
+ return;
154
+ }
155
+
156
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
157
+ const { readdirSync } = require("fs");
158
+ const files = readdirSync(COMPONENTS_DIR)
159
+ .filter((f: string) => f.endsWith(".tsx"))
160
+ .sort();
161
+
162
+ console.log(`📦 Found ${files.length} components\n`);
163
+
164
+ const items: RegistryItem[] = [];
165
+
166
+ for (const file of files) {
167
+ const filePath = join(COMPONENTS_DIR, file);
168
+ const item = generateRegistryItem(filePath);
169
+ items.push(item);
170
+
171
+ const componentJsonPath = join(OUTPUT_DIR, `${item.name}.json`);
172
+ writeFileSync(componentJsonPath, JSON.stringify(item, null, 2));
173
+ console.log(
174
+ ` ✅ ${item.name} (${item.dependencies.length} deps, ${item.registryDependencies.length} registry deps)`,
175
+ );
176
+ }
177
+
178
+ const registry: Registry = {
179
+ $schema: "https://ui.shadcn.com/schema/registry.json",
180
+ name: REGISTRY_NAME,
181
+ homepage: HOMEPAGE,
182
+ items,
183
+ };
184
+
185
+ const registryPath = join(OUTPUT_DIR, "registry.json");
186
+ writeFileSync(registryPath, JSON.stringify(registry, null, 2));
187
+
188
+ const indexData = {
189
+ name: REGISTRY_NAME,
190
+ homepage: HOMEPAGE,
191
+ components: items.map((item) => ({
192
+ name: item.name,
193
+ title: item.title,
194
+ dependencies: item.dependencies,
195
+ registryDependencies: item.registryDependencies,
196
+ })),
197
+ };
198
+
199
+ writeFileSync(
200
+ join(OUTPUT_DIR, "index.json"),
201
+ JSON.stringify(indexData, null, 2),
202
+ );
203
+
204
+ console.log(`\n✨ Registry built successfully!`);
205
+ console.log(` 📁 Output: ${OUTPUT_DIR}/`);
206
+ console.log(
207
+ ` 📄 ${files.length} component JSONs + registry.json + index.json`,
208
+ );
209
+ console.log(
210
+ `\n🚀 Deploy to Vercel and access at: https://your-domain.vercel.app/r/{name}.json`,
211
+ );
212
+ }
@@ -0,0 +1,160 @@
1
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
2
+ import { join } from "path";
3
+ import { welcome, info, success, warning, dim } from "../lib/logger";
4
+ import { selectBaseColor } from "../prompts/base-color";
5
+ import { selectPrimaryColor } from "../prompts/primary-color";
6
+ import { detectProjectType, inputAlias } from "../prompts/project-type";
7
+ import { writeConfig, readConfig } from "../lib/config";
8
+ import { generateCss } from "../lib/theme-generator";
9
+ import { execSync } from "child_process";
10
+ import type { InitOptions } from "../types";
11
+
12
+ const UTILS_TEMPLATE = `import { type ClassValue, clsx } from "clsx";
13
+ import { twMerge } from "tailwind-merge";
14
+
15
+ export function cn(...inputs: ClassValue[]) {
16
+ return twMerge(clsx(inputs));
17
+ }
18
+ `;
19
+
20
+ const COLOR_MAPPING: Record<string, string> = {
21
+ blue: "#3b82f6",
22
+ green: "#22c55e",
23
+ orange: "#f97316",
24
+ pink: "#ec4899",
25
+ purple: "#a855f7",
26
+ red: "#ef4444",
27
+ violet: "#8b5cf6",
28
+ yellow: "#eab308",
29
+ };
30
+
31
+ export async function init(options: InitOptions): Promise<void> {
32
+ const cwd = options.cwd || process.cwd();
33
+
34
+ welcome("Kira Kit CLI");
35
+
36
+ const existingConfig = readConfig(cwd);
37
+ if (existingConfig) {
38
+ warning("Kira Kit is already initialized in this project.");
39
+ const inquirer = await import("inquirer");
40
+ const { confirm } = await inquirer.prompt([
41
+ {
42
+ type: "confirm",
43
+ name: "confirm",
44
+ message: "Reinitialize? This will overwrite your config.",
45
+ default: false,
46
+ },
47
+ ]);
48
+ if (!confirm) {
49
+ return;
50
+ }
51
+ }
52
+
53
+ const baseColor = options.baseColor || (await selectBaseColor());
54
+ const primaryColor = options.primaryColor || (await selectPrimaryColor());
55
+ const projectType = await detectProjectType(cwd);
56
+
57
+ info(`Project type: ${projectType}`);
58
+ info(`Base color: ${baseColor}`);
59
+ info(`Primary color: ${primaryColor}`);
60
+
61
+ const componentsAlias = await inputAlias("components", "@/components");
62
+ const utilsAlias = await inputAlias("utils", "@/lib/utils");
63
+
64
+ const utilsDir = join(cwd, utilsAlias.replace("@/", "src/"));
65
+ const componentsUiDir = join(
66
+ cwd,
67
+ componentsAlias.replace("@/", "src/"),
68
+ "ui",
69
+ );
70
+
71
+ if (!existsSync(utilsDir)) {
72
+ mkdirSync(utilsDir, { recursive: true });
73
+ }
74
+
75
+ if (!existsSync(componentsUiDir)) {
76
+ mkdirSync(componentsUiDir, { recursive: true });
77
+ }
78
+
79
+ const utilsFilePath = join(utilsDir, "cn.ts");
80
+ writeFileSync(utilsFilePath, UTILS_TEMPLATE, "utf-8");
81
+ success(`Created ${utilsAlias}/cn.ts`);
82
+
83
+ const cssFilePath = join(cwd, "src", "index.css");
84
+
85
+ // Resolve primary color to hex
86
+ const primaryHex = COLOR_MAPPING[primaryColor] || primaryColor;
87
+ // Fallback if user somehow passed a value not in mapping and not a valid hex,
88
+ // generateCss will throw or handle it (currently throws if invalid).
89
+ // basic check:
90
+ const isHex = /^#[0-9A-F]{6}$/i.test(primaryHex);
91
+ const colorToUse = isHex ? primaryHex : "#3b82f6"; // Default to blue if invalid
92
+
93
+ if (existsSync(cssFilePath)) {
94
+ const content = readFileSync(cssFilePath, "utf-8");
95
+ const hasVariables = content.includes(":root {");
96
+ if (!hasVariables) {
97
+ const cssContent = generateCss(colorToUse);
98
+ writeFileSync(cssFilePath, cssContent, "utf-8");
99
+ success("Generated src/index.css with dynamic palette");
100
+ }
101
+ } else {
102
+ // Create it if it doesn't exist
103
+ const cssContent = generateCss(colorToUse);
104
+ writeFileSync(cssFilePath, cssContent, "utf-8");
105
+ success("Created src/index.css with dynamic palette");
106
+ }
107
+
108
+ writeConfig(cwd, {
109
+ tailwind: {
110
+ config: "",
111
+ css: "src/index.css",
112
+ baseColor,
113
+ cssVariables: true,
114
+ prefix: "",
115
+ },
116
+ aliases: {
117
+ components: componentsAlias,
118
+ utils: utilsAlias,
119
+ ui: `${componentsAlias}/ui`,
120
+ lib: "@/lib",
121
+ hooks: "@/hooks",
122
+ },
123
+ });
124
+
125
+ success("Created components.json");
126
+
127
+ info("Installing base dependencies...");
128
+
129
+ const packageManager = process.env.BUN_INSTALL
130
+ ? "bun"
131
+ : process.env.PNPM_HOME
132
+ ? "pnpm"
133
+ : process.env.YARN_ENABLE_IMMUTABLE_CACHE === "false"
134
+ ? "yarn"
135
+ : "npm";
136
+
137
+ try {
138
+ execSync(
139
+ `${packageManager} add clsx tailwind-merge class-variance-authority @tabler/icons-react`,
140
+ {
141
+ stdio: "inherit",
142
+ cwd,
143
+ env: { ...process.env, ADBLOCK: "1", DISABLE_OPENCOLLECTIVE: "1" },
144
+ },
145
+ );
146
+ success("Dependencies installed");
147
+ } catch {
148
+ warning("Failed to install dependencies. Please run manually:");
149
+ console.log(
150
+ ` ${packageManager} add clsx tailwind-merge class-variance-authority @tabler/icons-react`,
151
+ );
152
+ }
153
+
154
+ console.log("\n");
155
+ success("Kira Kit initialized successfully!");
156
+ console.log("\nNext steps:");
157
+ console.log(` ${dim("Add a component:")} kira-kit add button`);
158
+ console.log(` ${dim("List components:")} kira-kit list`);
159
+ console.log("\n");
160
+ }
@@ -0,0 +1,31 @@
1
+ import { fetchRegistryIndex } from "../lib/registry";
2
+ import { table } from "../lib/logger";
3
+ import { info, error } from "../lib/logger";
4
+
5
+ export async function listComponents(): Promise<void> {
6
+ try {
7
+ info("Fetching registry index...");
8
+
9
+ const index = await fetchRegistryIndex();
10
+
11
+ console.log(`\n📦 Kira Kit Components (${index.components.length} total)\n`);
12
+
13
+ const rows = [
14
+ ["Name", "Title", "Dependencies", "Registry Deps"],
15
+ ...index.components.map((c) => [
16
+ c.name,
17
+ c.title,
18
+ c.dependencies.length.toString(),
19
+ c.registryDependencies.length.toString(),
20
+ ]),
21
+ ];
22
+
23
+ table(rows);
24
+
25
+ console.log("\n");
26
+ info("Use 'kira-kit add <component>' to install a component.");
27
+ } catch (err) {
28
+ error("Failed to fetch registry index. Make sure you're connected to the internet.");
29
+ console.error(err);
30
+ }
31
+ }
package/src/index.ts ADDED
@@ -0,0 +1,118 @@
1
+ import { Command } from "commander";
2
+ import { spawn } from "child_process";
3
+ import { fileURLToPath } from "url";
4
+ import { dirname, resolve } from "path";
5
+ import { init } from "./commands/init";
6
+ import { addComponents } from "./commands/add";
7
+ import { buildRegistry } from "./commands/build";
8
+ import { listComponents } from "./commands/list";
9
+ import type { InitOptions, AddOptions } from "./types";
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = dirname(__filename);
13
+
14
+ const program = new Command();
15
+
16
+ program
17
+ .name("kira-kit")
18
+ .description("CLI tool for Kira Kit - Component library and project scaffolding")
19
+ .version("1.0.0");
20
+
21
+ program
22
+ .command("create [name]")
23
+ .description("Create a new project with Kira Kit")
24
+ .option("-f, --framework <type>", "Framework: nextjs, vite-react, vite-router, remix")
25
+ .option("--router <type>", "Router type for vite-router: file, code")
26
+ .option("--install", "Install dependencies")
27
+ .option("--no-install", "Don't install dependencies")
28
+ .option("--git", "Initialize Git repository")
29
+ .option("--no-git", "Don't initialize Git")
30
+ .action((name: string | undefined, options: Record<string, unknown>) => {
31
+ const createPath = resolve(__dirname, "..", "..", "create", "node_modules", "tsx", "cli.js");
32
+ const createSrcPath = resolve(__dirname, "..", "..", "create", "src", "index.ts");
33
+
34
+ const args = [createSrcPath];
35
+ if (name) args.push(name);
36
+ if (options.framework) args.push("--framework", String(options.framework));
37
+ if (options.router) args.push("--router", String(options.router));
38
+ if (options.install === true) args.push("--install");
39
+ if (options.install === false) args.push("--no-install");
40
+ if (options.git === true) args.push("--git");
41
+ if (options.git === false) args.push("--no-git");
42
+
43
+ const child = spawn(
44
+ process.execPath,
45
+ [createPath, ...args],
46
+ {
47
+ stdio: "inherit",
48
+ cwd: process.cwd(),
49
+ env: process.env,
50
+ }
51
+ );
52
+
53
+ child.on("exit", (code) => {
54
+ process.exit(code ?? 0);
55
+ });
56
+ });
57
+
58
+ program
59
+ .command("init")
60
+ .description("Initialize Kira Kit in your project")
61
+ .option("-c, --cwd <directory>", "Working directory", process.cwd())
62
+ .option("--base-color <color>", "Base color (slate, gray, zinc, neutral, stone)")
63
+ .option("--primary-color <color>", "Primary color (blue, green, orange, pink, purple, red, violet, yellow)")
64
+ .option("-y, --yes", "Skip prompts and use defaults")
65
+ .action(async (options: InitOptions) => {
66
+ try {
67
+ await init(options);
68
+ } catch (error) {
69
+ console.error(error);
70
+ process.exit(1);
71
+ }
72
+ });
73
+
74
+ program
75
+ .command("add")
76
+ .description("Add component(s) to your project")
77
+ .argument("[components...]", "Component names to add")
78
+ .option("-c, --cwd <directory>", "Working directory", process.cwd())
79
+ .option("-o, --overwrite", "Overwrite existing files")
80
+ .option("-y, --yes", "Skip prompts")
81
+ .option("--all", "Add all components")
82
+ .action(async (components: string[], options: AddOptions) => {
83
+ try {
84
+ await addComponents({
85
+ ...options,
86
+ components,
87
+ });
88
+ } catch (error) {
89
+ console.error(error);
90
+ process.exit(1);
91
+ }
92
+ });
93
+
94
+ program
95
+ .command("build")
96
+ .description("Build registry files for all components")
97
+ .action(() => {
98
+ try {
99
+ buildRegistry();
100
+ } catch (error) {
101
+ console.error(error);
102
+ process.exit(1);
103
+ }
104
+ });
105
+
106
+ program
107
+ .command("list")
108
+ .description("List all available components in the registry")
109
+ .action(async () => {
110
+ try {
111
+ await listComponents();
112
+ } catch (error) {
113
+ console.error(error);
114
+ process.exit(1);
115
+ }
116
+ });
117
+
118
+ program.parse();
@@ -0,0 +1,81 @@
1
+ export const NPM_DEPENDENCY_MAP: Record<string, string[]> = {
2
+ "@base-ui/react": ["@base-ui/react"],
3
+ animejs: ["animejs"],
4
+ "class-variance-authority": ["class-variance-authority"],
5
+ "@tabler/icons-react": ["@tabler/icons-react"],
6
+ datefns: ["date-fns"],
7
+ "react-day-picker": ["react-day-picker"],
8
+ "react-resizable-panels": ["react-resizable-panels"],
9
+ "@tanstack/react-table": ["@tanstack/react-table"],
10
+ "@tanstack/react-virtual": ["@tanstack/react-virtual"],
11
+ "@uiw/color-convert": ["@uiw/color-convert"],
12
+ "@uiw/react-color-hue": ["@uiw/react-color-hue"],
13
+ "@uiw/react-color-saturation": ["@uiw/react-color-saturation"],
14
+ "@dnd-kit/core": ["@dnd-kit/core"],
15
+ "@dnd-kit/sortable": ["@dnd-kit/sortable"],
16
+ "@dnd-kit/utilities": ["@dnd-kit/utilities"],
17
+ cmdk: ["cmdk"],
18
+ "embla-carousel-react": ["embla-carousel-react"],
19
+ sonner: ["sonner"],
20
+ };
21
+
22
+ export const REGISTRY_DEPENDENCY_MAP: Record<string, string[]> = {
23
+ accordion: [],
24
+ alert: [],
25
+ "alert-dialog": ["button"],
26
+ "announcement-bar": [],
27
+ "aspect-ratio": [],
28
+ avatar: [],
29
+ badge: [],
30
+ breadcrumb: [],
31
+ button: [],
32
+ "button-group": ["button"],
33
+ calendar: [],
34
+ card: [],
35
+ carousel: [],
36
+ checkbox: ["label"],
37
+ "color-picker": ["button", "popover", "input", "slider", "tabs"],
38
+ combobox: ["button"],
39
+ command: ["dialog"],
40
+ "context-menu": [],
41
+ "data-table": ["button", "checkbox", "input", "dropdown-menu", "table"],
42
+ "date-picker": ["button", "popover", "calendar"],
43
+ dialog: [],
44
+ drawer: [],
45
+ "dropdown-menu": [],
46
+ empty: [],
47
+ field: ["label"],
48
+ "file-upload": ["button", "dialog"],
49
+ "hover-card": [],
50
+ input: [],
51
+ "input-group": ["input"],
52
+ kbd: [],
53
+ kanban: [],
54
+ label: [],
55
+ menubar: [],
56
+ "navigation-menu": [],
57
+ pagination: ["button"],
58
+ popover: [],
59
+ progress: [],
60
+ "radio-group": ["label"],
61
+ resizable: [],
62
+ select: ["button", "popover"],
63
+ separator: [],
64
+ sidebar: ["button", "separator"],
65
+ skeleton: [],
66
+ slider: [],
67
+ sonner: [],
68
+ spotlight: ["command"],
69
+ stepper: [],
70
+ stats: [],
71
+ "stats-card": [],
72
+ switch: [],
73
+ table: [],
74
+ tabs: [],
75
+ textarea: [],
76
+ timeline: [],
77
+ toggle: [],
78
+ "toggle-group": ["toggle"],
79
+ tooltip: [],
80
+ "tree-view": ["checkbox"],
81
+ };