@dinachi/cli 1.3.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 +26 -0
- package/README.md +1 -0
- package/dist/index.js +461 -249
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.4.0] - 2026-12-02
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `dinachi info` shows the project as the CLI sees it: framework, RSC, TypeScript, Tailwind
|
|
15
|
+
version and CSS file, package manager, aliases and where they resolve, installed
|
|
16
|
+
components, whether the agent bridge is installed, and every component by tier.
|
|
17
|
+
`--json` prints it for an agent to read, with a `problems` list for an unreadable config or
|
|
18
|
+
one found in another workspace package.
|
|
19
|
+
- `init` and `add` check for an installed `dinachi-assistant` skill. When it lists fewer
|
|
20
|
+
components than the CLI can add, they print how many it knows and the
|
|
21
|
+
`npx skills update` command. Nothing is printed when no skill is installed.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- The `dinachi-assistant` skill is rewritten as plain markdown with no scripts: a short
|
|
26
|
+
workflow built on `info --json`, a component-selection table, and rules with wrong and
|
|
27
|
+
right examples for composition, styling, the agent bridge and motion. Its component list
|
|
28
|
+
is generated from the registry, with each component's description and docs link.
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- `init` and `add` read the Tailwind version that is installed, looking up through a
|
|
33
|
+
monorepo, so a `catalog:` or `workspace:` range or a root-only declaration no longer
|
|
34
|
+
reads as Tailwind 4. `init` no longer fails on an unreadable `package.json`.
|
|
35
|
+
|
|
10
36
|
## [1.3.0] - 2026-11-21
|
|
11
37
|
|
|
12
38
|
### Added
|
package/README.md
CHANGED
|
@@ -70,6 +70,7 @@ This will:
|
|
|
70
70
|
### Available Commands
|
|
71
71
|
|
|
72
72
|
- `dinachi init` - Initialize Dinachi UI in your project
|
|
73
|
+
- `dinachi info` - Show the project setup and installed components (`--json` for agents)
|
|
73
74
|
- `dinachi init --skip-install` - Initialize without package installation
|
|
74
75
|
- `dinachi add <component>` - Add a component to your project
|
|
75
76
|
- `dinachi add <component> --overwrite` - Overwrite existing component files
|
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
|
|
@@ -835,6 +835,108 @@ function getInstallCommand(pm, deps) {
|
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
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
|
+
|
|
838
940
|
// src/utils/json.ts
|
|
839
941
|
function parseJsonWithComments(content) {
|
|
840
942
|
let result = "";
|
|
@@ -892,63 +994,7 @@ function parseJsonWithComments(content) {
|
|
|
892
994
|
return JSON.parse(withoutTrailingCommas);
|
|
893
995
|
}
|
|
894
996
|
|
|
895
|
-
// src/utils/
|
|
896
|
-
var DEPENDENCY_VERSION_MAP = {
|
|
897
|
-
"@base-ui/react": "^1.9.0",
|
|
898
|
-
"lucide-react": "^0.552.0",
|
|
899
|
-
"motion": "^12.23.6",
|
|
900
|
-
"class-variance-authority": "^0.7.1",
|
|
901
|
-
"tailwindcss-animate": "^1.0.7",
|
|
902
|
-
"tw-animate-css": "^1.3.4",
|
|
903
|
-
"clsx": "^2.1.1",
|
|
904
|
-
"tailwind-merge": "^3.5.0",
|
|
905
|
-
"@json-render/core": "^0.14.0",
|
|
906
|
-
"@json-render/react": "^0.14.0",
|
|
907
|
-
"zod": "^4.3.6",
|
|
908
|
-
"react-day-picker": "^9.14.0",
|
|
909
|
-
"date-fns": "^4.4.0",
|
|
910
|
-
"@tanstack/react-table": "^8.21.3",
|
|
911
|
-
"@tanstack/react-virtual": "^3.14.26"
|
|
912
|
-
};
|
|
913
|
-
function toInstallSpec(dep) {
|
|
914
|
-
const version = DEPENDENCY_VERSION_MAP[dep];
|
|
915
|
-
return version ? `${dep}@${version}` : dep;
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
// src/utils/legacy.ts
|
|
919
|
-
import { spawnSync } from "child_process";
|
|
920
|
-
var V1_CLI_VERSION = "0.12.0";
|
|
921
|
-
function runV1Add(argv = process.argv) {
|
|
922
|
-
const windows = process.platform === "win32";
|
|
923
|
-
const args = ["--yes", `@dinachi/cli@${V1_CLI_VERSION}`, "add", ...v1AddArgs(argv)];
|
|
924
|
-
const result = windows ? spawnSync("npx.cmd", args.map(quoteForCmd), { stdio: "inherit", shell: true }) : spawnSync("npx", args, { stdio: "inherit" });
|
|
925
|
-
if (result.error) {
|
|
926
|
-
console.error(`Could not run @dinachi/cli@${V1_CLI_VERSION}: ${result.error.message}`);
|
|
927
|
-
return 1;
|
|
928
|
-
}
|
|
929
|
-
return result.status ?? 1;
|
|
930
|
-
}
|
|
931
|
-
function quoteForCmd(arg) {
|
|
932
|
-
return /^[\w@./:=-]+$/.test(arg) ? arg : `"${arg.replace(/"/g, '""')}"`;
|
|
933
|
-
}
|
|
934
|
-
function v1AddArgs(argv) {
|
|
935
|
-
const at = argv.indexOf("add");
|
|
936
|
-
return at === -1 ? [] : argv.slice(at + 1).filter((arg) => arg !== "--v1");
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
// src/commands/add.ts
|
|
940
|
-
var __filename2 = fileURLToPath2(import.meta.url);
|
|
941
|
-
var __dirname2 = path3.dirname(__filename2);
|
|
942
|
-
function stripTemplateDirective(content) {
|
|
943
|
-
return content.replace(/^\/\/ @ts-nocheck\s*\n/m, "");
|
|
944
|
-
}
|
|
945
|
-
function stripExtension(filePath) {
|
|
946
|
-
return filePath.replace(/\.[^./\\]+$/, "");
|
|
947
|
-
}
|
|
948
|
-
function toImportPath(fromFilePath, toFilePath) {
|
|
949
|
-
const relativePath = path3.relative(path3.dirname(fromFilePath), stripExtension(toFilePath)).replace(/\\/g, "/");
|
|
950
|
-
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
951
|
-
}
|
|
997
|
+
// src/utils/paths.ts
|
|
952
998
|
function matchPathPattern(pattern, input) {
|
|
953
999
|
if (!pattern.includes("*")) {
|
|
954
1000
|
return pattern === input ? "" : null;
|
|
@@ -962,15 +1008,15 @@ function matchPathPattern(pattern, input) {
|
|
|
962
1008
|
function readCompilerPathConfig(projectRoot) {
|
|
963
1009
|
const configFiles = ["tsconfig.json", "jsconfig.json"];
|
|
964
1010
|
for (const configFile of configFiles) {
|
|
965
|
-
const configPath =
|
|
966
|
-
if (!
|
|
1011
|
+
const configPath = path4.join(projectRoot, configFile);
|
|
1012
|
+
if (!fs4.existsSync(configPath)) {
|
|
967
1013
|
continue;
|
|
968
1014
|
}
|
|
969
1015
|
try {
|
|
970
|
-
const content =
|
|
1016
|
+
const content = fs4.readFileSync(configPath, "utf-8");
|
|
971
1017
|
const parsed = parseJsonWithComments(content);
|
|
972
1018
|
const compilerOptions = parsed.compilerOptions ?? {};
|
|
973
|
-
const baseUrl =
|
|
1019
|
+
const baseUrl = path4.resolve(
|
|
974
1020
|
projectRoot,
|
|
975
1021
|
typeof compilerOptions.baseUrl === "string" ? compilerOptions.baseUrl : "."
|
|
976
1022
|
);
|
|
@@ -994,14 +1040,14 @@ function readCompilerPathConfig(projectRoot) {
|
|
|
994
1040
|
}
|
|
995
1041
|
function resolveConfiguredPath(aliasOrPath, projectRoot, compilerConfig) {
|
|
996
1042
|
const normalized = aliasOrPath.replace(/\\/g, "/").trim();
|
|
997
|
-
if (
|
|
1043
|
+
if (path4.isAbsolute(normalized)) {
|
|
998
1044
|
return normalized;
|
|
999
1045
|
}
|
|
1000
1046
|
if (normalized.startsWith("./") || normalized.startsWith("../")) {
|
|
1001
|
-
return
|
|
1047
|
+
return path4.resolve(projectRoot, normalized);
|
|
1002
1048
|
}
|
|
1003
1049
|
if (normalized.startsWith("/")) {
|
|
1004
|
-
return
|
|
1050
|
+
return path4.resolve(projectRoot, `.${normalized}`);
|
|
1005
1051
|
}
|
|
1006
1052
|
if (compilerConfig) {
|
|
1007
1053
|
for (const [pattern, targets] of Object.entries(compilerConfig.paths)) {
|
|
@@ -1014,13 +1060,58 @@ function resolveConfiguredPath(aliasOrPath, projectRoot, compilerConfig) {
|
|
|
1014
1060
|
continue;
|
|
1015
1061
|
}
|
|
1016
1062
|
const mappedTarget = target.includes("*") ? target.replace("*", wildcard) : target;
|
|
1017
|
-
return
|
|
1063
|
+
return path4.resolve(compilerConfig.baseUrl, mappedTarget);
|
|
1018
1064
|
}
|
|
1019
1065
|
}
|
|
1020
1066
|
if (normalized.startsWith("@/") || normalized.startsWith("~/")) {
|
|
1021
|
-
return
|
|
1067
|
+
return path4.resolve(projectRoot, normalized.slice(2));
|
|
1022
1068
|
}
|
|
1023
|
-
return
|
|
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;
|
|
1097
|
+
}
|
|
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}`;
|
|
1024
1115
|
}
|
|
1025
1116
|
function tryResolveAsAlias(absoluteFilePath, compilerConfig) {
|
|
1026
1117
|
if (!compilerConfig) return null;
|
|
@@ -1028,8 +1119,8 @@ function tryResolveAsAlias(absoluteFilePath, compilerConfig) {
|
|
|
1028
1119
|
if (!pattern.includes("*") || !targets[0]?.includes("*")) continue;
|
|
1029
1120
|
const [prefix] = pattern.split("*");
|
|
1030
1121
|
const [targetPrefix] = targets[0].split("*");
|
|
1031
|
-
const targetBase =
|
|
1032
|
-
const rel =
|
|
1122
|
+
const targetBase = path5.resolve(compilerConfig.baseUrl, targetPrefix);
|
|
1123
|
+
const rel = path5.relative(targetBase, absoluteFilePath).replace(/\\/g, "/");
|
|
1033
1124
|
if (!rel.startsWith("..")) {
|
|
1034
1125
|
return prefix + stripExtension(rel);
|
|
1035
1126
|
}
|
|
@@ -1039,7 +1130,7 @@ function tryResolveAsAlias(absoluteFilePath, compilerConfig) {
|
|
|
1039
1130
|
function rewriteTemplateImports(content, targetFilePath, utilsFilePath, componentDir, compilerConfig) {
|
|
1040
1131
|
const utilsImportPath = tryResolveAsAlias(utilsFilePath, compilerConfig) ?? toImportPath(targetFilePath, utilsFilePath);
|
|
1041
1132
|
const componentImportPath = (name) => {
|
|
1042
|
-
const filePath =
|
|
1133
|
+
const filePath = path5.join(componentDir, `${name}.tsx`);
|
|
1043
1134
|
return tryResolveAsAlias(filePath, compilerConfig) ?? toImportPath(targetFilePath, filePath);
|
|
1044
1135
|
};
|
|
1045
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}`);
|
|
@@ -1063,7 +1154,7 @@ function getComponentDependencies(componentName, visited = /* @__PURE__ */ new S
|
|
|
1063
1154
|
}
|
|
1064
1155
|
function detectTailwindConfigPath(projectRoot, configuredName) {
|
|
1065
1156
|
const preferred = resolveConfiguredPath(configuredName, projectRoot, null);
|
|
1066
|
-
if (
|
|
1157
|
+
if (fs5.existsSync(preferred)) {
|
|
1067
1158
|
return preferred;
|
|
1068
1159
|
}
|
|
1069
1160
|
const alternatives = [
|
|
@@ -1075,8 +1166,8 @@ function detectTailwindConfigPath(projectRoot, configuredName) {
|
|
|
1075
1166
|
"tailwind.config.mts"
|
|
1076
1167
|
];
|
|
1077
1168
|
for (const candidate of alternatives) {
|
|
1078
|
-
const candidatePath =
|
|
1079
|
-
if (
|
|
1169
|
+
const candidatePath = path5.join(projectRoot, candidate);
|
|
1170
|
+
if (fs5.existsSync(candidatePath)) {
|
|
1080
1171
|
return candidatePath;
|
|
1081
1172
|
}
|
|
1082
1173
|
}
|
|
@@ -1116,29 +1207,14 @@ ${withTrailingComma}
|
|
|
1116
1207
|
`;
|
|
1117
1208
|
return next;
|
|
1118
1209
|
}
|
|
1119
|
-
function detectTailwindMajorVersion(projectRoot) {
|
|
1120
|
-
const packageJsonPath = path3.join(projectRoot, "package.json");
|
|
1121
|
-
if (!fs3.existsSync(packageJsonPath)) return 4;
|
|
1122
|
-
try {
|
|
1123
|
-
const raw = fs3.readFileSync(packageJsonPath, "utf-8");
|
|
1124
|
-
const packageJson = JSON.parse(raw);
|
|
1125
|
-
const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
1126
|
-
const twVersion = deps.tailwindcss;
|
|
1127
|
-
if (!twVersion) return 4;
|
|
1128
|
-
const match = twVersion.match(/(\d+)/);
|
|
1129
|
-
return match ? parseInt(match[1], 10) : 4;
|
|
1130
|
-
} catch {
|
|
1131
|
-
return 4;
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
1210
|
async function ensureTW4Plugin(deps, cssFilePath) {
|
|
1135
1211
|
if (!deps.includes("tw-animate-css") && !deps.includes("tailwindcss-animate")) {
|
|
1136
1212
|
return null;
|
|
1137
1213
|
}
|
|
1138
|
-
if (!
|
|
1214
|
+
if (!fs5.existsSync(cssFilePath)) {
|
|
1139
1215
|
return { skipped: true, path: cssFilePath };
|
|
1140
1216
|
}
|
|
1141
|
-
const content = await
|
|
1217
|
+
const content = await fs5.readFile(cssFilePath, "utf-8");
|
|
1142
1218
|
if (content.includes("tw-animate-css") || content.includes("tailwindcss-animate")) {
|
|
1143
1219
|
return { exists: true, path: cssFilePath };
|
|
1144
1220
|
}
|
|
@@ -1153,7 +1229,7 @@ ${importLine}
|
|
|
1153
1229
|
updated = `${importLine}
|
|
1154
1230
|
${content}`;
|
|
1155
1231
|
}
|
|
1156
|
-
await
|
|
1232
|
+
await fs5.writeFile(cssFilePath, updated);
|
|
1157
1233
|
return { updated: true, path: cssFilePath };
|
|
1158
1234
|
}
|
|
1159
1235
|
async function ensureTailwindConfig(deps, projectRoot, configuredFileName) {
|
|
@@ -1161,8 +1237,8 @@ async function ensureTailwindConfig(deps, projectRoot, configuredFileName) {
|
|
|
1161
1237
|
return null;
|
|
1162
1238
|
}
|
|
1163
1239
|
const configPath = detectTailwindConfigPath(projectRoot, configuredFileName || "tailwind.config.js");
|
|
1164
|
-
if (!
|
|
1165
|
-
const ext2 =
|
|
1240
|
+
if (!fs5.existsSync(configPath)) {
|
|
1241
|
+
const ext2 = path5.extname(configPath);
|
|
1166
1242
|
const isCjs2 = ext2 === ".cjs";
|
|
1167
1243
|
const configContent = isCjs2 ? `/** @type {import('tailwindcss').Config} */
|
|
1168
1244
|
module.exports = {
|
|
@@ -1192,15 +1268,15 @@ export default {
|
|
|
1192
1268
|
plugins: [tailwindcssAnimate],
|
|
1193
1269
|
}
|
|
1194
1270
|
`;
|
|
1195
|
-
await
|
|
1196
|
-
await
|
|
1271
|
+
await fs5.ensureDir(path5.dirname(configPath));
|
|
1272
|
+
await fs5.writeFile(configPath, configContent);
|
|
1197
1273
|
return { created: true, path: configPath };
|
|
1198
1274
|
}
|
|
1199
|
-
const currentContent = await
|
|
1275
|
+
const currentContent = await fs5.readFile(configPath, "utf-8");
|
|
1200
1276
|
if (currentContent.includes("tailwindcss-animate")) {
|
|
1201
1277
|
return { exists: true, path: configPath };
|
|
1202
1278
|
}
|
|
1203
|
-
const ext =
|
|
1279
|
+
const ext = path5.extname(configPath);
|
|
1204
1280
|
const isCjs = ext === ".cjs" || /module\.exports\s*=/.test(currentContent);
|
|
1205
1281
|
const pluginExpression = isCjs ? 'require("tailwindcss-animate")' : "tailwindcssAnimate";
|
|
1206
1282
|
let updatedContent = currentContent;
|
|
@@ -1212,7 +1288,7 @@ ${updatedContent}`;
|
|
|
1212
1288
|
if (!merged) {
|
|
1213
1289
|
return { skipped: true, path: configPath };
|
|
1214
1290
|
}
|
|
1215
|
-
await
|
|
1291
|
+
await fs5.writeFile(configPath, merged);
|
|
1216
1292
|
return { updated: true, path: configPath };
|
|
1217
1293
|
}
|
|
1218
1294
|
function escapeRegex(value) {
|
|
@@ -1232,13 +1308,13 @@ function extractExportBlocks(content) {
|
|
|
1232
1308
|
return results;
|
|
1233
1309
|
}
|
|
1234
1310
|
async function handleIndexFile(sourcePath, targetPath, allFilesAdded, targetDir) {
|
|
1235
|
-
const templateContent = stripTemplateDirective(await
|
|
1236
|
-
if (!
|
|
1237
|
-
await
|
|
1238
|
-
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") });
|
|
1239
1315
|
return;
|
|
1240
1316
|
}
|
|
1241
|
-
const existingContent = await
|
|
1317
|
+
const existingContent = await fs5.readFile(targetPath, "utf-8");
|
|
1242
1318
|
const exportBlocks = extractExportBlocks(templateContent);
|
|
1243
1319
|
const blocksToAppend = [];
|
|
1244
1320
|
for (const { block, modulePath } of exportBlocks) {
|
|
@@ -1255,8 +1331,8 @@ async function handleIndexFile(sourcePath, targetPath, allFilesAdded, targetDir)
|
|
|
1255
1331
|
const updatedContent = `${existingContent.trimEnd()}
|
|
1256
1332
|
${blocksToAppend.join("\n")}
|
|
1257
1333
|
`;
|
|
1258
|
-
await
|
|
1259
|
-
const indexPath =
|
|
1334
|
+
await fs5.writeFile(targetPath, updatedContent);
|
|
1335
|
+
const indexPath = path5.join(targetDir, "index.ts");
|
|
1260
1336
|
if (!allFilesAdded.some((f) => f.path === indexPath)) {
|
|
1261
1337
|
allFilesAdded.push({ name: "index.ts", path: indexPath });
|
|
1262
1338
|
}
|
|
@@ -1316,7 +1392,7 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1316
1392
|
spinner.fail("\u274C Component name is required when not using --all or --motion.");
|
|
1317
1393
|
console.log("Available components:");
|
|
1318
1394
|
Object.keys(registry).forEach((name) => {
|
|
1319
|
-
console.log(` ${
|
|
1395
|
+
console.log(` ${chalk2.cyan(name)}`);
|
|
1320
1396
|
});
|
|
1321
1397
|
process.exit(1);
|
|
1322
1398
|
}
|
|
@@ -1325,7 +1401,7 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1325
1401
|
spinner.fail(`\u274C Component "${name}" not found.`);
|
|
1326
1402
|
console.log("Available components:");
|
|
1327
1403
|
Object.keys(registry).forEach((n) => {
|
|
1328
|
-
console.log(` ${
|
|
1404
|
+
console.log(` ${chalk2.cyan(n)}`);
|
|
1329
1405
|
});
|
|
1330
1406
|
process.exit(1);
|
|
1331
1407
|
}
|
|
@@ -1333,7 +1409,7 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1333
1409
|
const { builds, missing } = resolveBuilds(componentNames, Boolean(options.motion));
|
|
1334
1410
|
if (missing.length > 0) {
|
|
1335
1411
|
spinner.fail(`\u274C No motion build for ${missing.map((n) => `"${n}"`).join(", ")}.`);
|
|
1336
|
-
console.log(`Install without --motion, or run ${
|
|
1412
|
+
console.log(`Install without --motion, or run ${chalk2.cyan("dinachi add --motion")} for the motion tier.`);
|
|
1337
1413
|
process.exit(1);
|
|
1338
1414
|
}
|
|
1339
1415
|
const componentsToInstall = withComponentDependencies([
|
|
@@ -1344,8 +1420,8 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1344
1420
|
const componentDir = resolveConfiguredPath(config.aliases.ui, projectRoot, compilerPathConfig);
|
|
1345
1421
|
const libDir = resolveConfiguredPath(config.aliases.lib, projectRoot, compilerPathConfig);
|
|
1346
1422
|
const utilsFilePath = resolveConfiguredPath(config.aliases.utils, projectRoot, compilerPathConfig);
|
|
1347
|
-
await
|
|
1348
|
-
await
|
|
1423
|
+
await fs5.ensureDir(componentDir);
|
|
1424
|
+
await fs5.ensureDir(libDir);
|
|
1349
1425
|
const allFilesAdded = [];
|
|
1350
1426
|
const allDepsInstalled = [];
|
|
1351
1427
|
const allUtilityDeps = [];
|
|
@@ -1363,11 +1439,11 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1363
1439
|
const utility = utilityRegistry[utilityName];
|
|
1364
1440
|
if (!utility) continue;
|
|
1365
1441
|
const utilityFilename = `${utility.name}.ts`;
|
|
1366
|
-
const sourcePath =
|
|
1367
|
-
const targetPath =
|
|
1368
|
-
if (!
|
|
1369
|
-
const content = stripTemplateDirective(await
|
|
1370
|
-
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);
|
|
1371
1447
|
allFilesAdded.push({
|
|
1372
1448
|
name: utilityFilename,
|
|
1373
1449
|
path: targetPath
|
|
@@ -1381,29 +1457,29 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1381
1457
|
for (const name of componentsToInstall) {
|
|
1382
1458
|
const comp = registry[name];
|
|
1383
1459
|
if (!comp) continue;
|
|
1384
|
-
const fileTargetDir = comp.targetDir ?
|
|
1460
|
+
const fileTargetDir = comp.targetDir ? path5.join(libDir, comp.targetDir) : componentDir;
|
|
1385
1461
|
if (comp.targetDir) {
|
|
1386
|
-
await
|
|
1462
|
+
await fs5.ensureDir(fileTargetDir);
|
|
1387
1463
|
}
|
|
1388
1464
|
const build = builds.get(name);
|
|
1389
1465
|
const templateDir = build?.variant.templateDir ?? name;
|
|
1390
1466
|
for (const file of comp.files) {
|
|
1391
|
-
const sourcePath =
|
|
1392
|
-
const targetPath =
|
|
1467
|
+
const sourcePath = path5.join(__dirname2, "../templates", templateDir, file.name);
|
|
1468
|
+
const targetPath = path5.join(fileTargetDir, file.name);
|
|
1393
1469
|
if (file.name === "index.ts") {
|
|
1394
1470
|
if (comp.targetDir) {
|
|
1395
|
-
const templateContent2 = stripTemplateDirective(await
|
|
1396
|
-
await
|
|
1471
|
+
const templateContent2 = stripTemplateDirective(await fs5.readFile(sourcePath, "utf-8"));
|
|
1472
|
+
await fs5.writeFile(targetPath, templateContent2);
|
|
1397
1473
|
allFilesAdded.push({ name: "index.ts", path: targetPath });
|
|
1398
1474
|
} else {
|
|
1399
1475
|
await handleIndexFile(sourcePath, targetPath, allFilesAdded, fileTargetDir);
|
|
1400
1476
|
}
|
|
1401
1477
|
continue;
|
|
1402
1478
|
}
|
|
1403
|
-
if (
|
|
1479
|
+
if (fs5.existsSync(targetPath) && !options.overwrite) {
|
|
1404
1480
|
if (options.yes) {
|
|
1405
1481
|
spinner.stop();
|
|
1406
|
-
console.log(` ${
|
|
1482
|
+
console.log(` ${chalk2.yellow("\u2298")} Kept existing ${file.name} (pass --overwrite to replace it)`);
|
|
1407
1483
|
spinner.start();
|
|
1408
1484
|
continue;
|
|
1409
1485
|
}
|
|
@@ -1415,15 +1491,15 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1415
1491
|
initial: false
|
|
1416
1492
|
});
|
|
1417
1493
|
if (!overwrite) {
|
|
1418
|
-
console.log(` ${
|
|
1494
|
+
console.log(` ${chalk2.yellow("\u2298")} Skipped ${file.name}`);
|
|
1419
1495
|
spinner.start();
|
|
1420
1496
|
continue;
|
|
1421
1497
|
}
|
|
1422
1498
|
spinner.start();
|
|
1423
1499
|
}
|
|
1424
|
-
const templateContent = stripTemplateDirective(await
|
|
1500
|
+
const templateContent = stripTemplateDirective(await fs5.readFile(sourcePath, "utf-8"));
|
|
1425
1501
|
const rewrittenContent = rewriteTemplateImports(templateContent, targetPath, utilsFilePath, componentDir, compilerPathConfig);
|
|
1426
|
-
await
|
|
1502
|
+
await fs5.writeFile(targetPath, rewrittenContent);
|
|
1427
1503
|
allFilesAdded.push({ name: file.name, path: targetPath });
|
|
1428
1504
|
}
|
|
1429
1505
|
if (comp.dependencies?.length) {
|
|
@@ -1433,12 +1509,12 @@ var addCommand = new Command("add").description("Add a component to your project
|
|
|
1433
1509
|
allDepsInstalled.push(...build.variant.dependencies);
|
|
1434
1510
|
}
|
|
1435
1511
|
if (name === "toast") {
|
|
1436
|
-
const toastLibPath =
|
|
1437
|
-
if (!
|
|
1512
|
+
const toastLibPath = path5.join(libDir, "toast.ts");
|
|
1513
|
+
if (!fs5.existsSync(toastLibPath)) {
|
|
1438
1514
|
const toastContent = `import { createToastManager } from "${config.aliases.ui}/toast";
|
|
1439
1515
|
export const toastManager = createToastManager();
|
|
1440
1516
|
`;
|
|
1441
|
-
await
|
|
1517
|
+
await fs5.writeFile(toastLibPath, toastContent);
|
|
1442
1518
|
allFilesAdded.push({ name: "toast.ts", path: toastLibPath });
|
|
1443
1519
|
}
|
|
1444
1520
|
}
|
|
@@ -1458,17 +1534,17 @@ export const toastManager = createToastManager();
|
|
|
1458
1534
|
}
|
|
1459
1535
|
const tailwindConfigInfo = tailwindMajor >= 4 ? await ensureTW4Plugin(
|
|
1460
1536
|
allDepsInstalled,
|
|
1461
|
-
|
|
1537
|
+
path5.resolve(projectRoot, config.tailwind?.css || "src/index.css")
|
|
1462
1538
|
) : await ensureTailwindConfig(
|
|
1463
1539
|
allDepsInstalled,
|
|
1464
1540
|
projectRoot,
|
|
1465
1541
|
config.tailwind?.config || "tailwind.config.js"
|
|
1466
1542
|
);
|
|
1467
|
-
const packageJsonPath =
|
|
1468
|
-
if (!
|
|
1543
|
+
const packageJsonPath = path5.join(projectRoot, "package.json");
|
|
1544
|
+
if (!fs5.existsSync(packageJsonPath)) {
|
|
1469
1545
|
throw new Error("No package.json found in the current directory.");
|
|
1470
1546
|
}
|
|
1471
|
-
const packageJson = JSON.parse(await
|
|
1547
|
+
const packageJson = JSON.parse(await fs5.readFile(packageJsonPath, "utf-8"));
|
|
1472
1548
|
const declaredDeps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
1473
1549
|
const uniqueDeps = [...new Set(allDepsInstalled)];
|
|
1474
1550
|
const missingDeps = uniqueDeps.filter((dep) => !declaredDeps[dep]);
|
|
@@ -1492,18 +1568,18 @@ export const toastManager = createToastManager();
|
|
|
1492
1568
|
console.log();
|
|
1493
1569
|
console.log("Files added:");
|
|
1494
1570
|
allFilesAdded.forEach((file) => {
|
|
1495
|
-
console.log(` ${
|
|
1571
|
+
console.log(` ${chalk2.green("+")} ${file.path}`);
|
|
1496
1572
|
});
|
|
1497
1573
|
if (tailwindConfigInfo) {
|
|
1498
1574
|
const animatePackage = tailwindMajor >= 4 ? "tw-animate-css" : "tailwindcss-animate";
|
|
1499
1575
|
console.log();
|
|
1500
1576
|
if (tailwindConfigInfo.created) {
|
|
1501
|
-
console.log(` ${
|
|
1577
|
+
console.log(` ${chalk2.green("+")} ${tailwindConfigInfo.path} (created with ${animatePackage} plugin)`);
|
|
1502
1578
|
} else if (tailwindConfigInfo.updated) {
|
|
1503
|
-
console.log(` ${
|
|
1579
|
+
console.log(` ${chalk2.blue("~")} ${tailwindConfigInfo.path} (updated with ${animatePackage} plugin)`);
|
|
1504
1580
|
} else if (tailwindConfigInfo.skipped) {
|
|
1505
1581
|
console.log(
|
|
1506
|
-
` ${
|
|
1582
|
+
` ${chalk2.yellow("!")} ${tailwindConfigInfo.path} (could not safely update automatically; add ${animatePackage} manually)`
|
|
1507
1583
|
);
|
|
1508
1584
|
}
|
|
1509
1585
|
}
|
|
@@ -1511,19 +1587,19 @@ export const toastManager = createToastManager();
|
|
|
1511
1587
|
console.log();
|
|
1512
1588
|
console.log("Dependencies to install manually:");
|
|
1513
1589
|
missingDeps.forEach((dep) => {
|
|
1514
|
-
console.log(` ${
|
|
1590
|
+
console.log(` ${chalk2.yellow("\u2022")} ${toInstallSpec(dep)}`);
|
|
1515
1591
|
});
|
|
1516
1592
|
} else if (missingDeps.length > 0) {
|
|
1517
1593
|
console.log();
|
|
1518
1594
|
console.log("Dependencies installed:");
|
|
1519
1595
|
missingDeps.forEach((dep) => {
|
|
1520
|
-
console.log(` ${
|
|
1596
|
+
console.log(` ${chalk2.green("\u2713")} ${toInstallSpec(dep)}`);
|
|
1521
1597
|
});
|
|
1522
1598
|
} else if (uniqueDeps.length > 0) {
|
|
1523
1599
|
console.log();
|
|
1524
1600
|
console.log("Dependencies (already installed):");
|
|
1525
1601
|
uniqueDeps.forEach((dep) => {
|
|
1526
|
-
console.log(` ${
|
|
1602
|
+
console.log(` ${chalk2.blue("~")} ${dep}`);
|
|
1527
1603
|
});
|
|
1528
1604
|
}
|
|
1529
1605
|
const unselected = componentsToInstall.flatMap(
|
|
@@ -1533,10 +1609,11 @@ export const toastManager = createToastManager();
|
|
|
1533
1609
|
console.log();
|
|
1534
1610
|
console.log("Also available in another build:");
|
|
1535
1611
|
unselected.forEach(({ name, flag, variant }) => {
|
|
1536
|
-
console.log(` ${
|
|
1537
|
-
console.log(` ${
|
|
1612
|
+
console.log(` ${chalk2.cyan(name)} ${chalk2.dim(`\u2014 ${variant.description}`)}`);
|
|
1613
|
+
console.log(` ${chalk2.dim(`dinachi add ${name} --${flag} --overwrite`)}`);
|
|
1538
1614
|
});
|
|
1539
1615
|
}
|
|
1616
|
+
warnIfSkillStale(process.cwd());
|
|
1540
1617
|
} catch (error) {
|
|
1541
1618
|
spinner.fail(`\u274C Failed to add component: ${error instanceof Error ? error.message : error}`);
|
|
1542
1619
|
process.exit(1);
|
|
@@ -1547,14 +1624,14 @@ export const toastManager = createToastManager();
|
|
|
1547
1624
|
// src/commands/init.ts
|
|
1548
1625
|
import { Command as Command2 } from "commander";
|
|
1549
1626
|
import { execSync as execSync2 } from "child_process";
|
|
1550
|
-
import
|
|
1551
|
-
import
|
|
1627
|
+
import fs6 from "fs-extra";
|
|
1628
|
+
import path6 from "path";
|
|
1552
1629
|
import prompts2 from "prompts";
|
|
1553
|
-
import
|
|
1630
|
+
import chalk3 from "chalk";
|
|
1554
1631
|
import ora2 from "ora";
|
|
1555
1632
|
function normalizeProjectPath(inputPath, projectRoot) {
|
|
1556
|
-
const absolutePath =
|
|
1557
|
-
const relativePath =
|
|
1633
|
+
const absolutePath = path6.isAbsolute(inputPath) ? path6.normalize(inputPath) : path6.resolve(projectRoot, inputPath);
|
|
1634
|
+
const relativePath = path6.relative(projectRoot, absolutePath).replace(/\\/g, "/");
|
|
1558
1635
|
const withoutPrefix = relativePath.replace(/^\.\//, "").replace(/\/$/, "");
|
|
1559
1636
|
return withoutPrefix.length > 0 ? withoutPrefix : ".";
|
|
1560
1637
|
}
|
|
@@ -1570,21 +1647,6 @@ export function cn(...inputs: ClassValue[]) {
|
|
|
1570
1647
|
}
|
|
1571
1648
|
`;
|
|
1572
1649
|
}
|
|
1573
|
-
function detectTailwindMajorVersion2(projectRoot) {
|
|
1574
|
-
const packageJsonPath = path4.join(projectRoot, "package.json");
|
|
1575
|
-
if (!fs4.existsSync(packageJsonPath)) return 4;
|
|
1576
|
-
try {
|
|
1577
|
-
const raw = fs4.readFileSync(packageJsonPath, "utf-8");
|
|
1578
|
-
const packageJson = JSON.parse(raw);
|
|
1579
|
-
const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
1580
|
-
const twVersion = deps.tailwindcss;
|
|
1581
|
-
if (!twVersion) return 4;
|
|
1582
|
-
const match = twVersion.match(/(\d+)/);
|
|
1583
|
-
return match ? parseInt(match[1], 10) : 4;
|
|
1584
|
-
} catch {
|
|
1585
|
-
return 4;
|
|
1586
|
-
}
|
|
1587
|
-
}
|
|
1588
1650
|
var DINACHI_THEME_PREFIXES = ["--color-", "--radius-", "--shadow-", "--shadow:"];
|
|
1589
1651
|
function extractPreservedThemeVars(css) {
|
|
1590
1652
|
const themeMatch = css.match(/@theme\s+inline\s*\{([^}]*)\}/);
|
|
@@ -1800,9 +1862,9 @@ function stripConflictingCSS(css) {
|
|
|
1800
1862
|
return result.trim();
|
|
1801
1863
|
}
|
|
1802
1864
|
async function injectThemeCSS(cssFilePath, tailwindMajor) {
|
|
1803
|
-
await
|
|
1804
|
-
if (
|
|
1805
|
-
const existing = await
|
|
1865
|
+
await fs6.ensureDir(path6.dirname(cssFilePath));
|
|
1866
|
+
if (fs6.existsSync(cssFilePath)) {
|
|
1867
|
+
const existing = await fs6.readFile(cssFilePath, "utf-8");
|
|
1806
1868
|
if (existing.includes("--primary:")) {
|
|
1807
1869
|
return { path: cssFilePath, skipped: true };
|
|
1808
1870
|
}
|
|
@@ -1813,11 +1875,11 @@ async function injectThemeCSS(cssFilePath, tailwindMajor) {
|
|
|
1813
1875
|
|
|
1814
1876
|
`, "");
|
|
1815
1877
|
const result = cleaned.length > 0 ? cleaned + "\n\n" + theme2 : getThemeCSS(tailwindMajor, "full", preservedVars);
|
|
1816
|
-
await
|
|
1878
|
+
await fs6.writeFile(cssFilePath, result);
|
|
1817
1879
|
return { path: cssFilePath, updated: true };
|
|
1818
1880
|
}
|
|
1819
1881
|
const theme = getThemeCSS(tailwindMajor, "full");
|
|
1820
|
-
await
|
|
1882
|
+
await fs6.writeFile(cssFilePath, theme);
|
|
1821
1883
|
return { path: cssFilePath, created: true };
|
|
1822
1884
|
}
|
|
1823
1885
|
function getTW3ColorExtend() {
|
|
@@ -1924,20 +1986,20 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1924
1986
|
];
|
|
1925
1987
|
let configPath = null;
|
|
1926
1988
|
for (const candidate of candidates) {
|
|
1927
|
-
const candidatePath =
|
|
1928
|
-
if (
|
|
1989
|
+
const candidatePath = path6.join(projectRoot, candidate);
|
|
1990
|
+
if (fs6.existsSync(candidatePath)) {
|
|
1929
1991
|
configPath = candidatePath;
|
|
1930
1992
|
break;
|
|
1931
1993
|
}
|
|
1932
1994
|
}
|
|
1933
1995
|
if (!configPath) {
|
|
1934
|
-
configPath =
|
|
1935
|
-
const ext =
|
|
1996
|
+
configPath = path6.join(projectRoot, configFileName);
|
|
1997
|
+
const ext = path6.extname(configPath);
|
|
1936
1998
|
const isCjs = ext === ".cjs";
|
|
1937
|
-
await
|
|
1999
|
+
await fs6.writeFile(configPath, createTW3Config(isCjs));
|
|
1938
2000
|
return { path: configPath, created: true };
|
|
1939
2001
|
}
|
|
1940
|
-
const content = await
|
|
2002
|
+
const content = await fs6.readFile(configPath, "utf-8");
|
|
1941
2003
|
if (content.includes('"var(--primary)"') || content.includes("'var(--primary)'")) {
|
|
1942
2004
|
return { path: configPath, skipped: true };
|
|
1943
2005
|
}
|
|
@@ -1946,7 +2008,7 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1946
2008
|
if (extendMatch && extendMatch.index !== void 0) {
|
|
1947
2009
|
const insertPos = extendMatch.index + extendMatch[0].length;
|
|
1948
2010
|
const updated = content.slice(0, insertPos) + "\n " + colorExtend + content.slice(insertPos);
|
|
1949
|
-
await
|
|
2011
|
+
await fs6.writeFile(configPath, updated);
|
|
1950
2012
|
return { path: configPath, updated: true };
|
|
1951
2013
|
}
|
|
1952
2014
|
const themeMatch = content.match(/theme\s*:\s*\{/);
|
|
@@ -1957,7 +2019,7 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1957
2019
|
${colorExtend}
|
|
1958
2020
|
},`;
|
|
1959
2021
|
const updated = content.slice(0, insertPos) + extendBlock + content.slice(insertPos);
|
|
1960
|
-
await
|
|
2022
|
+
await fs6.writeFile(configPath, updated);
|
|
1961
2023
|
return { path: configPath, updated: true };
|
|
1962
2024
|
}
|
|
1963
2025
|
const closingBrace = content.lastIndexOf("}");
|
|
@@ -1972,24 +2034,24 @@ async function ensureTW3ColorConfig(projectRoot, configFileName) {
|
|
|
1972
2034
|
},
|
|
1973
2035
|
`;
|
|
1974
2036
|
const updated = before + themeBlock + content.slice(closingBrace);
|
|
1975
|
-
await
|
|
2037
|
+
await fs6.writeFile(configPath, updated);
|
|
1976
2038
|
return { path: configPath, updated: true };
|
|
1977
2039
|
}
|
|
1978
2040
|
return { path: configPath, skipped: true };
|
|
1979
2041
|
}
|
|
1980
2042
|
function readJsonConfig(filePath) {
|
|
1981
2043
|
try {
|
|
1982
|
-
const content =
|
|
2044
|
+
const content = fs6.readFileSync(filePath, "utf-8");
|
|
1983
2045
|
return parseJsonWithComments(content);
|
|
1984
2046
|
} catch {
|
|
1985
2047
|
return null;
|
|
1986
2048
|
}
|
|
1987
2049
|
}
|
|
1988
2050
|
async function ensureAtAlias(projectRoot, srcDir, isTypeScript) {
|
|
1989
|
-
const tsConfigPath =
|
|
1990
|
-
const jsConfigPath =
|
|
1991
|
-
const configPath =
|
|
1992
|
-
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);
|
|
1993
2055
|
const parsedConfig = readJsonConfig(configPath);
|
|
1994
2056
|
if (existedBefore && !parsedConfig) {
|
|
1995
2057
|
return { path: configPath, skipped: true };
|
|
@@ -2026,7 +2088,7 @@ async function ensureAtAlias(projectRoot, srcDir, isTypeScript) {
|
|
|
2026
2088
|
}
|
|
2027
2089
|
};
|
|
2028
2090
|
try {
|
|
2029
|
-
await
|
|
2091
|
+
await fs6.writeFile(configPath, `${JSON.stringify(nextConfig, null, 2)}
|
|
2030
2092
|
`);
|
|
2031
2093
|
return { path: configPath, [existedBefore ? "updated" : "created"]: true };
|
|
2032
2094
|
} catch {
|
|
@@ -2034,24 +2096,24 @@ async function ensureAtAlias(projectRoot, srcDir, isTypeScript) {
|
|
|
2034
2096
|
}
|
|
2035
2097
|
}
|
|
2036
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) => {
|
|
2037
|
-
console.log(
|
|
2099
|
+
console.log(chalk3.bold.cyan("\u{1F3A8} Welcome to Dinachi UI!"));
|
|
2038
2100
|
console.log();
|
|
2039
2101
|
const projectRoot = process.cwd();
|
|
2040
|
-
const packageJsonPath =
|
|
2041
|
-
if (!
|
|
2042
|
-
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."));
|
|
2043
2105
|
process.exit(1);
|
|
2044
2106
|
}
|
|
2045
2107
|
const projectConfig = detectProjectType();
|
|
2046
|
-
console.log(
|
|
2108
|
+
console.log(chalk3.gray(`Detected ${projectConfig.framework} project`));
|
|
2047
2109
|
console.log();
|
|
2048
2110
|
let componentsPath;
|
|
2049
2111
|
let utilsPath;
|
|
2050
2112
|
if (options.yes) {
|
|
2051
2113
|
componentsPath = projectConfig.componentsPath;
|
|
2052
2114
|
utilsPath = projectConfig.utilsPath;
|
|
2053
|
-
console.log(
|
|
2054
|
-
console.log(
|
|
2115
|
+
console.log(chalk3.gray(`Components: ${componentsPath}`));
|
|
2116
|
+
console.log(chalk3.gray(`Utilities: ${utilsPath}`));
|
|
2055
2117
|
console.log();
|
|
2056
2118
|
} else {
|
|
2057
2119
|
const response = await prompts2([
|
|
@@ -2069,7 +2131,7 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
2069
2131
|
}
|
|
2070
2132
|
]);
|
|
2071
2133
|
if (!response.componentsPath || !response.utilsPath) {
|
|
2072
|
-
console.log(
|
|
2134
|
+
console.log(chalk3.red("\u274C Setup cancelled."));
|
|
2073
2135
|
process.exit(1);
|
|
2074
2136
|
}
|
|
2075
2137
|
componentsPath = response.componentsPath;
|
|
@@ -2079,16 +2141,16 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
2079
2141
|
try {
|
|
2080
2142
|
const normalizedComponentsPath = normalizeProjectPath(componentsPath, projectRoot);
|
|
2081
2143
|
const normalizedUtilsPath = normalizeProjectPath(utilsPath, projectRoot);
|
|
2082
|
-
const componentsDirPath =
|
|
2083
|
-
const utilsDirPath =
|
|
2084
|
-
const utilsFilePath =
|
|
2085
|
-
await
|
|
2086
|
-
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);
|
|
2087
2149
|
const utilsContent = createUtilsFileContent();
|
|
2088
|
-
await
|
|
2150
|
+
await fs6.writeFile(utilsFilePath, utilsContent);
|
|
2089
2151
|
spinner.text = "Setting up color theme...";
|
|
2090
|
-
const tailwindMajor =
|
|
2091
|
-
const cssFilePath =
|
|
2152
|
+
const tailwindMajor = detectTailwindMajorVersion(projectRoot);
|
|
2153
|
+
const cssFilePath = path6.resolve(projectRoot, projectConfig.cssPath);
|
|
2092
2154
|
const themeCSSResult = await injectThemeCSS(cssFilePath, tailwindMajor);
|
|
2093
2155
|
let twColorConfigResult = null;
|
|
2094
2156
|
if (tailwindMajor < 4) {
|
|
@@ -2102,7 +2164,7 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
2102
2164
|
const installCmd = getInstallCommand(packageManager, deps.map(toInstallSpec));
|
|
2103
2165
|
execSync2(installCmd, { stdio: "inherit", cwd: projectRoot });
|
|
2104
2166
|
}
|
|
2105
|
-
const hooksPath = projectConfig.srcDir === "." ? "hooks" :
|
|
2167
|
+
const hooksPath = projectConfig.srcDir === "." ? "hooks" : path6.join(projectConfig.srcDir, "hooks").replace(/\\/g, "/");
|
|
2106
2168
|
const configContent = JSON.stringify(
|
|
2107
2169
|
{
|
|
2108
2170
|
style: "default",
|
|
@@ -2115,8 +2177,8 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
2115
2177
|
cssVariables: true
|
|
2116
2178
|
},
|
|
2117
2179
|
aliases: {
|
|
2118
|
-
components: toConfigPath(
|
|
2119
|
-
utils: toConfigPath(
|
|
2180
|
+
components: toConfigPath(path6.dirname(normalizedComponentsPath)),
|
|
2181
|
+
utils: toConfigPath(path6.join(normalizedUtilsPath, "utils")),
|
|
2120
2182
|
ui: toConfigPath(normalizedComponentsPath),
|
|
2121
2183
|
lib: toConfigPath(normalizedUtilsPath),
|
|
2122
2184
|
hooks: toConfigPath(hooksPath)
|
|
@@ -2126,102 +2188,108 @@ var initCommand = new Command2("init").description("Initialize Dinachi UI in you
|
|
|
2126
2188
|
null,
|
|
2127
2189
|
2
|
|
2128
2190
|
);
|
|
2129
|
-
await
|
|
2191
|
+
await fs6.writeFile(path6.join(projectRoot, "components.json"), `${configContent}
|
|
2130
2192
|
`);
|
|
2131
2193
|
const aliasConfigUpdate = await ensureAtAlias(projectRoot, projectConfig.srcDir, projectConfig.isTypeScript);
|
|
2132
2194
|
spinner.succeed("\u2705 Dinachi UI setup complete!");
|
|
2133
2195
|
console.log();
|
|
2134
2196
|
console.log("Next steps:");
|
|
2135
|
-
console.log(` 1. Add a component: ${
|
|
2136
|
-
console.log(` 2. Components will be installed to: ${
|
|
2137
|
-
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)}`);
|
|
2138
2200
|
console.log();
|
|
2139
2201
|
if (aliasConfigUpdate.created) {
|
|
2140
|
-
console.log(` ${
|
|
2202
|
+
console.log(` ${chalk3.green("+")} Added @/* path alias in ${aliasConfigUpdate.path}`);
|
|
2141
2203
|
} else if (aliasConfigUpdate.updated) {
|
|
2142
|
-
console.log(` ${
|
|
2204
|
+
console.log(` ${chalk3.blue("~")} Updated @/* path alias in ${aliasConfigUpdate.path}`);
|
|
2143
2205
|
} else if (aliasConfigUpdate.skipped) {
|
|
2144
2206
|
console.log(
|
|
2145
|
-
` ${
|
|
2207
|
+
` ${chalk3.yellow("!")} Could not update ${aliasConfigUpdate.path}. Configure @/* manually if you use alias imports.`
|
|
2146
2208
|
);
|
|
2147
2209
|
}
|
|
2148
2210
|
if (themeCSSResult.created) {
|
|
2149
|
-
console.log(` ${
|
|
2211
|
+
console.log(` ${chalk3.green("+")} Created ${projectConfig.cssPath} with color theme (light + dark)`);
|
|
2150
2212
|
} else if (themeCSSResult.updated) {
|
|
2151
|
-
console.log(` ${
|
|
2213
|
+
console.log(` ${chalk3.blue("~")} Updated ${projectConfig.cssPath} with color theme (light + dark)`);
|
|
2152
2214
|
} else if (themeCSSResult.skipped) {
|
|
2153
|
-
console.log(` ${
|
|
2215
|
+
console.log(` ${chalk3.gray("-")} Color theme already configured in ${projectConfig.cssPath}`);
|
|
2154
2216
|
}
|
|
2155
2217
|
if (twColorConfigResult) {
|
|
2156
2218
|
if (twColorConfigResult.created) {
|
|
2157
|
-
console.log(` ${
|
|
2219
|
+
console.log(` ${chalk3.green("+")} Created ${projectConfig.tailwindConfig} with color mappings`);
|
|
2158
2220
|
} else if (twColorConfigResult.updated) {
|
|
2159
|
-
console.log(` ${
|
|
2221
|
+
console.log(` ${chalk3.blue("~")} Updated ${projectConfig.tailwindConfig} with color mappings`);
|
|
2160
2222
|
} else if (twColorConfigResult.skipped) {
|
|
2161
|
-
console.log(` ${
|
|
2223
|
+
console.log(` ${chalk3.gray("-")} Color mappings already in ${projectConfig.tailwindConfig}`);
|
|
2162
2224
|
}
|
|
2163
2225
|
}
|
|
2164
2226
|
if (!projectConfig.isTypeScript) {
|
|
2165
2227
|
console.log();
|
|
2166
2228
|
console.log(
|
|
2167
|
-
|
|
2229
|
+
chalk3.yellow(
|
|
2168
2230
|
"\u26A0\uFE0F Dinachi components are TypeScript-first. Your project can still consume TSX files, but type-check tooling is recommended."
|
|
2169
2231
|
)
|
|
2170
2232
|
);
|
|
2171
2233
|
}
|
|
2172
2234
|
if (projectConfig.framework === "next.js") {
|
|
2173
2235
|
console.log();
|
|
2174
|
-
console.log(
|
|
2236
|
+
console.log(chalk3.blue("\u{1F4DD} Next.js specific notes:"));
|
|
2175
2237
|
console.log(" - RSC (React Server Components) enabled in config");
|
|
2176
2238
|
console.log(' - Add "use client" for interactive components where needed');
|
|
2177
|
-
console.log(` - Tailwind config: ${
|
|
2239
|
+
console.log(` - Tailwind config: ${chalk3.cyan(projectConfig.tailwindConfig)}`);
|
|
2178
2240
|
} else if (projectConfig.framework === "remix") {
|
|
2179
2241
|
console.log();
|
|
2180
|
-
console.log(
|
|
2181
|
-
console.log(` - Components directory: ${
|
|
2182
|
-
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)}`);
|
|
2183
2245
|
}
|
|
2184
2246
|
if (options.skipInstall) {
|
|
2185
2247
|
console.log();
|
|
2186
2248
|
console.log("Dependencies to install manually:");
|
|
2187
|
-
console.log(` ${
|
|
2249
|
+
console.log(` ${chalk3.cyan(getInstallCommand(detectPackageManager(projectRoot), deps.map(toInstallSpec)))}`);
|
|
2188
2250
|
}
|
|
2189
2251
|
console.log();
|
|
2190
2252
|
console.log("\u{1F4A1} Tip: Install globally for shorter commands:");
|
|
2191
|
-
console.log(` ${
|
|
2192
|
-
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);
|
|
2193
2256
|
} catch (error) {
|
|
2194
2257
|
spinner.fail(`\u274C Setup failed: ${error.message}`);
|
|
2195
2258
|
process.exit(1);
|
|
2196
2259
|
}
|
|
2197
2260
|
});
|
|
2198
2261
|
function detectRsc(projectRoot, framework) {
|
|
2199
|
-
const configPath =
|
|
2200
|
-
if (
|
|
2262
|
+
const configPath = path6.join(projectRoot, "components.json");
|
|
2263
|
+
if (fs6.existsSync(configPath)) {
|
|
2201
2264
|
try {
|
|
2202
|
-
const existing = JSON.parse(
|
|
2265
|
+
const existing = JSON.parse(fs6.readFileSync(configPath, "utf-8"));
|
|
2203
2266
|
if (typeof existing.rsc === "boolean") return existing.rsc;
|
|
2204
2267
|
} catch {
|
|
2205
2268
|
}
|
|
2206
2269
|
}
|
|
2207
2270
|
if (framework !== "next.js") return false;
|
|
2208
|
-
const hasAppRouter =
|
|
2209
|
-
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"));
|
|
2210
2273
|
if (hasAppRouter) return true;
|
|
2211
2274
|
if (hasPagesRouter) return false;
|
|
2212
2275
|
return true;
|
|
2213
2276
|
}
|
|
2214
2277
|
function detectProjectType() {
|
|
2215
|
-
const packageJsonPath =
|
|
2216
|
-
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 {
|
|
2217
2286
|
return getDefaultConfig("react", false);
|
|
2218
2287
|
}
|
|
2219
|
-
const packageJson = JSON.parse(fs4.readFileSync(packageJsonPath, "utf-8"));
|
|
2220
2288
|
const deps = { ...packageJson.dependencies ?? {}, ...packageJson.devDependencies ?? {} };
|
|
2221
|
-
const hasSrcDir =
|
|
2222
|
-
const hasAppDir =
|
|
2223
|
-
const hasSrcAppDir =
|
|
2224
|
-
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);
|
|
2225
2293
|
const tailwindConfig = detectTailwindConfig();
|
|
2226
2294
|
const cssPath = detectCssPath(hasSrcDir, hasSrcAppDir);
|
|
2227
2295
|
if (deps.next) {
|
|
@@ -2293,7 +2361,7 @@ function detectProjectType() {
|
|
|
2293
2361
|
return getDefaultConfig("react", hasSrcDir);
|
|
2294
2362
|
}
|
|
2295
2363
|
function getDefaultConfig(framework, hasSrcDir) {
|
|
2296
|
-
const isTypeScript =
|
|
2364
|
+
const isTypeScript = fs6.existsSync(path6.join(process.cwd(), "tsconfig.json")) || fs6.existsSync(path6.join(process.cwd(), "tsconfig.base.json"));
|
|
2297
2365
|
return {
|
|
2298
2366
|
framework,
|
|
2299
2367
|
componentsPath: hasSrcDir ? "./src/components/ui" : "./components/ui",
|
|
@@ -2314,7 +2382,7 @@ function detectTailwindConfig() {
|
|
|
2314
2382
|
"tailwind.config.mts"
|
|
2315
2383
|
];
|
|
2316
2384
|
for (const config of configCandidates) {
|
|
2317
|
-
if (
|
|
2385
|
+
if (fs6.existsSync(path6.join(process.cwd(), config))) {
|
|
2318
2386
|
return config;
|
|
2319
2387
|
}
|
|
2320
2388
|
}
|
|
@@ -2333,7 +2401,7 @@ function detectCssPath(hasSrcDir, hasSrcAppDir, isRemix = false) {
|
|
|
2333
2401
|
"app/styles/tailwind.css"
|
|
2334
2402
|
];
|
|
2335
2403
|
for (const cssPath of possiblePaths) {
|
|
2336
|
-
if (
|
|
2404
|
+
if (fs6.existsSync(path6.join(cwd, cssPath))) {
|
|
2337
2405
|
return cssPath;
|
|
2338
2406
|
}
|
|
2339
2407
|
}
|
|
@@ -2343,22 +2411,166 @@ function detectCssPath(hasSrcDir, hasSrcAppDir, isRemix = false) {
|
|
|
2343
2411
|
return "index.css";
|
|
2344
2412
|
}
|
|
2345
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
|
+
|
|
2346
2558
|
// src/index.ts
|
|
2347
|
-
import
|
|
2348
|
-
import
|
|
2559
|
+
import fs8 from "fs";
|
|
2560
|
+
import path8 from "path";
|
|
2349
2561
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
2350
|
-
var program = new
|
|
2562
|
+
var program = new Command4();
|
|
2351
2563
|
var __filename3 = fileURLToPath3(import.meta.url);
|
|
2352
|
-
var __dirname3 =
|
|
2564
|
+
var __dirname3 = path8.dirname(__filename3);
|
|
2353
2565
|
function getCliVersion() {
|
|
2354
2566
|
try {
|
|
2355
|
-
const packageJsonPath =
|
|
2356
|
-
const packageJson = JSON.parse(
|
|
2567
|
+
const packageJsonPath = path8.resolve(__dirname3, "../package.json");
|
|
2568
|
+
const packageJson = JSON.parse(fs8.readFileSync(packageJsonPath, "utf-8"));
|
|
2357
2569
|
return packageJson.version ?? "0.0.0";
|
|
2358
2570
|
} catch {
|
|
2359
2571
|
return "0.0.0";
|
|
2360
2572
|
}
|
|
2361
2573
|
}
|
|
2362
2574
|
program.name("dinachi").description("Add Dinachi UI components to your project").version(getCliVersion());
|
|
2363
|
-
program.addCommand(addCommand).addCommand(initCommand);
|
|
2575
|
+
program.addCommand(addCommand).addCommand(initCommand).addCommand(createInfoCommand(getCliVersion()));
|
|
2364
2576
|
program.parse();
|