@dinachi/cli 1.1.0 → 1.4.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.
- package/CHANGELOG.md +81 -0
- package/README.md +1 -0
- package/dist/index.js +698 -314
- package/package.json +5 -1
- package/templates/agent/agent.tsx +35 -18
- package/templates/alert/alert.tsx +345 -0
- package/templates/alert/index.ts +16 -0
- package/templates/ask-bar/ask-bar.tsx +1061 -0
- package/templates/ask-bar/index.ts +1 -0
- package/templates/autocomplete/autocomplete.tsx +0 -1
- package/templates/breadcrumb/breadcrumb.tsx +606 -0
- package/templates/breadcrumb/index.ts +9 -0
- package/templates/calendar/calendar.tsx +1155 -0
- package/templates/calendar/index.ts +15 -0
- package/templates/combobox/combobox.tsx +0 -1
- package/templates/command-items/command-items.tsx +69 -0
- package/templates/command-items/index.ts +1 -0
- package/templates/command-palette/command-palette.tsx +954 -0
- package/templates/command-palette/index.ts +1 -0
- package/templates/comparison-table/comparison-table.tsx +540 -0
- package/templates/comparison-table/index.ts +15 -0
- package/templates/data-table/data-table.tsx +2077 -0
- package/templates/data-table/index.ts +14 -0
- package/templates/date-picker/date-picker.tsx +527 -0
- package/templates/date-picker/index.ts +2 -0
- package/templates/date-range-picker/date-range-picker.tsx +504 -0
- package/templates/date-range-picker/index.ts +2 -0
- package/templates/detail-list/detail-list.tsx +419 -0
- package/templates/detail-list/index.ts +12 -0
- package/templates/heat-table/heat-table.tsx +613 -0
- package/templates/heat-table/index.ts +9 -0
- package/templates/menu/menu.tsx +8 -3
- package/templates/month-picker/index.ts +1 -0
- package/templates/month-picker/month-picker.tsx +351 -0
- package/templates/omnibar/index.ts +1 -0
- package/templates/omnibar/omnibar.tsx +1009 -0
- package/templates/pagination/index.ts +8 -0
- package/templates/pagination/pagination.tsx +389 -0
- package/templates/table/index.ts +13 -0
- package/templates/table/table.tsx +265 -0
- package/templates/time-slots/index.ts +1 -0
- package/templates/time-slots/time-slots.tsx +589 -0
- package/templates/week-strip/index.ts +1 -0
- package/templates/week-strip/week-strip.tsx +329 -0
- package/templates/year-view/index.ts +1 -0
- package/templates/year-view/year-view.tsx +362 -0
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
|
-
import { Command as
|
|
4
|
+
import { Command as Command4 } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/add.ts
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
import { execSync } from "child_process";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
9
|
+
import fs5 from "fs-extra";
|
|
10
|
+
import path5 from "path";
|
|
11
11
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
12
12
|
import ora from "ora";
|
|
13
|
-
import
|
|
13
|
+
import chalk2 from "chalk";
|
|
14
14
|
import prompts from "prompts";
|
|
15
15
|
|
|
16
16
|
// src/utils/registry.ts
|
|
@@ -85,6 +85,14 @@ function getComponentRegistry() {
|
|
|
85
85
|
files: [{ name: "agent.tsx" }, { name: "index.ts" }],
|
|
86
86
|
dependencies: []
|
|
87
87
|
},
|
|
88
|
+
alert: {
|
|
89
|
+
name: "alert",
|
|
90
|
+
description: "An inline message that stays on the page, with an optional action and dismiss.",
|
|
91
|
+
files: [{ name: "alert.tsx" }, { name: "index.ts" }],
|
|
92
|
+
dependencies: ["class-variance-authority", "lucide-react"],
|
|
93
|
+
componentDependencies: ["agent", "button"],
|
|
94
|
+
utilityDependencies: ["cn"]
|
|
95
|
+
},
|
|
88
96
|
"alert-dialog": {
|
|
89
97
|
name: "alert-dialog",
|
|
90
98
|
description: "A modal dialog that interrupts the user with important content and expects a response.",
|
|
@@ -93,6 +101,14 @@ function getComponentRegistry() {
|
|
|
93
101
|
componentDependencies: ["agent"],
|
|
94
102
|
utilityDependencies: ["cn"]
|
|
95
103
|
},
|
|
104
|
+
"ask-bar": {
|
|
105
|
+
name: "ask-bar",
|
|
106
|
+
description: "A bar docked at the bottom of the page that turns a request into a plan, read back as one editable sentence and run on a press.",
|
|
107
|
+
files: [{ name: "ask-bar.tsx" }, { name: "index.ts" }],
|
|
108
|
+
dependencies: ["@base-ui/react", "lucide-react"],
|
|
109
|
+
componentDependencies: ["agent", "command-items"],
|
|
110
|
+
utilityDependencies: ["cn"]
|
|
111
|
+
},
|
|
96
112
|
autocomplete: {
|
|
97
113
|
name: "autocomplete",
|
|
98
114
|
description: "A text input with dynamic suggestions that helps users find and select values quickly.",
|
|
@@ -115,6 +131,14 @@ function getComponentRegistry() {
|
|
|
115
131
|
dependencies: ["class-variance-authority"],
|
|
116
132
|
utilityDependencies: ["cn"]
|
|
117
133
|
},
|
|
134
|
+
breadcrumb: {
|
|
135
|
+
name: "breadcrumb",
|
|
136
|
+
description: "A trail of links to the current page that folds its middle into a menu, and a back link with the trail in a sheet on phones.",
|
|
137
|
+
files: [{ name: "breadcrumb.tsx" }, { name: "index.ts" }],
|
|
138
|
+
dependencies: ["@base-ui/react", "lucide-react"],
|
|
139
|
+
componentDependencies: ["agent", "drawer", "link", "menu"],
|
|
140
|
+
utilityDependencies: ["cn"]
|
|
141
|
+
},
|
|
118
142
|
button: {
|
|
119
143
|
name: "button",
|
|
120
144
|
description: "A customizable button component with multiple variants.",
|
|
@@ -161,6 +185,28 @@ function getComponentRegistry() {
|
|
|
161
185
|
componentDependencies: ["agent"],
|
|
162
186
|
utilityDependencies: ["cn"]
|
|
163
187
|
},
|
|
188
|
+
"command-items": {
|
|
189
|
+
name: "command-items",
|
|
190
|
+
description: "The item, action and filter types a command palette, omnibar or assistant list share.",
|
|
191
|
+
files: [{ name: "command-items.tsx" }, { name: "index.ts" }],
|
|
192
|
+
dependencies: []
|
|
193
|
+
},
|
|
194
|
+
"command-palette": {
|
|
195
|
+
name: "command-palette",
|
|
196
|
+
description: "A Cmd+K search over pages, actions and records, with groups, recents, a preview pane and sub-lists.",
|
|
197
|
+
files: [{ name: "command-palette.tsx" }, { name: "index.ts" }],
|
|
198
|
+
dependencies: ["@base-ui/react", "lucide-react"],
|
|
199
|
+
componentDependencies: ["agent", "command-items"],
|
|
200
|
+
utilityDependencies: ["cn"]
|
|
201
|
+
},
|
|
202
|
+
"comparison-table": {
|
|
203
|
+
name: "comparison-table",
|
|
204
|
+
description: "Plans as columns and features as rows, with a sticky plan row, billing period and only-differences filter.",
|
|
205
|
+
files: [{ name: "comparison-table.tsx" }, { name: "index.ts" }],
|
|
206
|
+
dependencies: ["@base-ui/react", "lucide-react"],
|
|
207
|
+
componentDependencies: ["agent", "button", "select", "switch", "table"],
|
|
208
|
+
utilityDependencies: ["cn"]
|
|
209
|
+
},
|
|
164
210
|
"context-menu": {
|
|
165
211
|
name: "context-menu",
|
|
166
212
|
description: "A menu that appears at the pointer on right click or long press.",
|
|
@@ -169,6 +215,22 @@ function getComponentRegistry() {
|
|
|
169
215
|
componentDependencies: ["agent"],
|
|
170
216
|
utilityDependencies: ["cn"]
|
|
171
217
|
},
|
|
218
|
+
"data-table": {
|
|
219
|
+
name: "data-table",
|
|
220
|
+
description: "A sortable, filterable, selectable table on TanStack Table, with its own phone layout.",
|
|
221
|
+
files: [{ name: "data-table.tsx" }, { name: "index.ts" }],
|
|
222
|
+
dependencies: ["@tanstack/react-table", "@tanstack/react-virtual", "lucide-react"],
|
|
223
|
+
componentDependencies: ["agent", "button", "checkbox", "drawer", "input", "menu", "pagination", "select", "skeleton", "table", "toggle-group"],
|
|
224
|
+
utilityDependencies: ["cn"]
|
|
225
|
+
},
|
|
226
|
+
"detail-list": {
|
|
227
|
+
name: "detail-list",
|
|
228
|
+
description: "Labelled values in a dl, with copy and inline edit per row.",
|
|
229
|
+
files: [{ name: "detail-list.tsx" }, { name: "index.ts" }],
|
|
230
|
+
dependencies: ["lucide-react"],
|
|
231
|
+
componentDependencies: ["agent", "button"],
|
|
232
|
+
utilityDependencies: ["cn"]
|
|
233
|
+
},
|
|
172
234
|
dialog: {
|
|
173
235
|
name: "dialog",
|
|
174
236
|
description: "A popup that opens on top of the entire page, providing a modal interface for user interactions.",
|
|
@@ -206,6 +268,14 @@ function getComponentRegistry() {
|
|
|
206
268
|
dependencies: ["@base-ui/react"],
|
|
207
269
|
utilityDependencies: ["cn"]
|
|
208
270
|
},
|
|
271
|
+
"heat-table": {
|
|
272
|
+
name: "heat-table",
|
|
273
|
+
description: "A grid of values shaded by size, with the row and column lit for the cell in focus.",
|
|
274
|
+
files: [{ name: "heat-table.tsx" }, { name: "index.ts" }],
|
|
275
|
+
dependencies: ["@tanstack/react-virtual"],
|
|
276
|
+
componentDependencies: ["table"],
|
|
277
|
+
utilityDependencies: ["cn"]
|
|
278
|
+
},
|
|
209
279
|
input: {
|
|
210
280
|
name: "input",
|
|
211
281
|
description: "A customizable input field component with variants and sizes.",
|
|
@@ -267,6 +337,14 @@ function getComponentRegistry() {
|
|
|
267
337
|
componentDependencies: ["agent"],
|
|
268
338
|
utilityDependencies: ["cn"]
|
|
269
339
|
},
|
|
340
|
+
"omnibar": {
|
|
341
|
+
name: "omnibar",
|
|
342
|
+
description: "A header search field that grows into scoped results with inline actions, and a full-screen search on a phone.",
|
|
343
|
+
files: [{ name: "omnibar.tsx" }, { name: "index.ts" }],
|
|
344
|
+
dependencies: ["@base-ui/react", "lucide-react"],
|
|
345
|
+
componentDependencies: ["agent", "command-items", "drawer"],
|
|
346
|
+
utilityDependencies: ["cn"]
|
|
347
|
+
},
|
|
270
348
|
"otp-field": {
|
|
271
349
|
name: "otp-field",
|
|
272
350
|
description: "A one-time password / verification code input with auto-focus, paste handling, and validation.",
|
|
@@ -275,6 +353,14 @@ function getComponentRegistry() {
|
|
|
275
353
|
componentDependencies: ["agent"],
|
|
276
354
|
utilityDependencies: ["cn"]
|
|
277
355
|
},
|
|
356
|
+
pagination: {
|
|
357
|
+
name: "pagination",
|
|
358
|
+
description: "Pages of a list, in seven fixed slots, with gaps that open a go-to-page field.",
|
|
359
|
+
files: [{ name: "pagination.tsx" }, { name: "index.ts" }],
|
|
360
|
+
dependencies: ["lucide-react"],
|
|
361
|
+
componentDependencies: ["agent", "button"],
|
|
362
|
+
utilityDependencies: ["cn"]
|
|
363
|
+
},
|
|
278
364
|
popover: {
|
|
279
365
|
name: "popover",
|
|
280
366
|
description: "An anchored floating panel for contextual information and lightweight interactions.",
|
|
@@ -335,6 +421,62 @@ function getComponentRegistry() {
|
|
|
335
421
|
dependencies: [],
|
|
336
422
|
utilityDependencies: ["cn"]
|
|
337
423
|
},
|
|
424
|
+
calendar: {
|
|
425
|
+
name: "calendar",
|
|
426
|
+
description: "A month grid for picking a day, several days or a range, scrolled or paged.",
|
|
427
|
+
files: [{ name: "calendar.tsx" }, { name: "index.ts" }],
|
|
428
|
+
dependencies: ["@base-ui/react", "react-day-picker", "date-fns", "lucide-react"],
|
|
429
|
+
componentDependencies: ["agent"],
|
|
430
|
+
utilityDependencies: ["cn"]
|
|
431
|
+
},
|
|
432
|
+
"date-picker": {
|
|
433
|
+
name: "date-picker",
|
|
434
|
+
description: "A date field that reads what you type, with a calendar in a popover or a phone drawer.",
|
|
435
|
+
files: [{ name: "date-picker.tsx" }, { name: "index.ts" }],
|
|
436
|
+
dependencies: ["@base-ui/react", "date-fns", "lucide-react"],
|
|
437
|
+
componentDependencies: ["agent", "button", "calendar", "drawer", "popover"],
|
|
438
|
+
utilityDependencies: ["cn"]
|
|
439
|
+
},
|
|
440
|
+
"date-range-picker": {
|
|
441
|
+
name: "date-range-picker",
|
|
442
|
+
description: "A trigger naming a range, opening presets beside a calendar, applied on Apply.",
|
|
443
|
+
files: [{ name: "date-range-picker.tsx" }, { name: "index.ts" }],
|
|
444
|
+
dependencies: ["date-fns", "lucide-react"],
|
|
445
|
+
componentDependencies: ["agent", "button", "calendar", "drawer", "popover"],
|
|
446
|
+
utilityDependencies: ["cn"]
|
|
447
|
+
},
|
|
448
|
+
"month-picker": {
|
|
449
|
+
name: "month-picker",
|
|
450
|
+
description: "Twelve months a year at a time, for a billing month or a span of months.",
|
|
451
|
+
files: [{ name: "month-picker.tsx" }, { name: "index.ts" }],
|
|
452
|
+
dependencies: ["date-fns", "lucide-react"],
|
|
453
|
+
componentDependencies: ["agent", "calendar"],
|
|
454
|
+
utilityDependencies: ["cn"]
|
|
455
|
+
},
|
|
456
|
+
"time-slots": {
|
|
457
|
+
name: "time-slots",
|
|
458
|
+
description: "A day as a track to drag a booking across, held off busy and past time.",
|
|
459
|
+
files: [{ name: "time-slots.tsx" }, { name: "index.ts" }],
|
|
460
|
+
dependencies: ["date-fns"],
|
|
461
|
+
componentDependencies: ["agent"],
|
|
462
|
+
utilityDependencies: ["cn"]
|
|
463
|
+
},
|
|
464
|
+
"week-strip": {
|
|
465
|
+
name: "week-strip",
|
|
466
|
+
description: "Days in a row that snap a week at a time, with a dot for each booking.",
|
|
467
|
+
files: [{ name: "week-strip.tsx" }, { name: "index.ts" }],
|
|
468
|
+
dependencies: ["date-fns", "lucide-react"],
|
|
469
|
+
componentDependencies: ["agent", "calendar"],
|
|
470
|
+
utilityDependencies: ["cn"]
|
|
471
|
+
},
|
|
472
|
+
"year-view": {
|
|
473
|
+
name: "year-view",
|
|
474
|
+
description: "A year of days shaded by count, that turns a day into a filter.",
|
|
475
|
+
files: [{ name: "year-view.tsx" }, { name: "index.ts" }],
|
|
476
|
+
dependencies: ["date-fns"],
|
|
477
|
+
componentDependencies: ["agent", "calendar"],
|
|
478
|
+
utilityDependencies: ["cn"]
|
|
479
|
+
},
|
|
338
480
|
slider: {
|
|
339
481
|
name: "slider",
|
|
340
482
|
description: "An input where the user selects a value from within a given range.",
|
|
@@ -351,6 +493,13 @@ function getComponentRegistry() {
|
|
|
351
493
|
componentDependencies: ["agent"],
|
|
352
494
|
utilityDependencies: ["cn"]
|
|
353
495
|
},
|
|
496
|
+
table: {
|
|
497
|
+
name: "table",
|
|
498
|
+
description: "Styled native table parts, with numeric columns and a stacked phone layout.",
|
|
499
|
+
files: [{ name: "table.tsx" }, { name: "index.ts" }],
|
|
500
|
+
dependencies: [],
|
|
501
|
+
utilityDependencies: ["cn"]
|
|
502
|
+
},
|
|
354
503
|
tabs: {
|
|
355
504
|
name: "tabs",
|
|
356
505
|
description: "A component for toggling between related panels on the same page.",
|
|
@@ -642,25 +791,35 @@ var LOCK_FILE_MAP = [
|
|
|
642
791
|
{ file: "yarn.lock", manager: "yarn" },
|
|
643
792
|
{ file: "package-lock.json", manager: "npm" }
|
|
644
793
|
];
|
|
645
|
-
function
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
794
|
+
function fromPackageManagerField(dir) {
|
|
795
|
+
const packageJsonPath = path2.join(dir, "package.json");
|
|
796
|
+
if (!fs2.existsSync(packageJsonPath)) return null;
|
|
797
|
+
try {
|
|
798
|
+
const value = JSON.parse(fs2.readFileSync(packageJsonPath, "utf-8")).packageManager ?? "";
|
|
799
|
+
for (const pm of ["pnpm", "yarn", "bun", "npm"]) if (value.startsWith(`${pm}@`)) return pm;
|
|
800
|
+
} catch {
|
|
650
801
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
function fromUserAgent() {
|
|
805
|
+
const agent = process.env.npm_config_user_agent ?? "";
|
|
806
|
+
for (const pm of ["pnpm", "yarn", "bun"]) if (agent.startsWith(`${pm}/`)) return pm;
|
|
807
|
+
return null;
|
|
808
|
+
}
|
|
809
|
+
function detectPackageManager(startDir = process.cwd()) {
|
|
810
|
+
let dir = path2.resolve(startDir);
|
|
811
|
+
while (true) {
|
|
812
|
+
for (const entry of LOCK_FILE_MAP) {
|
|
813
|
+
if (fs2.existsSync(path2.join(dir, entry.file))) return entry.manager;
|
|
661
814
|
}
|
|
662
|
-
|
|
663
|
-
|
|
815
|
+
if (fs2.existsSync(path2.join(dir, "pnpm-workspace.yaml"))) return "pnpm";
|
|
816
|
+
const field = fromPackageManagerField(dir);
|
|
817
|
+
if (field) return field;
|
|
818
|
+
const parent = path2.dirname(dir);
|
|
819
|
+
if (parent === dir) break;
|
|
820
|
+
dir = parent;
|
|
821
|
+
}
|
|
822
|
+
return fromUserAgent() ?? "npm";
|
|
664
823
|
}
|
|
665
824
|
function getInstallCommand(pm, deps) {
|
|
666
825
|
const depsStr = deps.join(" ");
|
|
@@ -676,6 +835,108 @@ function getInstallCommand(pm, deps) {
|
|
|
676
835
|
}
|
|
677
836
|
}
|
|
678
837
|
|
|
838
|
+
// src/utils/dependencies.ts
|
|
839
|
+
var DEPENDENCY_VERSION_MAP = {
|
|
840
|
+
"@base-ui/react": "^1.9.0",
|
|
841
|
+
"lucide-react": "^0.552.0",
|
|
842
|
+
"motion": "^12.23.6",
|
|
843
|
+
"class-variance-authority": "^0.7.1",
|
|
844
|
+
"tailwindcss-animate": "^1.0.7",
|
|
845
|
+
"tw-animate-css": "^1.3.4",
|
|
846
|
+
"clsx": "^2.1.1",
|
|
847
|
+
"tailwind-merge": "^3.5.0",
|
|
848
|
+
"@json-render/core": "^0.14.0",
|
|
849
|
+
"@json-render/react": "^0.14.0",
|
|
850
|
+
"zod": "^4.3.6",
|
|
851
|
+
"react-day-picker": "^9.14.0",
|
|
852
|
+
"date-fns": "^4.4.0",
|
|
853
|
+
"@tanstack/react-table": "^8.21.3",
|
|
854
|
+
"@tanstack/react-virtual": "^3.14.26"
|
|
855
|
+
};
|
|
856
|
+
function toInstallSpec(dep) {
|
|
857
|
+
const version = DEPENDENCY_VERSION_MAP[dep];
|
|
858
|
+
return version ? `${dep}@${version}` : dep;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/utils/legacy.ts
|
|
862
|
+
import { spawnSync } from "child_process";
|
|
863
|
+
var V1_CLI_VERSION = "0.12.0";
|
|
864
|
+
function runV1Add(argv = process.argv) {
|
|
865
|
+
const windows = process.platform === "win32";
|
|
866
|
+
const args = ["--yes", `@dinachi/cli@${V1_CLI_VERSION}`, "add", ...v1AddArgs(argv)];
|
|
867
|
+
const result = windows ? spawnSync("npx.cmd", args.map(quoteForCmd), { stdio: "inherit", shell: true }) : spawnSync("npx", args, { stdio: "inherit" });
|
|
868
|
+
if (result.error) {
|
|
869
|
+
console.error(`Could not run @dinachi/cli@${V1_CLI_VERSION}: ${result.error.message}`);
|
|
870
|
+
return 1;
|
|
871
|
+
}
|
|
872
|
+
return result.status ?? 1;
|
|
873
|
+
}
|
|
874
|
+
function quoteForCmd(arg) {
|
|
875
|
+
return /^[\w@./:=-]+$/.test(arg) ? arg : `"${arg.replace(/"/g, '""')}"`;
|
|
876
|
+
}
|
|
877
|
+
function v1AddArgs(argv) {
|
|
878
|
+
const at = argv.indexOf("add");
|
|
879
|
+
return at === -1 ? [] : argv.slice(at + 1).filter((arg) => arg !== "--v1");
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/utils/skill.ts
|
|
883
|
+
import fs3 from "fs-extra";
|
|
884
|
+
import os from "os";
|
|
885
|
+
import path3 from "path";
|
|
886
|
+
import chalk from "chalk";
|
|
887
|
+
var SKILL = "dinachi-assistant";
|
|
888
|
+
var SKILL_LIST = path3.join("references", "components.md");
|
|
889
|
+
function findStaleSkill(cwd, components) {
|
|
890
|
+
const home = os.homedir();
|
|
891
|
+
const places = [
|
|
892
|
+
[path3.join(cwd, ".claude", "skills"), "project"],
|
|
893
|
+
[path3.join(cwd, ".agents", "skills"), "project"],
|
|
894
|
+
[path3.join(home, ".claude", "skills"), "global"],
|
|
895
|
+
[path3.join(home, ".agents", "skills"), "global"]
|
|
896
|
+
];
|
|
897
|
+
const seen = /* @__PURE__ */ new Set();
|
|
898
|
+
for (const [dir, scope] of places) {
|
|
899
|
+
const skillDir = path3.join(dir, SKILL);
|
|
900
|
+
let real;
|
|
901
|
+
try {
|
|
902
|
+
real = fs3.realpathSync(skillDir);
|
|
903
|
+
} catch {
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
if (seen.has(real)) continue;
|
|
907
|
+
seen.add(real);
|
|
908
|
+
const known = new Set(readSlugs(path3.join(real, SKILL_LIST)));
|
|
909
|
+
const count = components.filter((name) => known.has(name)).length;
|
|
910
|
+
if (count < components.length) {
|
|
911
|
+
return { path: skillDir, scope, known: count, total: components.length };
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
return null;
|
|
915
|
+
}
|
|
916
|
+
function readSlugs(file) {
|
|
917
|
+
try {
|
|
918
|
+
const content = fs3.readFileSync(file, "utf-8");
|
|
919
|
+
return [...content.matchAll(/^- `([a-z0-9-]+)`/gm)].map((match) => match[1]);
|
|
920
|
+
} catch {
|
|
921
|
+
return [];
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
function warnIfSkillStale(cwd) {
|
|
925
|
+
try {
|
|
926
|
+
const stale = findStaleSkill(cwd, Object.keys(getComponentRegistry()));
|
|
927
|
+
if (!stale) return;
|
|
928
|
+
const flag = stale.scope === "global" ? " -g" : " -p";
|
|
929
|
+
console.log();
|
|
930
|
+
console.log(chalk.yellow(`Your ${SKILL} skill knows ${stale.known} of ${stale.total} components.`));
|
|
931
|
+
console.log(` Update it: ${chalk.cyan(`npx skills update ${SKILL}${flag}`)}`);
|
|
932
|
+
} catch {
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// src/utils/paths.ts
|
|
937
|
+
import fs4 from "fs-extra";
|
|
938
|
+
import path4 from "path";
|
|
939
|
+
|
|
679
940
|
// src/utils/json.ts
|
|
680
941
|
function parseJsonWithComments(content) {
|
|
681
942
|
let result = "";
|
|
@@ -733,59 +994,7 @@ function parseJsonWithComments(content) {
|
|
|
733
994
|
return JSON.parse(withoutTrailingCommas);
|
|
734
995
|
}
|
|
735
996
|
|
|
736
|
-
// src/utils/
|
|
737
|
-
var DEPENDENCY_VERSION_MAP = {
|
|
738
|
-
"@base-ui/react": "^1.9.0",
|
|
739
|
-
"lucide-react": "^0.552.0",
|
|
740
|
-
"motion": "^12.23.6",
|
|
741
|
-
"class-variance-authority": "^0.7.1",
|
|
742
|
-
"tailwindcss-animate": "^1.0.7",
|
|
743
|
-
"tw-animate-css": "^1.3.4",
|
|
744
|
-
"clsx": "^2.1.1",
|
|
745
|
-
"tailwind-merge": "^3.5.0",
|
|
746
|
-
"@json-render/core": "^0.14.0",
|
|
747
|
-
"@json-render/react": "^0.14.0",
|
|
748
|
-
"zod": "^4.3.6"
|
|
749
|
-
};
|
|
750
|
-
function toInstallSpec(dep) {
|
|
751
|
-
const version = DEPENDENCY_VERSION_MAP[dep];
|
|
752
|
-
return version ? `${dep}@${version}` : dep;
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// src/utils/legacy.ts
|
|
756
|
-
import { spawnSync } from "child_process";
|
|
757
|
-
var V1_CLI_VERSION = "0.12.0";
|
|
758
|
-
function runV1Add(argv = process.argv) {
|
|
759
|
-
const windows = process.platform === "win32";
|
|
760
|
-
const args = ["--yes", `@dinachi/cli@${V1_CLI_VERSION}`, "add", ...v1AddArgs(argv)];
|
|
761
|
-
const result = windows ? spawnSync("npx.cmd", args.map(quoteForCmd), { stdio: "inherit", shell: true }) : spawnSync("npx", args, { stdio: "inherit" });
|
|
762
|
-
if (result.error) {
|
|
763
|
-
console.error(`Could not run @dinachi/cli@${V1_CLI_VERSION}: ${result.error.message}`);
|
|
764
|
-
return 1;
|
|
765
|
-
}
|
|
766
|
-
return result.status ?? 1;
|
|
767
|
-
}
|
|
768
|
-
function quoteForCmd(arg) {
|
|
769
|
-
return /^[\w@./:=-]+$/.test(arg) ? arg : `"${arg.replace(/"/g, '""')}"`;
|
|
770
|
-
}
|
|
771
|
-
function v1AddArgs(argv) {
|
|
772
|
-
const at = argv.indexOf("add");
|
|
773
|
-
return at === -1 ? [] : argv.slice(at + 1).filter((arg) => arg !== "--v1");
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
// src/commands/add.ts
|
|
777
|
-
var __filename2 = fileURLToPath2(import.meta.url);
|
|
778
|
-
var __dirname2 = path3.dirname(__filename2);
|
|
779
|
-
function stripTemplateDirective(content) {
|
|
780
|
-
return content.replace(/^\/\/ @ts-nocheck\s*\n/m, "");
|
|
781
|
-
}
|
|
782
|
-
function stripExtension(filePath) {
|
|
783
|
-
return filePath.replace(/\.[^./\\]+$/, "");
|
|
784
|
-
}
|
|
785
|
-
function toImportPath(fromFilePath, toFilePath) {
|
|
786
|
-
const relativePath = path3.relative(path3.dirname(fromFilePath), stripExtension(toFilePath)).replace(/\\/g, "/");
|
|
787
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
788
|
-
}
|
|
997
|
+
// src/utils/paths.ts
|
|
789
998
|
function matchPathPattern(pattern, input) {
|
|
790
999
|
if (!pattern.includes("*")) {
|
|
791
1000
|
return pattern === input ? "" : null;
|
|
@@ -799,15 +1008,15 @@ function matchPathPattern(pattern, input) {
|
|
|
799
1008
|
function readCompilerPathConfig(projectRoot) {
|
|
800
1009
|
const configFiles = ["tsconfig.json", "jsconfig.json"];
|
|
801
1010
|
for (const configFile of configFiles) {
|
|
802
|
-
const configPath =
|
|
803
|
-
if (!
|
|
1011
|
+
const configPath = path4.join(projectRoot, configFile);
|
|
1012
|
+
if (!fs4.existsSync(configPath)) {
|
|
804
1013
|
continue;
|
|
805
1014
|
}
|
|
806
1015
|
try {
|
|
807
|
-
const content =
|
|
1016
|
+
const content = fs4.readFileSync(configPath, "utf-8");
|
|
808
1017
|
const parsed = parseJsonWithComments(content);
|
|
809
1018
|
const compilerOptions = parsed.compilerOptions ?? {};
|
|
810
|
-
const baseUrl =
|
|
1019
|
+
const baseUrl = path4.resolve(
|
|
811
1020
|
projectRoot,
|
|
812
1021
|
typeof compilerOptions.baseUrl === "string" ? compilerOptions.baseUrl : "."
|
|
813
1022
|
);
|
|
@@ -831,14 +1040,14 @@ function readCompilerPathConfig(projectRoot) {
|
|
|
831
1040
|
}
|
|
832
1041
|
function resolveConfiguredPath(aliasOrPath, projectRoot, compilerConfig) {
|
|
833
1042
|
const normalized = aliasOrPath.replace(/\\/g, "/").trim();
|
|
834
|
-
if (
|
|
1043
|
+
if (path4.isAbsolute(normalized)) {
|
|
835
1044
|
return normalized;
|
|
836
1045
|
}
|
|
837
1046
|
if (normalized.startsWith("./") || normalized.startsWith("../")) {
|
|
838
|
-
return
|
|
1047
|
+
return path4.resolve(projectRoot, normalized);
|
|
839
1048
|
}
|
|
840
1049
|
if (normalized.startsWith("/")) {
|
|
841
|
-
return
|
|
1050
|
+
return path4.resolve(projectRoot, `.${normalized}`);
|
|
842
1051
|
}
|
|
843
1052
|
if (compilerConfig) {
|
|
844
1053
|
for (const [pattern, targets] of Object.entries(compilerConfig.paths)) {
|
|
@@ -851,13 +1060,58 @@ function resolveConfiguredPath(aliasOrPath, projectRoot, compilerConfig) {
|
|
|
851
1060
|
continue;
|
|
852
1061
|
}
|
|
853
1062
|
const mappedTarget = target.includes("*") ? target.replace("*", wildcard) : target;
|
|
854
|
-
return
|
|
1063
|
+
return path4.resolve(compilerConfig.baseUrl, mappedTarget);
|
|
855
1064
|
}
|
|
856
1065
|
}
|
|
857
1066
|
if (normalized.startsWith("@/") || normalized.startsWith("~/")) {
|
|
858
|
-
return
|
|
1067
|
+
return path4.resolve(projectRoot, normalized.slice(2));
|
|
1068
|
+
}
|
|
1069
|
+
return path4.resolve(projectRoot, normalized);
|
|
1070
|
+
}
|
|
1071
|
+
function majorOf(version) {
|
|
1072
|
+
if (typeof version !== "string") return null;
|
|
1073
|
+
const match = version.match(/^[\^~>=v\s]*(\d+)/);
|
|
1074
|
+
return match ? parseInt(match[1], 10) : null;
|
|
1075
|
+
}
|
|
1076
|
+
function readJson(file) {
|
|
1077
|
+
try {
|
|
1078
|
+
return JSON.parse(fs4.readFileSync(file, "utf-8"));
|
|
1079
|
+
} catch {
|
|
1080
|
+
return null;
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
function findTailwindMajorVersion(projectRoot) {
|
|
1084
|
+
let declared = null;
|
|
1085
|
+
let dir = path4.resolve(projectRoot);
|
|
1086
|
+
while (true) {
|
|
1087
|
+
const installed = readJson(path4.join(dir, "node_modules", "tailwindcss", "package.json"));
|
|
1088
|
+
const installedMajor = majorOf(installed?.version);
|
|
1089
|
+
if (installedMajor !== null) return installedMajor;
|
|
1090
|
+
if (declared === null) {
|
|
1091
|
+
const pkg = readJson(path4.join(dir, "package.json"));
|
|
1092
|
+
declared = majorOf(pkg?.dependencies?.tailwindcss ?? pkg?.devDependencies?.tailwindcss);
|
|
1093
|
+
}
|
|
1094
|
+
const parent = path4.dirname(dir);
|
|
1095
|
+
if (parent === dir) return declared;
|
|
1096
|
+
dir = parent;
|
|
859
1097
|
}
|
|
860
|
-
|
|
1098
|
+
}
|
|
1099
|
+
function detectTailwindMajorVersion(projectRoot) {
|
|
1100
|
+
return findTailwindMajorVersion(projectRoot) ?? 4;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
// src/commands/add.ts
|
|
1104
|
+
var __filename2 = fileURLToPath2(import.meta.url);
|
|
1105
|
+
var __dirname2 = path5.dirname(__filename2);
|
|
1106
|
+
function stripTemplateDirective(content) {
|
|
1107
|
+
return content.replace(/^\/\/ @ts-nocheck\s*\n/m, "");
|
|
1108
|
+
}
|
|
1109
|
+
function stripExtension(filePath) {
|
|
1110
|
+
return filePath.replace(/\.[^./\\]+$/, "");
|
|
1111
|
+
}
|
|
1112
|
+
function toImportPath(fromFilePath, toFilePath) {
|
|
1113
|
+
const relativePath = path5.relative(path5.dirname(fromFilePath), stripExtension(toFilePath)).replace(/\\/g, "/");
|
|
1114
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
861
1115
|
}
|
|
862
1116
|
function tryResolveAsAlias(absoluteFilePath, compilerConfig) {
|
|
863
1117
|
if (!compilerConfig) return null;
|
|
@@ -865,8 +1119,8 @@ function tryResolveAsAlias(absoluteFilePath, compilerConfig) {
|
|
|
865
1119
|
if (!pattern.includes("*") || !targets[0]?.includes("*")) continue;
|
|
866
1120
|
const [prefix] = pattern.split("*");
|
|
867
1121
|
const [targetPrefix] = targets[0].split("*");
|
|
868
|
-
const targetBase =
|
|
869
|
-
const rel =
|
|
1122
|
+
const targetBase = path5.resolve(compilerConfig.baseUrl, targetPrefix);
|
|
1123
|
+
const rel = path5.relative(targetBase, absoluteFilePath).replace(/\\/g, "/");
|
|
870
1124
|
if (!rel.startsWith("..")) {
|
|
871
1125
|
return prefix + stripExtension(rel);
|
|
872
1126
|
}
|
|
@@ -876,7 +1130,7 @@ function tryResolveAsAlias(absoluteFilePath, compilerConfig) {
|
|
|
876
1130
|
function rewriteTemplateImports(content, targetFilePath, utilsFilePath, componentDir, compilerConfig) {
|
|
877
1131
|
const utilsImportPath = tryResolveAsAlias(utilsFilePath, compilerConfig) ?? toImportPath(targetFilePath, utilsFilePath);
|
|
878
1132
|
const componentImportPath = (name) => {
|
|
879
|
-
const filePath =
|
|
1133
|
+
const filePath = path5.join(componentDir, `${name}.tsx`);
|
|
880
1134
|
return tryResolveAsAlias(filePath, compilerConfig) ?? toImportPath(targetFilePath, filePath);
|
|
881
1135
|
};
|
|
882
1136
|
return content.replace(/(['"])@\/lib\/utils\1/g, `$1${utilsImportPath}$1`).replace(/(['"])@\/components\/ui\/([a-z0-9-]+)\1/g, (_match, quote, name) => `${quote}${componentImportPath(name)}${quote}`);
|
|
@@ -900,7 +1154,7 @@ function getComponentDependencies(componentName, visited = /* @__PURE__ */ new S
|
|
|
900
1154
|
}
|
|
901
1155
|
function detectTailwindConfigPath(projectRoot, configuredName) {
|
|
902
1156
|
const preferred = resolveConfiguredPath(configuredName, projectRoot, null);
|
|
903
|
-
if (
|
|
1157
|
+
if (fs5.existsSync(preferred)) {
|
|
904
1158
|
return preferred;
|
|
905
1159
|
}
|
|
906
1160
|
const alternatives = [
|
|
@@ -912,8 +1166,8 @@ function detectTailwindConfigPath(projectRoot, configuredName) {
|
|
|
912
1166
|
"tailwind.config.mts"
|
|
913
1167
|
];
|
|
914
1168
|
for (const candidate of alternatives) {
|
|
915
|
-
const candidatePath =
|
|
916
|
-
if (
|
|
1169
|
+
const candidatePath = path5.join(projectRoot, candidate);
|
|
1170
|
+
if (fs5.existsSync(candidatePath)) {
|
|
917
1171
|
return candidatePath;
|
|
918
1172
|
}
|
|
919
1173
|
}
|
|
@@ -953,29 +1207,14 @@ ${withTrailingComma}
|
|
|
953
1207
|
`;
|
|
954
1208
|
return next;
|
|
955
1209
|
}
|
|
956
|
-
function detectTailwindMajorVersion(projectRoot) {
|
|
957
|
-
const packageJsonPath = path3.join(projectRoot, "package.json");
|
|
958
|
-
if (!fs3.existsSync(packageJsonPath)) return 4;
|
|
959
|
-
try {
|
|
960
|
-
const raw = fs3.readFileSync(packageJsonPath, "utf-8");
|
|
961
|
-
const packageJson = JSON.parse(raw);
|
|
962
|
-
const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
963
|
-
const twVersion = deps.tailwindcss;
|
|
964
|
-
if (!twVersion) return 4;
|
|
965
|
-
const match = twVersion.match(/(\d+)/);
|
|
966
|
-
return match ? parseInt(match[1], 10) : 4;
|
|
967
|
-
} catch {
|
|
968
|
-
return 4;
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
1210
|
async function ensureTW4Plugin(deps, cssFilePath) {
|
|
972
1211
|
if (!deps.includes("tw-animate-css") && !deps.includes("tailwindcss-animate")) {
|
|
973
1212
|
return null;
|
|
974
1213
|
}
|
|
975
|
-
if (!
|
|
1214
|
+
if (!fs5.existsSync(cssFilePath)) {
|
|
976
1215
|
return { skipped: true, path: cssFilePath };
|
|
977
1216
|
}
|
|
978
|
-
const content = await
|
|
1217
|
+
const content = await fs5.readFile(cssFilePath, "utf-8");
|
|
979
1218
|
if (content.includes("tw-animate-css") || content.includes("tailwindcss-animate")) {
|
|
980
1219
|
return { exists: true, path: cssFilePath };
|
|
981
1220
|
}
|
|
@@ -990,7 +1229,7 @@ ${importLine}
|
|
|
990
1229
|
updated = `${importLine}
|
|
991
1230
|
${content}`;
|
|
992
1231
|
}
|
|
993
|
-
await
|
|
1232
|
+
await fs5.writeFile(cssFilePath, updated);
|
|
994
1233
|
return { updated: true, path: cssFilePath };
|
|
995
1234
|
}
|
|
996
1235
|
async function ensureTailwindConfig(deps, projectRoot, configuredFileName) {
|
|
@@ -998,8 +1237,8 @@ async function ensureTailwindConfig(deps, projectRoot, configuredFileName) {
|
|
|
998
1237
|
return null;
|
|
999
1238
|
}
|
|
1000
1239
|
const configPath = detectTailwindConfigPath(projectRoot, configuredFileName || "tailwind.config.js");
|
|
1001
|
-
if (!
|
|
1002
|
-
const ext2 =
|
|
1240
|
+
if (!fs5.existsSync(configPath)) {
|
|
1241
|
+
const ext2 = path5.extname(configPath);
|
|
1003
1242
|
const isCjs2 = ext2 === ".cjs";
|
|
1004
1243
|
const configContent = isCjs2 ? `/** @type {import('tailwindcss').Config} */
|
|
1005
1244
|
module.exports = {
|
|
@@ -1029,15 +1268,15 @@ export default {
|
|
|
1029
1268
|
plugins: [tailwindcssAnimate],
|
|
1030
1269
|
}
|
|
1031
1270
|
`;
|
|
1032
|
-
await
|
|
1033
|
-
await
|
|
1271
|
+
await fs5.ensureDir(path5.dirname(configPath));
|
|
1272
|
+
await fs5.writeFile(configPath, configContent);
|
|
1034
1273
|
return { created: true, path: configPath };
|
|
1035
1274
|
}
|
|
1036
|
-
const currentContent = await
|
|
1275
|
+
const currentContent = await fs5.readFile(configPath, "utf-8");
|
|
1037
1276
|
if (currentContent.includes("tailwindcss-animate")) {
|
|
1038
1277
|
return { exists: true, path: configPath };
|
|
1039
1278
|
}
|
|
1040
|
-
const ext =
|
|
1279
|
+
const ext = path5.extname(configPath);
|
|
1041
1280
|
const isCjs = ext === ".cjs" || /module\.exports\s*=/.test(currentContent);
|
|
1042
1281
|
const pluginExpression = isCjs ? 'require("tailwindcss-animate")' : "tailwindcssAnimate";
|
|
1043
1282
|
let updatedContent = currentContent;
|
|
@@ -1049,7 +1288,7 @@ ${updatedContent}`;
|
|
|
1049
1288
|
if (!merged) {
|
|
1050
1289
|
return { skipped: true, path: configPath };
|
|
1051
1290
|
}
|
|
1052
|
-
await
|
|
1291
|
+
await fs5.writeFile(configPath, merged);
|
|
1053
1292
|
return { updated: true, path: configPath };
|
|
1054
1293
|
}
|
|
1055
1294
|
function escapeRegex(value) {
|
|
@@ -1069,13 +1308,13 @@ function extractExportBlocks(content) {
|
|
|
1069
1308
|
return results;
|
|
1070
1309
|
}
|
|
1071
1310
|
async function handleIndexFile(sourcePath, targetPath, allFilesAdded, targetDir) {
|
|
1072
|
-
const templateContent = stripTemplateDirective(await
|
|
1073
|
-
if (!
|
|
1074
|
-
await
|
|
1075
|
-
allFilesAdded.push({ name: "index.ts", path:
|
|
1311
|
+
const templateContent = stripTemplateDirective(await fs5.readFile(sourcePath, "utf-8"));
|
|
1312
|
+
if (!fs5.existsSync(targetPath)) {
|
|
1313
|
+
await fs5.writeFile(targetPath, templateContent);
|
|
1314
|
+
allFilesAdded.push({ name: "index.ts", path: path5.join(targetDir, "index.ts") });
|
|
1076
1315
|
return;
|
|
1077
1316
|
}
|
|
1078
|
-
const existingContent = await
|
|
1317
|
+
const existingContent = await fs5.readFile(targetPath, "utf-8");
|
|
1079
1318
|
const exportBlocks = extractExportBlocks(templateContent);
|
|
1080
1319
|
const blocksToAppend = [];
|
|
1081
1320
|
for (const { block, modulePath } of exportBlocks) {
|
|
@@ -1092,8 +1331,8 @@ async function handleIndexFile(sourcePath, targetPath, allFilesAdded, targetDir)
|
|
|
1092
1331
|
const updatedContent = `${existingContent.trimEnd()}
|
|
1093
1332
|
${blocksToAppend.join("\n")}
|
|
1094
1333
|
`;
|
|
1095
|
-
await
|
|
1096
|
-
const indexPath =
|
|
1334
|
+
await fs5.writeFile(targetPath, updatedContent);
|
|
1335
|
+
const indexPath = path5.join(targetDir, "index.ts");
|
|
1097
1336
|
if (!allFilesAdded.some((f) => f.path === indexPath)) {
|
|
1098
1337
|
allFilesAdded.push({ name: "index.ts", path: indexPath });
|
|
1099
1338
|
}
|
|
@@ -1153,7 +1392,7 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1153
1392
|
spinner.fail("\u274C Component name is required when not using --all or --motion.");
|
|
1154
1393
|
console.log("Available components:");
|
|
1155
1394
|
Object.keys(registry).forEach((name) => {
|
|
1156
|
-
console.log(` ${
|
|
1395
|
+
console.log(` ${chalk2.cyan(name)}`);
|
|
1157
1396
|
});
|
|
1158
1397
|
process.exit(1);
|
|
1159
1398
|
}
|
|
@@ -1162,7 +1401,7 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1162
1401
|
spinner.fail(`\u274C Component "${name}" not found.`);
|
|
1163
1402
|
console.log("Available components:");
|
|
1164
1403
|
Object.keys(registry).forEach((n) => {
|
|
1165
|
-
console.log(` ${
|
|
1404
|
+
console.log(` ${chalk2.cyan(n)}`);
|
|
1166
1405
|
});
|
|
1167
1406
|
process.exit(1);
|
|
1168
1407
|
}
|
|
@@ -1170,7 +1409,7 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1170
1409
|
const { builds, missing } = resolveBuilds(componentNames, Boolean(options.motion));
|
|
1171
1410
|
if (missing.length > 0) {
|
|
1172
1411
|
spinner.fail(`\u274C No motion build for ${missing.map((n) => `"${n}"`).join(", ")}.`);
|
|
1173
|
-
console.log(`Install without --motion, or run ${
|
|
1412
|
+
console.log(`Install without --motion, or run ${chalk2.cyan("dinachi add --motion")} for the motion tier.`);
|
|
1174
1413
|
process.exit(1);
|
|
1175
1414
|
}
|
|
1176
1415
|
const componentsToInstall = withComponentDependencies([
|
|
@@ -1181,8 +1420,8 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1181
1420
|
const componentDir = resolveConfiguredPath(config.aliases.ui, projectRoot, compilerPathConfig);
|
|
1182
1421
|
const libDir = resolveConfiguredPath(config.aliases.lib, projectRoot, compilerPathConfig);
|
|
1183
1422
|
const utilsFilePath = resolveConfiguredPath(config.aliases.utils, projectRoot, compilerPathConfig);
|
|
1184
|
-
await
|
|
1185
|
-
await
|
|
1423
|
+
await fs5.ensureDir(componentDir);
|
|
1424
|
+
await fs5.ensureDir(libDir);
|
|
1186
1425
|
const allFilesAdded = [];
|
|
1187
1426
|
const allDepsInstalled = [];
|
|
1188
1427
|
const allUtilityDeps = [];
|
|
@@ -1200,11 +1439,11 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1200
1439
|
const utility = utilityRegistry[utilityName];
|
|
1201
1440
|
if (!utility) continue;
|
|
1202
1441
|
const utilityFilename = `${utility.name}.ts`;
|
|
1203
|
-
const sourcePath =
|
|
1204
|
-
const targetPath =
|
|
1205
|
-
if (!
|
|
1206
|
-
const content = stripTemplateDirective(await
|
|
1207
|
-
await
|
|
1442
|
+
const sourcePath = path5.join(__dirname2, "../templates/utils", utilityFilename);
|
|
1443
|
+
const targetPath = path5.join(libDir, utilityFilename);
|
|
1444
|
+
if (!fs5.existsSync(targetPath)) {
|
|
1445
|
+
const content = stripTemplateDirective(await fs5.readFile(sourcePath, "utf-8"));
|
|
1446
|
+
await fs5.writeFile(targetPath, content);
|
|
1208
1447
|
allFilesAdded.push({
|
|
1209
1448
|
name: utilityFilename,
|
|
1210
1449
|
path: targetPath
|
|
@@ -1218,26 +1457,32 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1218
1457
|
for (const name of componentsToInstall) {
|
|
1219
1458
|
const comp = registry[name];
|
|
1220
1459
|
if (!comp) continue;
|
|
1221
|
-
const fileTargetDir = comp.targetDir ?
|
|
1460
|
+
const fileTargetDir = comp.targetDir ? path5.join(libDir, comp.targetDir) : componentDir;
|
|
1222
1461
|
if (comp.targetDir) {
|
|
1223
|
-
await
|
|
1462
|
+
await fs5.ensureDir(fileTargetDir);
|
|
1224
1463
|
}
|
|
1225
1464
|
const build = builds.get(name);
|
|
1226
1465
|
const templateDir = build?.variant.templateDir ?? name;
|
|
1227
1466
|
for (const file of comp.files) {
|
|
1228
|
-
const sourcePath =
|
|
1229
|
-
const targetPath =
|
|
1467
|
+
const sourcePath = path5.join(__dirname2, "../templates", templateDir, file.name);
|
|
1468
|
+
const targetPath = path5.join(fileTargetDir, file.name);
|
|
1230
1469
|
if (file.name === "index.ts") {
|
|
1231
1470
|
if (comp.targetDir) {
|
|
1232
|
-
const templateContent2 = stripTemplateDirective(await
|
|
1233
|
-
await
|
|
1471
|
+
const templateContent2 = stripTemplateDirective(await fs5.readFile(sourcePath, "utf-8"));
|
|
1472
|
+
await fs5.writeFile(targetPath, templateContent2);
|
|
1234
1473
|
allFilesAdded.push({ name: "index.ts", path: targetPath });
|
|
1235
1474
|
} else {
|
|
1236
1475
|
await handleIndexFile(sourcePath, targetPath, allFilesAdded, fileTargetDir);
|
|
1237
1476
|
}
|
|
1238
1477
|
continue;
|
|
1239
1478
|
}
|
|
1240
|
-
if (
|
|
1479
|
+
if (fs5.existsSync(targetPath) && !options.overwrite) {
|
|
1480
|
+
if (options.yes) {
|
|
1481
|
+
spinner.stop();
|
|
1482
|
+
console.log(` ${chalk2.yellow("\u2298")} Kept existing ${file.name} (pass --overwrite to replace it)`);
|
|
1483
|
+
spinner.start();
|
|
1484
|
+
continue;
|
|
1485
|
+
}
|
|
1241
1486
|
spinner.stop();
|
|
1242
1487
|
const { overwrite } = await prompts({
|
|
1243
1488
|
type: "confirm",
|
|
@@ -1246,15 +1491,15 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1246
1491
|
initial: false
|
|
1247
1492
|
});
|
|
1248
1493
|
if (!overwrite) {
|
|
1249
|
-
console.log(` ${
|
|
1494
|
+
console.log(` ${chalk2.yellow("\u2298")} Skipped ${file.name}`);
|
|
1250
1495
|
spinner.start();
|
|
1251
1496
|
continue;
|
|
1252
1497
|
}
|
|
1253
1498
|
spinner.start();
|
|
1254
1499
|
}
|
|
1255
|
-
const templateContent = stripTemplateDirective(await
|
|
1500
|
+
const templateContent = stripTemplateDirective(await fs5.readFile(sourcePath, "utf-8"));
|
|
1256
1501
|
const rewrittenContent = rewriteTemplateImports(templateContent, targetPath, utilsFilePath, componentDir, compilerPathConfig);
|
|
1257
|
-
await
|
|
1502
|
+
await fs5.writeFile(targetPath, rewrittenContent);
|
|
1258
1503
|
allFilesAdded.push({ name: file.name, path: targetPath });
|
|
1259
1504
|
}
|
|
1260
1505
|
if (comp.dependencies?.length) {
|
|
@@ -1264,12 +1509,12 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1264
1509
|
allDepsInstalled.push(...build.variant.dependencies);
|
|
1265
1510
|
}
|
|
1266
1511
|
if (name === "toast") {
|
|
1267
|
-
const toastLibPath =
|
|
1268
|
-
if (!
|
|
1512
|
+
const toastLibPath = path5.join(libDir, "toast.ts");
|
|
1513
|
+
if (!fs5.existsSync(toastLibPath)) {
|
|
1269
1514
|
const toastContent = `import { createToastManager } from "${config.aliases.ui}/toast";
|
|
1270
1515
|
export const toastManager = createToastManager();
|
|
1271
1516
|
`;
|
|
1272
|
-
await
|
|
1517
|
+
await fs5.writeFile(toastLibPath, toastContent);
|
|
1273
1518
|
allFilesAdded.push({ name: "toast.ts", path: toastLibPath });
|
|
1274
1519
|
}
|
|
1275
1520
|
}
|
|
@@ -1289,17 +1534,17 @@ export const toastManager = createToastManager();
|
|
|
1289
1534
|
}
|
|
1290
1535
|
const tailwindConfigInfo = tailwindMajor >= 4 ? await ensureTW4Plugin(
|
|
1291
1536
|
allDepsInstalled,
|
|
1292
|
-
|
|
1537
|
+
path5.resolve(projectRoot, config.tailwind?.css || "src/index.css")
|
|
1293
1538
|
) : await ensureTailwindConfig(
|
|
1294
1539
|
allDepsInstalled,
|
|
1295
1540
|
projectRoot,
|
|
1296
1541
|
config.tailwind?.config || "tailwind.config.js"
|
|
1297
1542
|
);
|
|
1298
|
-
const packageJsonPath =
|
|
1299
|
-
if (!
|
|
1543
|
+
const packageJsonPath = path5.join(projectRoot, "package.json");
|
|
1544
|
+
if (!fs5.existsSync(packageJsonPath)) {
|
|
1300
1545
|
throw new Error("No package.json found in the current directory.");
|
|
1301
1546
|
}
|
|
1302
|
-
const packageJson = JSON.parse(await
|
|
1547
|
+
const packageJson = JSON.parse(await fs5.readFile(packageJsonPath, "utf-8"));
|
|
1303
1548
|
const declaredDeps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
1304
1549
|
const uniqueDeps = [...new Set(allDepsInstalled)];
|
|
1305
1550
|
const missingDeps = uniqueDeps.filter((dep) => !declaredDeps[dep]);
|
|
@@ -1323,18 +1568,18 @@ export const toastManager = createToastManager();
|
|
|
1323
1568
|
console.log();
|
|
1324
1569
|
console.log("Files added:");
|
|
1325
1570
|
allFilesAdded.forEach((file) => {
|
|
1326
|
-
console.log(` ${
|
|
1571
|
+
console.log(` ${chalk2.green("+")} ${file.path}`);
|
|
1327
1572
|
});
|
|
1328
1573
|
if (tailwindConfigInfo) {
|
|
1329
1574
|
const animatePackage = tailwindMajor >= 4 ? "tw-animate-css" : "tailwindcss-animate";
|
|
1330
1575
|
console.log();
|
|
1331
1576
|
if (tailwindConfigInfo.created) {
|
|
1332
|
-
console.log(` ${
|
|
1577
|
+
console.log(` ${chalk2.green("+")} ${tailwindConfigInfo.path} (created with ${animatePackage} plugin)`);
|
|
1333
1578
|
} else if (tailwindConfigInfo.updated) {
|
|
1334
|
-
console.log(` ${
|
|
1579
|
+
console.log(` ${chalk2.blue("~")} ${tailwindConfigInfo.path} (updated with ${animatePackage} plugin)`);
|
|
1335
1580
|
} else if (tailwindConfigInfo.skipped) {
|
|
1336
1581
|
console.log(
|
|
1337
|
-
` ${
|
|
1582
|
+
` ${chalk2.yellow("!")} ${tailwindConfigInfo.path} (could not safely update automatically; add ${animatePackage} manually)`
|
|
1338
1583
|
);
|
|
1339
1584
|
}
|
|
1340
1585
|
}
|
|
@@ -1342,19 +1587,19 @@ export const toastManager = createToastManager();
|
|
|
1342
1587
|
console.log();
|
|
1343
1588
|
console.log("Dependencies to install manually:");
|
|
1344
1589
|
missingDeps.forEach((dep) => {
|
|
1345
|
-
console.log(` ${
|
|
1590
|
+
console.log(` ${chalk2.yellow("\u2022")} ${toInstallSpec(dep)}`);
|
|
1346
1591
|
});
|
|
1347
1592
|
} else if (missingDeps.length > 0) {
|
|
1348
1593
|
console.log();
|
|
1349
1594
|
console.log("Dependencies installed:");
|
|
1350
1595
|
missingDeps.forEach((dep) => {
|
|
1351
|
-
console.log(` ${
|
|
1596
|
+
console.log(` ${chalk2.green("\u2713")} ${toInstallSpec(dep)}`);
|
|
1352
1597
|
});
|
|
1353
1598
|
} else if (uniqueDeps.length > 0) {
|
|
1354
1599
|
console.log();
|
|
1355
1600
|
console.log("Dependencies (already installed):");
|
|
1356
1601
|
uniqueDeps.forEach((dep) => {
|
|
1357
|
-
console.log(` ${
|
|
1602
|
+
console.log(` ${chalk2.blue("~")} ${dep}`);
|
|
1358
1603
|
});
|
|
1359
1604
|
}
|
|
1360
1605
|
const unselected = componentsToInstall.flatMap(
|
|
@@ -1364,10 +1609,11 @@ export const toastManager = createToastManager();
|
|
|
1364
1609
|
console.log();
|
|
1365
1610
|
console.log("Also available in another build:");
|
|
1366
1611
|
unselected.forEach(({ name, flag, variant }) => {
|
|
1367
|
-
console.log(` ${
|
|
1368
|
-
console.log(` ${
|
|
1612
|
+
console.log(` ${chalk2.cyan(name)} ${chalk2.dim(`\u2014 ${variant.description}`)}`);
|
|
1613
|
+
console.log(` ${chalk2.dim(`dinachi add ${name} --${flag} --overwrite`)}`);
|
|
1369
1614
|
});
|
|
1370
1615
|
}
|
|
1616
|
+
warnIfSkillStale(process.cwd());
|
|
1371
1617
|
} catch (error) {
|
|
1372
1618
|
spinner.fail(`\u274C Failed to add component: ${error instanceof Error ? error.message : error}`);
|
|
1373
1619
|
process.exit(1);
|
|
@@ -1378,14 +1624,14 @@ export const toastManager = createToastManager();
|
|
|
1378
1624
|
// src/commands/init.ts
|
|
1379
1625
|
import { Command as Command2 } from "commander";
|
|
1380
1626
|
import { execSync as execSync2 } from "child_process";
|
|
1381
|
-
import
|
|
1382
|
-
import
|
|
1627
|
+
import fs6 from "fs-extra";
|
|
1628
|
+
import path6 from "path";
|
|
1383
1629
|
import prompts2 from "prompts";
|
|
1384
|
-
import
|
|
1630
|
+
import chalk3 from "chalk";
|
|
1385
1631
|
import ora2 from "ora";
|
|
1386
1632
|
function normalizeProjectPath(inputPath, projectRoot) {
|
|
1387
|
-
const absolutePath =
|
|
1388
|
-
const relativePath =
|
|
1633
|
+
const absolutePath = path6.isAbsolute(inputPath) ? path6.normalize(inputPath) : path6.resolve(projectRoot, inputPath);
|
|
1634
|
+
const relativePath = path6.relative(projectRoot, absolutePath).replace(/\\/g, "/");
|
|
1389
1635
|
const withoutPrefix = relativePath.replace(/^\.\//, "").replace(/\/$/, "");
|
|
1390
1636
|
return withoutPrefix.length > 0 ? withoutPrefix : ".";
|
|
1391
1637
|
}
|
|
@@ -1401,21 +1647,6 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
1401
1647
|
}
|
|
1402
1648
|
`;
|
|
1403
1649
|
}
|
|
1404
|
-
function detectTailwindMajorVersion2(projectRoot) {
|
|
1405
|
-
const packageJsonPath = path4.join(projectRoot, "package.json");
|
|
1406
|
-
if (!fs4.existsSync(packageJsonPath)) return 4;
|
|
1407
|
-
try {
|
|
1408
|
-
const raw = fs4.readFileSync(packageJsonPath, "utf-8");
|
|
1409
|
-
const packageJson = JSON.parse(raw);
|
|
1410
|
-
const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
1411
|
-
const twVersion = deps.tailwindcss;
|
|
1412
|
-
if (!twVersion) return 4;
|
|
1413
|
-
const match = twVersion.match(/(\d+)/);
|
|
1414
|
-
return match ? parseInt(match[1], 10) : 4;
|
|
1415
|
-
} catch {
|
|
1416
|
-
return 4;
|
|
1417
|
-
}
|
|
1418
|
-
}
|
|
1419
1650
|
var DINACHI_THEME_PREFIXES = ["--color-", "--radius-", "--shadow-", "--shadow:"];
|
|
1420
1651
|
function extractPreservedThemeVars(css) {
|
|
1421
1652
|
const themeMatch = css.match(/@theme\s+inline\s*\{([^}]*)\}/);
|
|
@@ -1425,33 +1656,34 @@ function extractPreservedThemeVars(css) {
|
|
|
1425
1656
|
return line.startsWith("--") && !DINACHI_THEME_PREFIXES.some((p) => line.startsWith(p));
|
|
1426
1657
|
});
|
|
1427
1658
|
}
|
|
1659
|
+
var DARK_VARIANT = "@custom-variant dark (&:where(.dark, .dark *));";
|
|
1428
1660
|
function getThemeCSS(tailwindMajor, mode, preservedThemeVars = []) {
|
|
1429
1661
|
const lightVars = `:root {
|
|
1430
|
-
--background: oklch(0.986 0
|
|
1431
|
-
--foreground: oklch(0.1459 0
|
|
1432
|
-
--card: oklch(0.9781 0
|
|
1433
|
-
--card-foreground: oklch(0.1459 0
|
|
1662
|
+
--background: oklch(0.986 0 0);
|
|
1663
|
+
--foreground: oklch(0.1459 0 0);
|
|
1664
|
+
--card: oklch(0.9781 0 0);
|
|
1665
|
+
--card-foreground: oklch(0.1459 0 0);
|
|
1434
1666
|
--popover: oklch(1 0 0);
|
|
1435
|
-
--popover-foreground: oklch(0.1324 0
|
|
1436
|
-
--primary: oklch(0.1324 0
|
|
1437
|
-
--primary-foreground: oklch(0.9729 0
|
|
1438
|
-
--secondary: oklch(0.9248 0
|
|
1439
|
-
--secondary-foreground: oklch(0.1324 0
|
|
1440
|
-
--muted: oklch(0.9631 0
|
|
1441
|
-
--muted-foreground: oklch(0.
|
|
1442
|
-
--accent: oklch(0.9248 0
|
|
1443
|
-
--accent-foreground: oklch(0.1459 0
|
|
1667
|
+
--popover-foreground: oklch(0.1324 0 0);
|
|
1668
|
+
--primary: oklch(0.1324 0 0);
|
|
1669
|
+
--primary-foreground: oklch(0.9729 0 0);
|
|
1670
|
+
--secondary: oklch(0.9248 0 0);
|
|
1671
|
+
--secondary-foreground: oklch(0.1324 0 0);
|
|
1672
|
+
--muted: oklch(0.9631 0 0);
|
|
1673
|
+
--muted-foreground: oklch(0.5 0 0);
|
|
1674
|
+
--accent: oklch(0.9248 0 0);
|
|
1675
|
+
--accent-foreground: oklch(0.1459 0 0);
|
|
1444
1676
|
--destructive: oklch(0.5248 0.1368 20.8317);
|
|
1445
1677
|
--destructive-foreground: oklch(1 0 0);
|
|
1446
1678
|
--success: oklch(0.5882 0.1655 145.39);
|
|
1447
1679
|
--success-foreground: oklch(1 0 0);
|
|
1448
1680
|
--warning: oklch(0.6365 0.1639 55.49);
|
|
1449
1681
|
--warning-foreground: oklch(1 0 0);
|
|
1450
|
-
--info: oklch(0.
|
|
1682
|
+
--info: oklch(0.546 0.214 259.815);
|
|
1451
1683
|
--info-foreground: oklch(1 0 0);
|
|
1452
|
-
--border: oklch(0.9239 0
|
|
1453
|
-
--input: oklch(0.8481 0
|
|
1454
|
-
--ring: oklch(0.1459 0
|
|
1684
|
+
--border: oklch(0.9239 0 0);
|
|
1685
|
+
--input: oklch(0.8481 0 0);
|
|
1686
|
+
--ring: oklch(0.1459 0 0);
|
|
1455
1687
|
--chart-1: oklch(0.6038 0.2363 344.4657);
|
|
1456
1688
|
--chart-2: oklch(0.4445 0.2251 300.6246);
|
|
1457
1689
|
--chart-3: oklch(0.379 0.0438 226.1538);
|
|
@@ -1460,14 +1692,14 @@ function getThemeCSS(tailwindMajor, mode, preservedThemeVars = []) {
|
|
|
1460
1692
|
/* A panel surface, distinct from the page. The docs site points --sidebar at
|
|
1461
1693
|
--background instead, because its nav is part of the page rather than docked beside
|
|
1462
1694
|
it \u2014 that is a choice about that layout, not a value this theme is drifting from. */
|
|
1463
|
-
--sidebar: oklch(0.972 0
|
|
1464
|
-
--sidebar-foreground: oklch(0.2284 0
|
|
1465
|
-
--sidebar-primary: oklch(0.1324 0
|
|
1466
|
-
--sidebar-primary-foreground: oklch(0.9742 0
|
|
1467
|
-
--sidebar-accent: oklch(0.9248 0
|
|
1468
|
-
--sidebar-accent-foreground: oklch(0.1459 0
|
|
1469
|
-
--sidebar-border: oklch(0.9407 0
|
|
1470
|
-
--sidebar-ring: oklch(0.5916 0
|
|
1695
|
+
--sidebar: oklch(0.972 0 0);
|
|
1696
|
+
--sidebar-foreground: oklch(0.2284 0 0);
|
|
1697
|
+
--sidebar-primary: oklch(0.1324 0 0);
|
|
1698
|
+
--sidebar-primary-foreground: oklch(0.9742 0 0);
|
|
1699
|
+
--sidebar-accent: oklch(0.9248 0 0);
|
|
1700
|
+
--sidebar-accent-foreground: oklch(0.1459 0 0);
|
|
1701
|
+
--sidebar-border: oklch(0.9407 0 0);
|
|
1702
|
+
--sidebar-ring: oklch(0.5916 0 0);
|
|
1471
1703
|
--radius: 1.05rem;
|
|
1472
1704
|
/* Every component inlines these same values as a var() fallback, so motion works
|
|
1473
1705
|
without them. Declaring them here is what lets a project retune the feel of every
|
|
@@ -1497,19 +1729,19 @@ function getThemeCSS(tailwindMajor, mode, preservedThemeVars = []) {
|
|
|
1497
1729
|
}`;
|
|
1498
1730
|
const darkVars = `.dark {
|
|
1499
1731
|
--background: oklch(0.1149 0 0);
|
|
1500
|
-
--foreground: oklch(0.7999 0
|
|
1501
|
-
--card: oklch(0.133 0
|
|
1502
|
-
--card-foreground: oklch(0.7996 0
|
|
1503
|
-
--popover: oklch(0.
|
|
1504
|
-
--popover-foreground: oklch(0.9742 0
|
|
1505
|
-
--primary: oklch(0.9729 0
|
|
1506
|
-
--primary-foreground: oklch(0.1324 0
|
|
1507
|
-
--secondary: oklch(0.1844 0
|
|
1508
|
-
--secondary-foreground: oklch(0.8009 0
|
|
1509
|
-
--muted: oklch(0.1579 0
|
|
1510
|
-
--muted-foreground: oklch(0.
|
|
1511
|
-
--accent: oklch(0.1391 0
|
|
1512
|
-
--accent-foreground: oklch(0.9742 0
|
|
1732
|
+
--foreground: oklch(0.7999 0 0);
|
|
1733
|
+
--card: oklch(0.133 0 0);
|
|
1734
|
+
--card-foreground: oklch(0.7996 0 0);
|
|
1735
|
+
--popover: oklch(0.14 0 0);
|
|
1736
|
+
--popover-foreground: oklch(0.9742 0 0);
|
|
1737
|
+
--primary: oklch(0.9729 0 0);
|
|
1738
|
+
--primary-foreground: oklch(0.1324 0 0);
|
|
1739
|
+
--secondary: oklch(0.1844 0 0);
|
|
1740
|
+
--secondary-foreground: oklch(0.8009 0 0);
|
|
1741
|
+
--muted: oklch(0.1579 0 0);
|
|
1742
|
+
--muted-foreground: oklch(0.62 0 0);
|
|
1743
|
+
--accent: oklch(0.1391 0 0);
|
|
1744
|
+
--accent-foreground: oklch(0.9742 0 0);
|
|
1513
1745
|
--destructive: oklch(0.585 0.15 20.8317);
|
|
1514
1746
|
--destructive-foreground: oklch(1 0 0);
|
|
1515
1747
|
--success: oklch(0.5484 0.1497 145.39);
|
|
@@ -1517,29 +1749,30 @@ function getThemeCSS(tailwindMajor, mode, preservedThemeVars = []) {
|
|
|
1517
1749
|
--warning: oklch(0.5966 0.1499 55.49);
|
|
1518
1750
|
--warning-foreground: oklch(1 0 0);
|
|
1519
1751
|
--info: oklch(0.707 0.165 254.624);
|
|
1520
|
-
--info-foreground: oklch(0.1324 0
|
|
1521
|
-
--border: oklch(0.
|
|
1522
|
-
--input: oklch(0.2213 0
|
|
1523
|
-
--ring: oklch(0.9248 0
|
|
1752
|
+
--info-foreground: oklch(0.1324 0 0);
|
|
1753
|
+
--border: oklch(0.192 0 0);
|
|
1754
|
+
--input: oklch(0.2213 0 0);
|
|
1755
|
+
--ring: oklch(0.9248 0 0);
|
|
1524
1756
|
--chart-1: oklch(0.5316 0.1409 355.1999);
|
|
1525
1757
|
--chart-2: oklch(0.5633 0.1912 306.8561);
|
|
1526
1758
|
--chart-3: oklch(0.7227 0.1502 60.5799);
|
|
1527
1759
|
--chart-4: oklch(0.6193 0.2029 312.7422);
|
|
1528
1760
|
--chart-5: oklch(0.6118 0.2093 6.1387);
|
|
1529
|
-
--sidebar: oklch(0.1495 0
|
|
1530
|
-
--sidebar-foreground: oklch(0.8942 0
|
|
1531
|
-
--sidebar-primary: oklch(0.9729 0
|
|
1532
|
-
--sidebar-primary-foreground: oklch(0.1324 0
|
|
1533
|
-
--sidebar-accent: oklch(0.2163 0
|
|
1534
|
-
--sidebar-accent-foreground: oklch(0.9699 0
|
|
1535
|
-
--sidebar-border: oklch(0.2757 0
|
|
1536
|
-
--sidebar-ring: oklch(0.9248 0
|
|
1761
|
+
--sidebar: oklch(0.1495 0 0);
|
|
1762
|
+
--sidebar-foreground: oklch(0.8942 0 0);
|
|
1763
|
+
--sidebar-primary: oklch(0.9729 0 0);
|
|
1764
|
+
--sidebar-primary-foreground: oklch(0.1324 0 0);
|
|
1765
|
+
--sidebar-accent: oklch(0.2163 0 0);
|
|
1766
|
+
--sidebar-accent-foreground: oklch(0.9699 0 0);
|
|
1767
|
+
--sidebar-border: oklch(0.2757 0 0);
|
|
1768
|
+
--sidebar-ring: oklch(0.9248 0 0);
|
|
1537
1769
|
}`;
|
|
1538
1770
|
const parts = [];
|
|
1539
1771
|
if (tailwindMajor >= 4) {
|
|
1540
1772
|
if (mode === "full") {
|
|
1541
1773
|
parts.push('@import "tailwindcss";');
|
|
1542
1774
|
}
|
|
1775
|
+
parts.push(DARK_VARIANT);
|
|
1543
1776
|
parts.push(lightVars, darkVars);
|
|
1544
1777
|
const preservedLines = preservedThemeVars.length > 0 ? "\n" + preservedThemeVars.map((v) => ` ${v}`).join("\n") : "";
|
|
1545
1778
|
parts.push(`@theme inline {
|
|
@@ -1629,21 +1862,24 @@ function stripConflictingCSS(css) {
|
|
|
1629
1862
|
return result.trim();
|
|
1630
1863
|
}
|
|
1631
1864
|
async function injectThemeCSS(cssFilePath, tailwindMajor) {
|
|
1632
|
-
await
|
|
1633
|
-
if (
|
|
1634
|
-
const existing = await
|
|
1865
|
+
await fs6.ensureDir(path6.dirname(cssFilePath));
|
|
1866
|
+
if (fs6.existsSync(cssFilePath)) {
|
|
1867
|
+
const existing = await fs6.readFile(cssFilePath, "utf-8");
|
|
1635
1868
|
if (existing.includes("--primary:")) {
|
|
1636
1869
|
return { path: cssFilePath, skipped: true };
|
|
1637
1870
|
}
|
|
1638
1871
|
const preservedVars = tailwindMajor >= 4 ? extractPreservedThemeVars(existing) : [];
|
|
1639
1872
|
const cleaned = stripConflictingCSS(existing);
|
|
1640
|
-
|
|
1873
|
+
let theme2 = getThemeCSS(tailwindMajor, "append", preservedVars);
|
|
1874
|
+
if (/@custom-variant\s+dark\b/.test(cleaned)) theme2 = theme2.replace(`${DARK_VARIANT}
|
|
1875
|
+
|
|
1876
|
+
`, "");
|
|
1641
1877
|
const result = cleaned.length > 0 ? cleaned + "\n\n" + theme2 : getThemeCSS(tailwindMajor, "full", preservedVars);
|
|
1642
|
-
await
|
|
1878
|
+
await fs6.writeFile(cssFilePath, result);
|
|
1643
1879
|
return { path: cssFilePath, updated: true };
|
|
1644
1880
|
}
|
|
1645
1881
|
const theme = getThemeCSS(tailwindMajor, "full");
|
|
1646
|
-
await
|
|
1882
|
+
await fs6.writeFile(cssFilePath, theme);
|
|
1647
1883
|
return { path: cssFilePath, created: true };
|
|
1648
1884
|
}
|
|
1649
1885
|
function getTW3ColorExtend() {
|
|
@@ -1750,20 +1986,20 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1750
1986
|
];
|
|
1751
1987
|
let configPath = null;
|
|
1752
1988
|
for (const candidate of candidates) {
|
|
1753
|
-
const candidatePath =
|
|
1754
|
-
if (
|
|
1989
|
+
const candidatePath = path6.join(projectRoot, candidate);
|
|
1990
|
+
if (fs6.existsSync(candidatePath)) {
|
|
1755
1991
|
configPath = candidatePath;
|
|
1756
1992
|
break;
|
|
1757
1993
|
}
|
|
1758
1994
|
}
|
|
1759
1995
|
if (!configPath) {
|
|
1760
|
-
configPath =
|
|
1761
|
-
const ext =
|
|
1996
|
+
configPath = path6.join(projectRoot, configFileName);
|
|
1997
|
+
const ext = path6.extname(configPath);
|
|
1762
1998
|
const isCjs = ext === ".cjs";
|
|
1763
|
-
await
|
|
1999
|
+
await fs6.writeFile(configPath, createTW3Config(isCjs));
|
|
1764
2000
|
return { path: configPath, created: true };
|
|
1765
2001
|
}
|
|
1766
|
-
const content = await
|
|
2002
|
+
const content = await fs6.readFile(configPath, "utf-8");
|
|
1767
2003
|
if (content.includes('"var(--primary)"') || content.includes("'var(--primary)'")) {
|
|
1768
2004
|
return { path: configPath, skipped: true };
|
|
1769
2005
|
}
|
|
@@ -1772,7 +2008,7 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1772
2008
|
if (extendMatch && extendMatch.index !== void 0) {
|
|
1773
2009
|
const insertPos = extendMatch.index + extendMatch[0].length;
|
|
1774
2010
|
const updated = content.slice(0, insertPos) + "\n " + colorExtend + content.slice(insertPos);
|
|
1775
|
-
await
|
|
2011
|
+
await fs6.writeFile(configPath, updated);
|
|
1776
2012
|
return { path: configPath, updated: true };
|
|
1777
2013
|
}
|
|
1778
2014
|
const themeMatch = content.match(/theme\s*:\s*\{/);
|
|
@@ -1783,7 +2019,7 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1783
2019
|
${colorExtend}
|
|
1784
2020
|
},`;
|
|
1785
2021
|
const updated = content.slice(0, insertPos) + extendBlock + content.slice(insertPos);
|
|
1786
|
-
await
|
|
2022
|
+
await fs6.writeFile(configPath, updated);
|
|
1787
2023
|
return { path: configPath, updated: true };
|
|
1788
2024
|
}
|
|
1789
2025
|
const closingBrace = content.lastIndexOf("}");
|
|
@@ -1798,24 +2034,24 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1798
2034
|
},
|
|
1799
2035
|
`;
|
|
1800
2036
|
const updated = before + themeBlock + content.slice(closingBrace);
|
|
1801
|
-
await
|
|
2037
|
+
await fs6.writeFile(configPath, updated);
|
|
1802
2038
|
return { path: configPath, updated: true };
|
|
1803
2039
|
}
|
|
1804
2040
|
return { path: configPath, skipped: true };
|
|
1805
2041
|
}
|
|
1806
2042
|
function readJsonConfig(filePath) {
|
|
1807
2043
|
try {
|
|
1808
|
-
const content =
|
|
2044
|
+
const content = fs6.readFileSync(filePath, "utf-8");
|
|
1809
2045
|
return parseJsonWithComments(content);
|
|
1810
2046
|
} catch {
|
|
1811
2047
|
return null;
|
|
1812
2048
|
}
|
|
1813
2049
|
}
|
|
1814
2050
|
async function ensureAtAlias(projectRoot, srcDir, isTypeScript) {
|
|
1815
|
-
const tsConfigPath =
|
|
1816
|
-
const jsConfigPath =
|
|
1817
|
-
const configPath =
|
|
1818
|
-
const existedBefore =
|
|
2051
|
+
const tsConfigPath = path6.join(projectRoot, "tsconfig.json");
|
|
2052
|
+
const jsConfigPath = path6.join(projectRoot, "jsconfig.json");
|
|
2053
|
+
const configPath = fs6.existsSync(tsConfigPath) ? tsConfigPath : fs6.existsSync(jsConfigPath) ? jsConfigPath : path6.join(projectRoot, isTypeScript ? "tsconfig.json" : "jsconfig.json");
|
|
2054
|
+
const existedBefore = fs6.existsSync(configPath);
|
|
1819
2055
|
const parsedConfig = readJsonConfig(configPath);
|
|
1820
2056
|
if (existedBefore && !parsedConfig) {
|
|
1821
2057
|
return { path: configPath, skipped: true };
|
|
@@ -1852,7 +2088,7 @@ async function ensureAtAlias(projectRoot, srcDir, isTypeScript) {
|
|
|
1852
2088
|
}
|
|
1853
2089
|
};
|
|
1854
2090
|
try {
|
|
1855
|
-
await
|
|
2091
|
+
await fs6.writeFile(configPath, `${JSON.stringify(nextConfig, null, 2)}
|
|
1856
2092
|
`);
|
|
1857
2093
|
return { path: configPath, [existedBefore ? "updated" : "created"]: true };
|
|
1858
2094
|
} catch {
|
|
@@ -1860,24 +2096,24 @@ async function ensureAtAlias(projectRoot, srcDir, isTypeScript) {
|
|
|
1860
2096
|
}
|
|
1861
2097
|
}
|
|
1862
2098
|
var initCommand = new Command2("init").description("Initialize Dinachi UI in your project").option("--skip-install", "Skip package installation").option("-y, --yes", "Accept all defaults without prompting").action(async (options) => {
|
|
1863
|
-
console.log(
|
|
2099
|
+
console.log(chalk3.bold.cyan("\u{1F3A8} Welcome to Dinachi UI!"));
|
|
1864
2100
|
console.log();
|
|
1865
2101
|
const projectRoot = process.cwd();
|
|
1866
|
-
const packageJsonPath =
|
|
1867
|
-
if (!
|
|
1868
|
-
console.log(
|
|
2102
|
+
const packageJsonPath = path6.join(projectRoot, "package.json");
|
|
2103
|
+
if (!fs6.existsSync(packageJsonPath)) {
|
|
2104
|
+
console.log(chalk3.red("\u274C No package.json found. Please run this command in a valid project."));
|
|
1869
2105
|
process.exit(1);
|
|
1870
2106
|
}
|
|
1871
2107
|
const projectConfig = detectProjectType();
|
|
1872
|
-
console.log(
|
|
2108
|
+
console.log(chalk3.gray(`Detected ${projectConfig.framework} project`));
|
|
1873
2109
|
console.log();
|
|
1874
2110
|
let componentsPath;
|
|
1875
2111
|
let utilsPath;
|
|
1876
2112
|
if (options.yes) {
|
|
1877
2113
|
componentsPath = projectConfig.componentsPath;
|
|
1878
2114
|
utilsPath = projectConfig.utilsPath;
|
|
1879
|
-
console.log(
|
|
1880
|
-
console.log(
|
|
2115
|
+
console.log(chalk3.gray(`Components: ${componentsPath}`));
|
|
2116
|
+
console.log(chalk3.gray(`Utilities: ${utilsPath}`));
|
|
1881
2117
|
console.log();
|
|
1882
2118
|
} else {
|
|
1883
2119
|
const response = await prompts2([
|
|
@@ -1895,7 +2131,7 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
1895
2131
|
}
|
|
1896
2132
|
]);
|
|
1897
2133
|
if (!response.componentsPath || !response.utilsPath) {
|
|
1898
|
-
console.log(
|
|
2134
|
+
console.log(chalk3.red("\u274C Setup cancelled."));
|
|
1899
2135
|
process.exit(1);
|
|
1900
2136
|
}
|
|
1901
2137
|
componentsPath = response.componentsPath;
|
|
@@ -1905,16 +2141,16 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
1905
2141
|
try {
|
|
1906
2142
|
const normalizedComponentsPath = normalizeProjectPath(componentsPath, projectRoot);
|
|
1907
2143
|
const normalizedUtilsPath = normalizeProjectPath(utilsPath, projectRoot);
|
|
1908
|
-
const componentsDirPath =
|
|
1909
|
-
const utilsDirPath =
|
|
1910
|
-
const utilsFilePath =
|
|
1911
|
-
await
|
|
1912
|
-
await
|
|
2144
|
+
const componentsDirPath = path6.resolve(projectRoot, normalizedComponentsPath);
|
|
2145
|
+
const utilsDirPath = path6.resolve(projectRoot, normalizedUtilsPath);
|
|
2146
|
+
const utilsFilePath = path6.join(utilsDirPath, "utils.ts");
|
|
2147
|
+
await fs6.ensureDir(componentsDirPath);
|
|
2148
|
+
await fs6.ensureDir(utilsDirPath);
|
|
1913
2149
|
const utilsContent = createUtilsFileContent();
|
|
1914
|
-
await
|
|
2150
|
+
await fs6.writeFile(utilsFilePath, utilsContent);
|
|
1915
2151
|
spinner.text = "Setting up color theme...";
|
|
1916
|
-
const tailwindMajor =
|
|
1917
|
-
const cssFilePath =
|
|
2152
|
+
const tailwindMajor = detectTailwindMajorVersion(projectRoot);
|
|
2153
|
+
const cssFilePath = path6.resolve(projectRoot, projectConfig.cssPath);
|
|
1918
2154
|
const themeCSSResult = await injectThemeCSS(cssFilePath, tailwindMajor);
|
|
1919
2155
|
let twColorConfigResult = null;
|
|
1920
2156
|
if (tailwindMajor < 4) {
|
|
@@ -1928,7 +2164,7 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
1928
2164
|
const installCmd = getInstallCommand(packageManager, deps.map(toInstallSpec));
|
|
1929
2165
|
execSync2(installCmd, { stdio: "inherit", cwd: projectRoot });
|
|
1930
2166
|
}
|
|
1931
|
-
const hooksPath = projectConfig.srcDir === "." ? "hooks" :
|
|
2167
|
+
const hooksPath = projectConfig.srcDir === "." ? "hooks" : path6.join(projectConfig.srcDir, "hooks").replace(/\\/g, "/");
|
|
1932
2168
|
const configContent = JSON.stringify(
|
|
1933
2169
|
{
|
|
1934
2170
|
style: "default",
|
|
@@ -1941,8 +2177,8 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
1941
2177
|
cssVariables: true
|
|
1942
2178
|
},
|
|
1943
2179
|
aliases: {
|
|
1944
|
-
components: toConfigPath(
|
|
1945
|
-
utils: toConfigPath(
|
|
2180
|
+
components: toConfigPath(path6.dirname(normalizedComponentsPath)),
|
|
2181
|
+
utils: toConfigPath(path6.join(normalizedUtilsPath, "utils")),
|
|
1946
2182
|
ui: toConfigPath(normalizedComponentsPath),
|
|
1947
2183
|
lib: toConfigPath(normalizedUtilsPath),
|
|
1948
2184
|
hooks: toConfigPath(hooksPath)
|
|
@@ -1952,104 +2188,108 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
1952
2188
|
null,
|
|
1953
2189
|
2
|
|
1954
2190
|
);
|
|
1955
|
-
await
|
|
2191
|
+
await fs6.writeFile(path6.join(projectRoot, "components.json"), `${configContent}
|
|
1956
2192
|
`);
|
|
1957
2193
|
const aliasConfigUpdate = await ensureAtAlias(projectRoot, projectConfig.srcDir, projectConfig.isTypeScript);
|
|
1958
2194
|
spinner.succeed("\u2705 Dinachi UI setup complete!");
|
|
1959
2195
|
console.log();
|
|
1960
2196
|
console.log("Next steps:");
|
|
1961
|
-
console.log(` 1. Add a component: ${
|
|
1962
|
-
console.log(` 2. Components will be installed to: ${
|
|
1963
|
-
console.log(` 3. Utils available at: ${
|
|
2197
|
+
console.log(` 1. Add a component: ${chalk3.cyan("npx @dinachi/cli add button")}`);
|
|
2198
|
+
console.log(` 2. Components will be installed to: ${chalk3.cyan(componentsDirPath)}`);
|
|
2199
|
+
console.log(` 3. Utils available at: ${chalk3.cyan(utilsFilePath)}`);
|
|
1964
2200
|
console.log();
|
|
1965
2201
|
if (aliasConfigUpdate.created) {
|
|
1966
|
-
console.log(` ${
|
|
2202
|
+
console.log(` ${chalk3.green("+")} Added @/* path alias in ${aliasConfigUpdate.path}`);
|
|
1967
2203
|
} else if (aliasConfigUpdate.updated) {
|
|
1968
|
-
console.log(` ${
|
|
2204
|
+
console.log(` ${chalk3.blue("~")} Updated @/* path alias in ${aliasConfigUpdate.path}`);
|
|
1969
2205
|
} else if (aliasConfigUpdate.skipped) {
|
|
1970
2206
|
console.log(
|
|
1971
|
-
` ${
|
|
2207
|
+
` ${chalk3.yellow("!")} Could not update ${aliasConfigUpdate.path}. Configure @/* manually if you use alias imports.`
|
|
1972
2208
|
);
|
|
1973
2209
|
}
|
|
1974
2210
|
if (themeCSSResult.created) {
|
|
1975
|
-
console.log(` ${
|
|
2211
|
+
console.log(` ${chalk3.green("+")} Created ${projectConfig.cssPath} with color theme (light + dark)`);
|
|
1976
2212
|
} else if (themeCSSResult.updated) {
|
|
1977
|
-
console.log(` ${
|
|
2213
|
+
console.log(` ${chalk3.blue("~")} Updated ${projectConfig.cssPath} with color theme (light + dark)`);
|
|
1978
2214
|
} else if (themeCSSResult.skipped) {
|
|
1979
|
-
console.log(` ${
|
|
2215
|
+
console.log(` ${chalk3.gray("-")} Color theme already configured in ${projectConfig.cssPath}`);
|
|
1980
2216
|
}
|
|
1981
2217
|
if (twColorConfigResult) {
|
|
1982
2218
|
if (twColorConfigResult.created) {
|
|
1983
|
-
console.log(` ${
|
|
2219
|
+
console.log(` ${chalk3.green("+")} Created ${projectConfig.tailwindConfig} with color mappings`);
|
|
1984
2220
|
} else if (twColorConfigResult.updated) {
|
|
1985
|
-
console.log(` ${
|
|
2221
|
+
console.log(` ${chalk3.blue("~")} Updated ${projectConfig.tailwindConfig} with color mappings`);
|
|
1986
2222
|
} else if (twColorConfigResult.skipped) {
|
|
1987
|
-
console.log(` ${
|
|
2223
|
+
console.log(` ${chalk3.gray("-")} Color mappings already in ${projectConfig.tailwindConfig}`);
|
|
1988
2224
|
}
|
|
1989
2225
|
}
|
|
1990
2226
|
if (!projectConfig.isTypeScript) {
|
|
1991
2227
|
console.log();
|
|
1992
2228
|
console.log(
|
|
1993
|
-
|
|
2229
|
+
chalk3.yellow(
|
|
1994
2230
|
"\u26A0\uFE0F Dinachi components are TypeScript-first. Your project can still consume TSX files, but type-check tooling is recommended."
|
|
1995
2231
|
)
|
|
1996
2232
|
);
|
|
1997
2233
|
}
|
|
1998
2234
|
if (projectConfig.framework === "next.js") {
|
|
1999
2235
|
console.log();
|
|
2000
|
-
console.log(
|
|
2236
|
+
console.log(chalk3.blue("\u{1F4DD} Next.js specific notes:"));
|
|
2001
2237
|
console.log(" - RSC (React Server Components) enabled in config");
|
|
2002
2238
|
console.log(' - Add "use client" for interactive components where needed');
|
|
2003
|
-
console.log(` - Tailwind config: ${
|
|
2239
|
+
console.log(` - Tailwind config: ${chalk3.cyan(projectConfig.tailwindConfig)}`);
|
|
2004
2240
|
} else if (projectConfig.framework === "remix") {
|
|
2005
2241
|
console.log();
|
|
2006
|
-
console.log(
|
|
2007
|
-
console.log(` - Components directory: ${
|
|
2008
|
-
console.log(` - Utilities directory: ${
|
|
2242
|
+
console.log(chalk3.blue("\u{1F4DD} Remix specific notes:"));
|
|
2243
|
+
console.log(` - Components directory: ${chalk3.cyan(componentsDirPath)}`);
|
|
2244
|
+
console.log(` - Utilities directory: ${chalk3.cyan(utilsDirPath)}`);
|
|
2009
2245
|
}
|
|
2010
2246
|
if (options.skipInstall) {
|
|
2011
2247
|
console.log();
|
|
2012
2248
|
console.log("Dependencies to install manually:");
|
|
2013
|
-
|
|
2014
|
-
console.log(` ${chalk2.yellow("\u2022")} ${toInstallSpec(dep)}`);
|
|
2015
|
-
});
|
|
2249
|
+
console.log(` ${chalk3.cyan(getInstallCommand(detectPackageManager(projectRoot), deps.map(toInstallSpec)))}`);
|
|
2016
2250
|
}
|
|
2017
2251
|
console.log();
|
|
2018
2252
|
console.log("\u{1F4A1} Tip: Install globally for shorter commands:");
|
|
2019
|
-
console.log(` ${
|
|
2020
|
-
console.log(` Then use: ${
|
|
2253
|
+
console.log(` ${chalk3.cyan("npm install -g @dinachi/cli")}`);
|
|
2254
|
+
console.log(` Then use: ${chalk3.cyan("dinachi add button")}`);
|
|
2255
|
+
warnIfSkillStale(projectRoot);
|
|
2021
2256
|
} catch (error) {
|
|
2022
2257
|
spinner.fail(`\u274C Setup failed: ${error.message}`);
|
|
2023
2258
|
process.exit(1);
|
|
2024
2259
|
}
|
|
2025
2260
|
});
|
|
2026
2261
|
function detectRsc(projectRoot, framework) {
|
|
2027
|
-
const configPath =
|
|
2028
|
-
if (
|
|
2262
|
+
const configPath = path6.join(projectRoot, "components.json");
|
|
2263
|
+
if (fs6.existsSync(configPath)) {
|
|
2029
2264
|
try {
|
|
2030
|
-
const existing = JSON.parse(
|
|
2265
|
+
const existing = JSON.parse(fs6.readFileSync(configPath, "utf-8"));
|
|
2031
2266
|
if (typeof existing.rsc === "boolean") return existing.rsc;
|
|
2032
2267
|
} catch {
|
|
2033
2268
|
}
|
|
2034
2269
|
}
|
|
2035
2270
|
if (framework !== "next.js") return false;
|
|
2036
|
-
const hasAppRouter =
|
|
2037
|
-
const hasPagesRouter =
|
|
2271
|
+
const hasAppRouter = fs6.existsSync(path6.join(projectRoot, "app")) || fs6.existsSync(path6.join(projectRoot, "src", "app"));
|
|
2272
|
+
const hasPagesRouter = fs6.existsSync(path6.join(projectRoot, "pages")) || fs6.existsSync(path6.join(projectRoot, "src", "pages"));
|
|
2038
2273
|
if (hasAppRouter) return true;
|
|
2039
2274
|
if (hasPagesRouter) return false;
|
|
2040
2275
|
return true;
|
|
2041
2276
|
}
|
|
2042
2277
|
function detectProjectType() {
|
|
2043
|
-
const packageJsonPath =
|
|
2044
|
-
if (!
|
|
2278
|
+
const packageJsonPath = path6.join(process.cwd(), "package.json");
|
|
2279
|
+
if (!fs6.existsSync(packageJsonPath)) {
|
|
2280
|
+
return getDefaultConfig("react", false);
|
|
2281
|
+
}
|
|
2282
|
+
let packageJson;
|
|
2283
|
+
try {
|
|
2284
|
+
packageJson = JSON.parse(fs6.readFileSync(packageJsonPath, "utf-8"));
|
|
2285
|
+
} catch {
|
|
2045
2286
|
return getDefaultConfig("react", false);
|
|
2046
2287
|
}
|
|
2047
|
-
const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
|
|
2048
2288
|
const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
2049
|
-
const hasSrcDir =
|
|
2050
|
-
const hasAppDir =
|
|
2051
|
-
const hasSrcAppDir =
|
|
2052
|
-
const isTypeScript =
|
|
2289
|
+
const hasSrcDir = fs6.existsSync(path6.join(process.cwd(), "src"));
|
|
2290
|
+
const hasAppDir = fs6.existsSync(path6.join(process.cwd(), "app"));
|
|
2291
|
+
const hasSrcAppDir = fs6.existsSync(path6.join(process.cwd(), "src", "app"));
|
|
2292
|
+
const isTypeScript = fs6.existsSync(path6.join(process.cwd(), "tsconfig.json")) || fs6.existsSync(path6.join(process.cwd(), "tsconfig.base.json")) || Boolean(deps.typescript);
|
|
2053
2293
|
const tailwindConfig = detectTailwindConfig();
|
|
2054
2294
|
const cssPath = detectCssPath(hasSrcDir, hasSrcAppDir);
|
|
2055
2295
|
if (deps.next) {
|
|
@@ -2121,7 +2361,7 @@ function detectProjectType() {
|
|
|
2121
2361
|
return getDefaultConfig("react", hasSrcDir);
|
|
2122
2362
|
}
|
|
2123
2363
|
function getDefaultConfig(framework, hasSrcDir) {
|
|
2124
|
-
const isTypeScript =
|
|
2364
|
+
const isTypeScript = fs6.existsSync(path6.join(process.cwd(), "tsconfig.json")) || fs6.existsSync(path6.join(process.cwd(), "tsconfig.base.json"));
|
|
2125
2365
|
return {
|
|
2126
2366
|
framework,
|
|
2127
2367
|
componentsPath: hasSrcDir ? "./src/components/ui" : "./components/ui",
|
|
@@ -2142,7 +2382,7 @@ function detectTailwindConfig() {
|
|
|
2142
2382
|
"tailwind.config.mts"
|
|
2143
2383
|
];
|
|
2144
2384
|
for (const config of configCandidates) {
|
|
2145
|
-
if (
|
|
2385
|
+
if (fs6.existsSync(path6.join(process.cwd(), config))) {
|
|
2146
2386
|
return config;
|
|
2147
2387
|
}
|
|
2148
2388
|
}
|
|
@@ -2161,7 +2401,7 @@ function detectCssPath(hasSrcDir, hasSrcAppDir, isRemix = false) {
|
|
|
2161
2401
|
"app/styles/tailwind.css"
|
|
2162
2402
|
];
|
|
2163
2403
|
for (const cssPath of possiblePaths) {
|
|
2164
|
-
if (
|
|
2404
|
+
if (fs6.existsSync(path6.join(cwd, cssPath))) {
|
|
2165
2405
|
return cssPath;
|
|
2166
2406
|
}
|
|
2167
2407
|
}
|
|
@@ -2171,22 +2411,166 @@ function detectCssPath(hasSrcDir, hasSrcAppDir, isRemix = false) {
|
|
|
2171
2411
|
return "index.css";
|
|
2172
2412
|
}
|
|
2173
2413
|
|
|
2414
|
+
// src/commands/info.ts
|
|
2415
|
+
import { Command as Command3 } from "commander";
|
|
2416
|
+
import fs7 from "fs-extra";
|
|
2417
|
+
import path7 from "path";
|
|
2418
|
+
import chalk4 from "chalk";
|
|
2419
|
+
var DOCS = "https://www.dinachi.dev/docs/components/{slug}.md";
|
|
2420
|
+
function toRelative(projectRoot, target) {
|
|
2421
|
+
return path7.relative(projectRoot, target).replace(/\\/g, "/") || ".";
|
|
2422
|
+
}
|
|
2423
|
+
function isValidJson(file) {
|
|
2424
|
+
try {
|
|
2425
|
+
JSON.parse(fs7.readFileSync(file, "utf-8"));
|
|
2426
|
+
return true;
|
|
2427
|
+
} catch {
|
|
2428
|
+
return false;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
function findNestedConfigs(projectRoot) {
|
|
2432
|
+
const found = [];
|
|
2433
|
+
const visit = (dir, depth) => {
|
|
2434
|
+
let entries;
|
|
2435
|
+
try {
|
|
2436
|
+
entries = fs7.readdirSync(dir, { withFileTypes: true });
|
|
2437
|
+
} catch {
|
|
2438
|
+
return;
|
|
2439
|
+
}
|
|
2440
|
+
for (const entry of entries) {
|
|
2441
|
+
if (!entry.isDirectory() || entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
2442
|
+
const child = path7.join(dir, entry.name);
|
|
2443
|
+
if (fs7.existsSync(path7.join(child, "components.json"))) found.push(toRelative(projectRoot, child));
|
|
2444
|
+
else if (depth < 2) visit(child, depth + 1);
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
visit(projectRoot, 1);
|
|
2448
|
+
return found;
|
|
2449
|
+
}
|
|
2450
|
+
function isInstalled(component, uiDir, libDir) {
|
|
2451
|
+
const dir = component.targetDir ? path7.join(libDir, component.targetDir) : uiDir;
|
|
2452
|
+
const files = component.files.filter((file) => file.name !== "index.ts");
|
|
2453
|
+
return files.length > 0 && files.every((file) => fs7.existsSync(path7.join(dir, file.name)));
|
|
2454
|
+
}
|
|
2455
|
+
async function collectInfo(projectRoot, cliVersion) {
|
|
2456
|
+
const config = await getConfig();
|
|
2457
|
+
const project = detectProjectType();
|
|
2458
|
+
const registry = getComponentRegistry();
|
|
2459
|
+
const tailwindVersion = findTailwindMajorVersion(projectRoot);
|
|
2460
|
+
const problems = [];
|
|
2461
|
+
const packageJsonPath = path7.join(projectRoot, "package.json");
|
|
2462
|
+
if (!fs7.existsSync(packageJsonPath)) problems.push("No package.json here. Run this in the app that will use the components.");
|
|
2463
|
+
else if (!isValidJson(packageJsonPath)) problems.push("package.json is not valid JSON, so the framework could not be detected.");
|
|
2464
|
+
const configPath = path7.join(projectRoot, "components.json");
|
|
2465
|
+
if (!config && fs7.existsSync(configPath)) {
|
|
2466
|
+
problems.push("components.json is not valid JSON. Fix the file rather than running init again.");
|
|
2467
|
+
} else if (!config) {
|
|
2468
|
+
const nested = findNestedConfigs(projectRoot);
|
|
2469
|
+
if (nested.length > 0) problems.push(`components.json found in ${nested.join(", ")}. Run commands there instead.`);
|
|
2470
|
+
}
|
|
2471
|
+
if (tailwindVersion === null) problems.push("Tailwind CSS was not found in package.json or node_modules.");
|
|
2472
|
+
const available = { core: [], motion: [], integrations: [] };
|
|
2473
|
+
for (const [name, component] of Object.entries(registry)) {
|
|
2474
|
+
if (component.integration) available.integrations.push(name);
|
|
2475
|
+
else available[component.tier ?? "core"].push(name);
|
|
2476
|
+
}
|
|
2477
|
+
let resolvedPaths = null;
|
|
2478
|
+
let installed = [];
|
|
2479
|
+
if (config) {
|
|
2480
|
+
const compiler = readCompilerPathConfig(projectRoot);
|
|
2481
|
+
const ui = resolveConfiguredPath(config.aliases.ui, projectRoot, compiler);
|
|
2482
|
+
const lib = resolveConfiguredPath(config.aliases.lib, projectRoot, compiler);
|
|
2483
|
+
const utils = resolveConfiguredPath(config.aliases.utils, projectRoot, compiler);
|
|
2484
|
+
resolvedPaths = {
|
|
2485
|
+
ui: toRelative(projectRoot, ui),
|
|
2486
|
+
lib: toRelative(projectRoot, lib),
|
|
2487
|
+
utils: toRelative(projectRoot, utils)
|
|
2488
|
+
};
|
|
2489
|
+
installed = Object.entries(registry).filter(([, component]) => isInstalled(component, ui, lib)).map(([name]) => name);
|
|
2490
|
+
}
|
|
2491
|
+
const configured = config?.tailwind.config ?? project.tailwindConfig;
|
|
2492
|
+
const tailwindConfig = configured && fs7.existsSync(path7.join(projectRoot, configured)) ? configured : null;
|
|
2493
|
+
return {
|
|
2494
|
+
cliVersion,
|
|
2495
|
+
initialized: config !== null,
|
|
2496
|
+
framework: project.framework,
|
|
2497
|
+
isRSC: config ? config.rsc : detectRsc(projectRoot, project.framework),
|
|
2498
|
+
typescript: config ? config.tsx : project.isTypeScript,
|
|
2499
|
+
tailwindVersion,
|
|
2500
|
+
tailwindCssFile: config?.tailwind.css ?? project.cssPath,
|
|
2501
|
+
// Tailwind 4 is configured in CSS, so a config file name means nothing there.
|
|
2502
|
+
tailwindConfig: tailwindVersion !== null && tailwindVersion >= 4 ? null : tailwindConfig,
|
|
2503
|
+
packageManager: detectPackageManager(projectRoot),
|
|
2504
|
+
aliases: config ? { ...config.aliases } : null,
|
|
2505
|
+
resolvedPaths,
|
|
2506
|
+
installed,
|
|
2507
|
+
agentBridge: installed.includes("agent"),
|
|
2508
|
+
available,
|
|
2509
|
+
docs: DOCS,
|
|
2510
|
+
problems
|
|
2511
|
+
};
|
|
2512
|
+
}
|
|
2513
|
+
function printInfo(info) {
|
|
2514
|
+
const row = (label, value) => console.log(` ${chalk4.dim(label.padEnd(16))}${value}`);
|
|
2515
|
+
console.log();
|
|
2516
|
+
console.log(chalk4.bold("Project"));
|
|
2517
|
+
row("framework", info.framework);
|
|
2518
|
+
row("rsc", String(info.isRSC));
|
|
2519
|
+
row("typescript", String(info.typescript));
|
|
2520
|
+
row("tailwind", info.tailwindVersion === null ? "not found" : `v${info.tailwindVersion}`);
|
|
2521
|
+
row("css", info.tailwindCssFile);
|
|
2522
|
+
if (info.tailwindConfig) row("tailwind config", info.tailwindConfig);
|
|
2523
|
+
row("package manager", info.packageManager);
|
|
2524
|
+
console.log();
|
|
2525
|
+
console.log(chalk4.bold("Dinachi"));
|
|
2526
|
+
row("cli", info.cliVersion);
|
|
2527
|
+
if (!info.initialized) {
|
|
2528
|
+
row("initialized", `no, run ${chalk4.cyan("npx @dinachi/cli@latest init")}`);
|
|
2529
|
+
} else if (info.resolvedPaths) {
|
|
2530
|
+
row("components", info.resolvedPaths.ui);
|
|
2531
|
+
row("lib", info.resolvedPaths.lib);
|
|
2532
|
+
row("utils", info.resolvedPaths.utils);
|
|
2533
|
+
row("agent bridge", info.agentBridge ? "installed" : "not installed");
|
|
2534
|
+
row("installed", info.installed.length > 0 ? info.installed.join(", ") : "none");
|
|
2535
|
+
}
|
|
2536
|
+
const { core, motion, integrations } = info.available;
|
|
2537
|
+
console.log();
|
|
2538
|
+
row("available", `${core.length} core, ${motion.length} motion, ${integrations.length} integration`);
|
|
2539
|
+
row("docs", info.docs);
|
|
2540
|
+
if (info.problems.length > 0) {
|
|
2541
|
+
console.log();
|
|
2542
|
+
console.log(chalk4.bold.yellow("Problems"));
|
|
2543
|
+
for (const problem of info.problems) console.log(` ${chalk4.yellow("!")} ${problem}`);
|
|
2544
|
+
}
|
|
2545
|
+
console.log();
|
|
2546
|
+
}
|
|
2547
|
+
function createInfoCommand(cliVersion) {
|
|
2548
|
+
return new Command3("info").description("Show the project setup and installed components, for you or an agent").option("--json", "Print JSON").action(async (options) => {
|
|
2549
|
+
const info = await collectInfo(process.cwd(), cliVersion);
|
|
2550
|
+
if (options.json) {
|
|
2551
|
+
console.log(JSON.stringify(info, null, 2));
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2554
|
+
printInfo(info);
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2174
2558
|
// src/index.ts
|
|
2175
|
-
import
|
|
2176
|
-
import
|
|
2559
|
+
import fs8 from "fs";
|
|
2560
|
+
import path8 from "path";
|
|
2177
2561
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2178
|
-
var program = new
|
|
2562
|
+
var program = new Command4();
|
|
2179
2563
|
var __filename3 = fileURLToPath3(import.meta.url);
|
|
2180
|
-
var __dirname3 =
|
|
2564
|
+
var __dirname3 = path8.dirname(__filename3);
|
|
2181
2565
|
function getCliVersion() {
|
|
2182
2566
|
try {
|
|
2183
|
-
const packageJsonPath =
|
|
2184
|
-
const packageJson = JSON.parse(
|
|
2567
|
+
const packageJsonPath = path8.resolve(__dirname3, "../package.json");
|
|
2568
|
+
const packageJson = JSON.parse(fs8.readFileSync(packageJsonPath, "utf-8"));
|
|
2185
2569
|
return packageJson.version ?? "0.0.0";
|
|
2186
2570
|
} catch {
|
|
2187
2571
|
return "0.0.0";
|
|
2188
2572
|
}
|
|
2189
2573
|
}
|
|
2190
2574
|
program.name("dinachi").description("Add Dinachi UI components to your project").version(getCliVersion());
|
|
2191
|
-
program.addCommand(addCommand).addCommand(initCommand);
|
|
2575
|
+
program.addCommand(addCommand).addCommand(initCommand).addCommand(createInfoCommand(getCliVersion()));
|
|
2192
2576
|
program.parse();
|