@foundrykit/cli 1.0.3 → 1.0.4
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 +8 -0
- package/dist/cli.js +83 -75
- package/dist/cli.js.map +1 -1
- package/dist/index.js +83 -75
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/commands/add.ts +99 -88
- package/src/commands/init.ts +12 -5
package/CHANGELOG.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -345,7 +345,14 @@ async function updateLayoutImport(globalCssPath) {
|
|
|
345
345
|
}
|
|
346
346
|
async function createDirectories() {
|
|
347
347
|
console.log(chalk.blue("\u{1F4C1} Creating component directories..."));
|
|
348
|
-
const dirs = [
|
|
348
|
+
const dirs = [
|
|
349
|
+
"components/primitives",
|
|
350
|
+
"components/components",
|
|
351
|
+
"components/blocks",
|
|
352
|
+
"components/animations",
|
|
353
|
+
"lib",
|
|
354
|
+
"hooks"
|
|
355
|
+
];
|
|
349
356
|
for (const dir of dirs) {
|
|
350
357
|
await fs.ensureDir(path.join(process.cwd(), dir));
|
|
351
358
|
}
|
|
@@ -414,8 +421,8 @@ async function createConfigFile(options) {
|
|
|
414
421
|
registry: "https://foundry.umiflow.com",
|
|
415
422
|
paths: {
|
|
416
423
|
utils: "./src/lib/utils.ts",
|
|
417
|
-
primitives: "./src/components/
|
|
418
|
-
components: "./src/components",
|
|
424
|
+
primitives: "./src/components/primitives",
|
|
425
|
+
components: "./src/components/components",
|
|
419
426
|
blocks: "./src/components/blocks",
|
|
420
427
|
hooks: "./src/hooks",
|
|
421
428
|
animations: "./src/components/animations"
|
|
@@ -439,8 +446,8 @@ async function createConfigFile(options) {
|
|
|
439
446
|
if (hasAppDir && !fs.existsSync(path.join(process.cwd(), "src/app"))) {
|
|
440
447
|
config.paths = {
|
|
441
448
|
utils: "./lib/utils.ts",
|
|
442
|
-
primitives: "./components/
|
|
443
|
-
components: "./components",
|
|
449
|
+
primitives: "./components/primitives",
|
|
450
|
+
components: "./components/components",
|
|
444
451
|
blocks: "./components/blocks",
|
|
445
452
|
hooks: "./hooks",
|
|
446
453
|
animations: "./components/animations"
|
|
@@ -935,14 +942,6 @@ async function addSingleComponent(id, options) {
|
|
|
935
942
|
console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
|
|
936
943
|
for (const dep of componentData.registryDependencies) {
|
|
937
944
|
try {
|
|
938
|
-
if (dep === "primitives") {
|
|
939
|
-
console.log(
|
|
940
|
-
chalk4.gray(
|
|
941
|
-
` \u23ED Skipping "${dep}" - primitive dependencies will be handled separately`
|
|
942
|
-
)
|
|
943
|
-
);
|
|
944
|
-
continue;
|
|
945
|
-
}
|
|
946
945
|
const depData = await registry.getComponent(dep);
|
|
947
946
|
const hasExisting = await hasConflictingFiles(depData, options);
|
|
948
947
|
if (!hasExisting) {
|
|
@@ -976,22 +975,21 @@ async function validateProject2() {
|
|
|
976
975
|
"No package.json found. Please run this command in a project root."
|
|
977
976
|
);
|
|
978
977
|
}
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
...packageJson2.dependencies,
|
|
982
|
-
...packageJson2.devDependencies
|
|
983
|
-
};
|
|
984
|
-
const hasFoundryKit = Object.keys(dependencies).some(
|
|
985
|
-
(dep) => dep.startsWith("@foundrykit/")
|
|
986
|
-
);
|
|
987
|
-
if (!hasFoundryKit && !dependencies.next) {
|
|
978
|
+
const configPath = path3.join(process.cwd(), "foundrykit.config.json");
|
|
979
|
+
if (!fs3.existsSync(configPath)) {
|
|
988
980
|
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
989
981
|
}
|
|
990
982
|
}
|
|
991
983
|
async function hasConflictingFiles(componentData, options) {
|
|
984
|
+
const config = await loadConfig();
|
|
992
985
|
const basePath = options.path || process.cwd();
|
|
993
986
|
for (const file of componentData.files) {
|
|
994
|
-
const
|
|
987
|
+
const resolvedPath = resolveComponentPath(
|
|
988
|
+
file.path,
|
|
989
|
+
componentData.category,
|
|
990
|
+
config
|
|
991
|
+
);
|
|
992
|
+
const filePath = path3.join(basePath, resolvedPath);
|
|
995
993
|
if (fs3.existsSync(filePath)) {
|
|
996
994
|
return true;
|
|
997
995
|
}
|
|
@@ -999,13 +997,19 @@ async function hasConflictingFiles(componentData, options) {
|
|
|
999
997
|
return false;
|
|
1000
998
|
}
|
|
1001
999
|
async function installComponentFiles(componentData, options) {
|
|
1000
|
+
const config = await loadConfig();
|
|
1002
1001
|
const basePath = options.path || process.cwd();
|
|
1003
1002
|
console.log(chalk4.blue("\u{1F4DD} Installing component files..."));
|
|
1004
1003
|
for (const file of componentData.files) {
|
|
1005
|
-
const
|
|
1004
|
+
const resolvedPath = resolveComponentPath(
|
|
1005
|
+
file.path,
|
|
1006
|
+
componentData.category,
|
|
1007
|
+
config
|
|
1008
|
+
);
|
|
1009
|
+
const filePath = path3.join(basePath, resolvedPath);
|
|
1006
1010
|
await fs3.ensureDir(path3.dirname(filePath));
|
|
1007
1011
|
await fs3.writeFile(filePath, file.content);
|
|
1008
|
-
console.log(chalk4.green(` \u2713 ${
|
|
1012
|
+
console.log(chalk4.green(` \u2713 ${resolvedPath}`));
|
|
1009
1013
|
}
|
|
1010
1014
|
}
|
|
1011
1015
|
async function handlePackageDependencies(componentData) {
|
|
@@ -1013,22 +1017,6 @@ async function handlePackageDependencies(componentData) {
|
|
|
1013
1017
|
if (componentData.packageDependencies?.length) {
|
|
1014
1018
|
componentData.packageDependencies.forEach((dep) => allDependencies.add(dep));
|
|
1015
1019
|
}
|
|
1016
|
-
if (componentData.registryDependencies?.includes("utils")) {
|
|
1017
|
-
allDependencies.add("clsx");
|
|
1018
|
-
allDependencies.add("tailwind-merge");
|
|
1019
|
-
}
|
|
1020
|
-
if (componentData.registryDependencies?.includes("primitives")) {
|
|
1021
|
-
allDependencies.add("@radix-ui/react-slot");
|
|
1022
|
-
allDependencies.add("class-variance-authority");
|
|
1023
|
-
allDependencies.add("clsx");
|
|
1024
|
-
allDependencies.add("tailwind-merge");
|
|
1025
|
-
}
|
|
1026
|
-
if (componentData.id === "button") {
|
|
1027
|
-
allDependencies.add("class-variance-authority");
|
|
1028
|
-
}
|
|
1029
|
-
if (componentData.id === "search-bar") {
|
|
1030
|
-
allDependencies.add("lucide-react");
|
|
1031
|
-
}
|
|
1032
1020
|
if (allDependencies.size === 0) {
|
|
1033
1021
|
return;
|
|
1034
1022
|
}
|
|
@@ -1084,47 +1072,67 @@ async function detectPackageManager2() {
|
|
|
1084
1072
|
}
|
|
1085
1073
|
return "pnpm";
|
|
1086
1074
|
}
|
|
1087
|
-
function showUsageExample(componentData) {
|
|
1075
|
+
async function showUsageExample(componentData) {
|
|
1076
|
+
const config = await loadConfig();
|
|
1088
1077
|
console.log(chalk4.cyan("\n\u{1F4A1} Usage:"));
|
|
1089
1078
|
const componentName = componentData.name.replace(/\s+/g, "");
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1079
|
+
const importPath = getImportPath(componentData, config);
|
|
1080
|
+
console.log(chalk4.gray(`import { ${componentName} } from "${importPath}"`));
|
|
1081
|
+
if (componentData.usageExample) {
|
|
1082
|
+
console.log(chalk4.gray(`
|
|
1083
|
+
${componentData.usageExample}`));
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
async function loadConfig() {
|
|
1087
|
+
const configPath = path3.join(process.cwd(), "foundrykit.config.json");
|
|
1088
|
+
if (!fs3.existsSync(configPath)) {
|
|
1089
|
+
throw new Error(
|
|
1090
|
+
'Configuration file not found. Run "foundrykit init" first.'
|
|
1095
1091
|
);
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1092
|
+
}
|
|
1093
|
+
return fs3.readJson(configPath);
|
|
1094
|
+
}
|
|
1095
|
+
function resolveComponentPath(originalPath, category, config) {
|
|
1096
|
+
const categoryPath = config.paths[category] || config.paths.components;
|
|
1097
|
+
const fileName = path3.basename(originalPath);
|
|
1098
|
+
const componentName = path3.dirname(originalPath).split("/").pop() || "";
|
|
1099
|
+
if (category === "primitives") {
|
|
1100
|
+
return path3.join(categoryPath, componentName, fileName);
|
|
1101
|
+
} else if (category === "components") {
|
|
1102
|
+
return path3.join(
|
|
1103
|
+
config.paths.components,
|
|
1104
|
+
"components",
|
|
1105
|
+
componentName,
|
|
1106
|
+
fileName
|
|
1101
1107
|
);
|
|
1102
|
-
} else if (
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1108
|
+
} else if (category === "blocks") {
|
|
1109
|
+
return path3.join(
|
|
1110
|
+
config.paths.blocks || path3.join(config.paths.components, "blocks"),
|
|
1111
|
+
componentName,
|
|
1112
|
+
fileName
|
|
1107
1113
|
);
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
console.log(chalk4.gray('\n<Input placeholder="Enter text..." />'));
|
|
1114
|
-
} else if (componentData.id.includes("hero")) {
|
|
1115
|
-
console.log(chalk4.gray(`
|
|
1116
|
-
<${componentName} />`));
|
|
1117
|
-
} else if (componentData.id === "card") {
|
|
1118
|
-
console.log(chalk4.gray("\n<Card>"));
|
|
1119
|
-
console.log(chalk4.gray(" <CardHeader>"));
|
|
1120
|
-
console.log(chalk4.gray(" <CardTitle>Title</CardTitle>"));
|
|
1121
|
-
console.log(
|
|
1122
|
-
chalk4.gray(" <CardDescription>Description</CardDescription>")
|
|
1114
|
+
} else if (category === "animations") {
|
|
1115
|
+
return path3.join(
|
|
1116
|
+
config.paths.animations || path3.join(config.paths.components, "animations"),
|
|
1117
|
+
componentName,
|
|
1118
|
+
fileName
|
|
1123
1119
|
);
|
|
1124
|
-
console.log(chalk4.gray(" </CardHeader>"));
|
|
1125
|
-
console.log(chalk4.gray(" <CardContent>Content</CardContent>"));
|
|
1126
|
-
console.log(chalk4.gray("</Card>"));
|
|
1127
1120
|
}
|
|
1121
|
+
return originalPath;
|
|
1122
|
+
}
|
|
1123
|
+
function getImportPath(componentData, config) {
|
|
1124
|
+
const aliases = config.aliases || {};
|
|
1125
|
+
const componentName = path3.basename(componentData.files[0].path, ".tsx");
|
|
1126
|
+
if (componentData.category === "primitives") {
|
|
1127
|
+
return `@/components/ui/${componentName}`;
|
|
1128
|
+
} else if (componentData.category === "components") {
|
|
1129
|
+
return `@/components/components/${componentName}`;
|
|
1130
|
+
} else if (componentData.category === "blocks") {
|
|
1131
|
+
return `@/components/blocks/${componentName}`;
|
|
1132
|
+
} else if (componentData.category === "animations") {
|
|
1133
|
+
return `@/components/animations/${componentName}`;
|
|
1134
|
+
}
|
|
1135
|
+
return `@/components/${componentName}`;
|
|
1128
1136
|
}
|
|
1129
1137
|
|
|
1130
1138
|
// src/commands/update.ts
|