@foundrykit/cli 1.0.2 → 1.0.3
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 +6 -0
- package/dist/cli.js +138 -69
- package/dist/cli.js.map +1 -1
- package/dist/index.js +138 -69
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/add.ts +24 -0
- package/src/commands/init.ts +154 -46
package/CHANGELOG.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -14,10 +14,10 @@ import path from "path";
|
|
|
14
14
|
import { execSync } from "child_process";
|
|
15
15
|
import inquirer from "inquirer";
|
|
16
16
|
function initCommand() {
|
|
17
|
-
return new Command("init").description("Initialize FoundryKit in your
|
|
17
|
+
return new Command("init").description("Initialize FoundryKit in your project").option("-f, --force", "overwrite existing files").option("--skip-install", "skip installing dependencies").action(async (options) => {
|
|
18
18
|
try {
|
|
19
19
|
console.log(chalk.blue("\u{1F680} Initializing FoundryKit..."));
|
|
20
|
-
await
|
|
20
|
+
await validateProject();
|
|
21
21
|
if (!options.force && await isFoundryKitInitialized()) {
|
|
22
22
|
const { shouldContinue } = await inquirer.prompt([
|
|
23
23
|
{
|
|
@@ -35,6 +35,8 @@ function initCommand() {
|
|
|
35
35
|
if (!options.skipInstall) {
|
|
36
36
|
await installDependencies();
|
|
37
37
|
}
|
|
38
|
+
await createConfigFile(options);
|
|
39
|
+
await installUtils();
|
|
38
40
|
await setupTailwindV4();
|
|
39
41
|
await createDirectories();
|
|
40
42
|
await createExampleFiles();
|
|
@@ -43,14 +45,18 @@ function initCommand() {
|
|
|
43
45
|
console.log(chalk.cyan("\n\u{1F4E6} Next steps:"));
|
|
44
46
|
console.log(
|
|
45
47
|
chalk.gray(
|
|
46
|
-
" 1. Add a component:
|
|
48
|
+
" 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal"
|
|
47
49
|
)
|
|
48
50
|
);
|
|
49
51
|
console.log(
|
|
50
|
-
chalk.gray(
|
|
52
|
+
chalk.gray(
|
|
53
|
+
" 2. List available components: pnpm dlx @foundrykit/cli list"
|
|
54
|
+
)
|
|
51
55
|
);
|
|
52
56
|
console.log(
|
|
53
|
-
chalk.gray(
|
|
57
|
+
chalk.gray(
|
|
58
|
+
" 3. Check out the docs: https://foundry-docs.umiflow.com"
|
|
59
|
+
)
|
|
54
60
|
);
|
|
55
61
|
} catch (error) {
|
|
56
62
|
console.error(chalk.red("\u274C Failed to initialize FoundryKit:"));
|
|
@@ -61,7 +67,7 @@ function initCommand() {
|
|
|
61
67
|
}
|
|
62
68
|
});
|
|
63
69
|
}
|
|
64
|
-
async function
|
|
70
|
+
async function validateProject() {
|
|
65
71
|
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
66
72
|
if (!fs.existsSync(packageJsonPath)) {
|
|
67
73
|
throw new Error(
|
|
@@ -81,82 +87,32 @@ async function validateNextJsProject() {
|
|
|
81
87
|
console.log(chalk.green("\u2705 Next.js project detected"));
|
|
82
88
|
}
|
|
83
89
|
async function isFoundryKitInitialized() {
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const packageJson2 = await fs.readJson(packageJsonPath);
|
|
87
|
-
const dependencies = {
|
|
88
|
-
...packageJson2.dependencies,
|
|
89
|
-
...packageJson2.devDependencies
|
|
90
|
-
};
|
|
91
|
-
return Object.keys(dependencies).some(
|
|
92
|
-
(dep) => dep.startsWith("@foundrykit/")
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
90
|
+
const configPath = path.join(process.cwd(), "foundrykit.config.json");
|
|
91
|
+
return fs.existsSync(configPath);
|
|
96
92
|
}
|
|
97
93
|
async function installDependencies() {
|
|
98
|
-
console.log(chalk.blue("\u{1F4E6} Installing
|
|
99
|
-
const
|
|
100
|
-
if (isWorkspace) {
|
|
101
|
-
console.log(
|
|
102
|
-
chalk.yellow("\u26A0\uFE0F Workspace detected - skipping dependency installation")
|
|
103
|
-
);
|
|
104
|
-
console.log(chalk.gray("Dependencies are already available via workspace"));
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const dependencies = [
|
|
108
|
-
"@foundrykit/primitives",
|
|
109
|
-
"@foundrykit/components",
|
|
110
|
-
"@foundrykit/blocks",
|
|
111
|
-
"@foundrykit/hooks",
|
|
112
|
-
"@foundrykit/animation",
|
|
113
|
-
"@foundrykit/tailwind"
|
|
114
|
-
];
|
|
94
|
+
console.log(chalk.blue("\u{1F4E6} Installing base dependencies..."));
|
|
95
|
+
const dependencies = ["clsx", "tailwind-merge"];
|
|
115
96
|
try {
|
|
116
97
|
const packageManager = detectPackageManager();
|
|
117
98
|
console.log(chalk.gray(`Using ${packageManager}...`));
|
|
118
|
-
const installCmd = packageManager === "npm" ? `npm install ${dependencies.join(" ")}` : packageManager === "yarn" ? `yarn add ${dependencies.join(" ")}` : `pnpm add ${dependencies.join(" ")}`;
|
|
99
|
+
const installCmd = packageManager === "npm" ? `npm install ${dependencies.join(" ")}` : packageManager === "yarn" ? `yarn add ${dependencies.join(" ")}` : packageManager === "bun" ? `bun add ${dependencies.join(" ")}` : `pnpm add ${dependencies.join(" ")}`;
|
|
119
100
|
execSync(installCmd, { stdio: "inherit" });
|
|
120
101
|
console.log(chalk.green("\u2705 Dependencies installed"));
|
|
121
102
|
} catch (error) {
|
|
122
|
-
|
|
123
|
-
"
|
|
103
|
+
console.log(
|
|
104
|
+
chalk.yellow("\u26A0\uFE0F Could not install dependencies automatically")
|
|
124
105
|
);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
try {
|
|
129
|
-
const pnpmWorkspacePath = path.join(
|
|
130
|
-
process.cwd(),
|
|
131
|
-
"../../pnpm-workspace.yaml"
|
|
106
|
+
console.log(chalk.gray("Please install them manually:"));
|
|
107
|
+
console.log(
|
|
108
|
+
chalk.cyan(` ${detectPackageManager()} add ${dependencies.join(" ")}`)
|
|
132
109
|
);
|
|
133
|
-
if (fs.existsSync(pnpmWorkspacePath)) {
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
137
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
138
|
-
const packageJson2 = await fs.readJson(packageJsonPath);
|
|
139
|
-
const allDeps = {
|
|
140
|
-
...packageJson2.dependencies,
|
|
141
|
-
...packageJson2.devDependencies
|
|
142
|
-
};
|
|
143
|
-
const foundryKitPackages = Object.keys(allDeps).filter(
|
|
144
|
-
(key) => key.startsWith("@foundrykit/")
|
|
145
|
-
);
|
|
146
|
-
for (const pkg of foundryKitPackages) {
|
|
147
|
-
if (allDeps[pkg]?.includes("workspace:")) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return false;
|
|
153
|
-
} catch {
|
|
154
|
-
return false;
|
|
155
110
|
}
|
|
156
111
|
}
|
|
157
112
|
function detectPackageManager() {
|
|
158
113
|
if (fs.existsSync("pnpm-lock.yaml")) return "pnpm";
|
|
159
114
|
if (fs.existsSync("yarn.lock")) return "yarn";
|
|
115
|
+
if (fs.existsSync("bun.lockb")) return "bun";
|
|
160
116
|
return "npm";
|
|
161
117
|
}
|
|
162
118
|
async function setupTailwindV4() {
|
|
@@ -444,6 +400,102 @@ async function updatePackageScripts() {
|
|
|
444
400
|
await fs.writeJson(packageJsonPath, packageJson2, { spaces: 2 });
|
|
445
401
|
console.log(chalk.green("\u2705 Package scripts updated"));
|
|
446
402
|
}
|
|
403
|
+
async function createConfigFile(options) {
|
|
404
|
+
console.log(chalk.blue("\u{1F4DD} Creating configuration file..."));
|
|
405
|
+
const configPath = path.join(process.cwd(), "foundrykit.config.json");
|
|
406
|
+
if (fs.existsSync(configPath) && !options.force) {
|
|
407
|
+
console.log(chalk.yellow("\u26A0\uFE0F Configuration file already exists"));
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const framework = await detectFramework();
|
|
411
|
+
const isTypeScript = fs.existsSync(path.join(process.cwd(), "tsconfig.json"));
|
|
412
|
+
const config = {
|
|
413
|
+
version: "1.0.0",
|
|
414
|
+
registry: "https://foundry.umiflow.com",
|
|
415
|
+
paths: {
|
|
416
|
+
utils: "./src/lib/utils.ts",
|
|
417
|
+
primitives: "./src/components/ui",
|
|
418
|
+
components: "./src/components",
|
|
419
|
+
blocks: "./src/components/blocks",
|
|
420
|
+
hooks: "./src/hooks",
|
|
421
|
+
animations: "./src/components/animations"
|
|
422
|
+
},
|
|
423
|
+
packageManager: detectPackageManager(),
|
|
424
|
+
typescript: isTypeScript,
|
|
425
|
+
framework,
|
|
426
|
+
tailwind: {
|
|
427
|
+
config: "./tailwind.config.js",
|
|
428
|
+
css: "./src/styles/globals.css"
|
|
429
|
+
},
|
|
430
|
+
aliases: {
|
|
431
|
+
"@": "./src",
|
|
432
|
+
"@/components": "./src/components",
|
|
433
|
+
"@/lib": "./src/lib",
|
|
434
|
+
"@/hooks": "./src/hooks"
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
if (framework === "next") {
|
|
438
|
+
const hasAppDir = fs.existsSync(path.join(process.cwd(), "app"));
|
|
439
|
+
if (hasAppDir && !fs.existsSync(path.join(process.cwd(), "src/app"))) {
|
|
440
|
+
config.paths = {
|
|
441
|
+
utils: "./lib/utils.ts",
|
|
442
|
+
primitives: "./components/ui",
|
|
443
|
+
components: "./components",
|
|
444
|
+
blocks: "./components/blocks",
|
|
445
|
+
hooks: "./hooks",
|
|
446
|
+
animations: "./components/animations"
|
|
447
|
+
};
|
|
448
|
+
config.tailwind.css = "./app/globals.css";
|
|
449
|
+
config.aliases = {
|
|
450
|
+
"@": "./",
|
|
451
|
+
"@/components": "./components",
|
|
452
|
+
"@/lib": "./lib",
|
|
453
|
+
"@/hooks": "./hooks"
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
458
|
+
console.log(chalk.green("\u2705 Created foundrykit.config.json"));
|
|
459
|
+
}
|
|
460
|
+
async function installUtils() {
|
|
461
|
+
console.log(chalk.blue("\u{1F4E6} Installing utils..."));
|
|
462
|
+
const configPath = path.join(process.cwd(), "foundrykit.config.json");
|
|
463
|
+
if (!fs.existsSync(configPath)) {
|
|
464
|
+
console.log(chalk.yellow("\u26A0\uFE0F Configuration file not found"));
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const config = await fs.readJson(configPath);
|
|
468
|
+
const utilsPath = path.join(process.cwd(), config.paths.utils);
|
|
469
|
+
if (fs.existsSync(utilsPath)) {
|
|
470
|
+
console.log(chalk.yellow("\u26A0\uFE0F Utils file already exists"));
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
await fs.ensureDir(path.dirname(utilsPath));
|
|
474
|
+
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
475
|
+
import { twMerge } from 'tailwind-merge';
|
|
476
|
+
|
|
477
|
+
export function cn(...inputs: ClassValue[]) {
|
|
478
|
+
return twMerge(clsx(inputs));
|
|
479
|
+
}
|
|
480
|
+
`;
|
|
481
|
+
await fs.writeFile(utilsPath, utilsContent);
|
|
482
|
+
console.log(chalk.green("\u2705 Created utils file"));
|
|
483
|
+
}
|
|
484
|
+
async function detectFramework() {
|
|
485
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
|
486
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
487
|
+
const packageJson2 = await fs.readJson(packageJsonPath);
|
|
488
|
+
const deps = {
|
|
489
|
+
...packageJson2.dependencies,
|
|
490
|
+
...packageJson2.devDependencies
|
|
491
|
+
};
|
|
492
|
+
if (deps.next) return "next";
|
|
493
|
+
if (deps.remix) return "remix";
|
|
494
|
+
if (deps.vite) return "vite";
|
|
495
|
+
if (deps.react) return "react";
|
|
496
|
+
}
|
|
497
|
+
return "react";
|
|
498
|
+
}
|
|
447
499
|
|
|
448
500
|
// src/commands/list.ts
|
|
449
501
|
import { Command as Command2 } from "commander";
|
|
@@ -861,7 +913,7 @@ function createGroupedChoices(components) {
|
|
|
861
913
|
async function addSingleComponent(id, options) {
|
|
862
914
|
console.log(chalk4.blue(`
|
|
863
915
|
\u{1F4E6} Adding ${id} to your project...`));
|
|
864
|
-
await
|
|
916
|
+
await validateProject2();
|
|
865
917
|
const registry = getRegistry();
|
|
866
918
|
try {
|
|
867
919
|
const componentData = await registry.getComponent(id);
|
|
@@ -883,6 +935,14 @@ async function addSingleComponent(id, options) {
|
|
|
883
935
|
console.log(chalk4.blue("\u{1F4E6} Installing required dependencies..."));
|
|
884
936
|
for (const dep of componentData.registryDependencies) {
|
|
885
937
|
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
|
+
}
|
|
886
946
|
const depData = await registry.getComponent(dep);
|
|
887
947
|
const hasExisting = await hasConflictingFiles(depData, options);
|
|
888
948
|
if (!hasExisting) {
|
|
@@ -909,7 +969,7 @@ async function addSingleComponent(id, options) {
|
|
|
909
969
|
throw error;
|
|
910
970
|
}
|
|
911
971
|
}
|
|
912
|
-
async function
|
|
972
|
+
async function validateProject2() {
|
|
913
973
|
const packageJsonPath = path3.join(process.cwd(), "package.json");
|
|
914
974
|
if (!fs3.existsSync(packageJsonPath)) {
|
|
915
975
|
throw new Error(
|
|
@@ -957,9 +1017,18 @@ async function handlePackageDependencies(componentData) {
|
|
|
957
1017
|
allDependencies.add("clsx");
|
|
958
1018
|
allDependencies.add("tailwind-merge");
|
|
959
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
|
+
}
|
|
960
1026
|
if (componentData.id === "button") {
|
|
961
1027
|
allDependencies.add("class-variance-authority");
|
|
962
1028
|
}
|
|
1029
|
+
if (componentData.id === "search-bar") {
|
|
1030
|
+
allDependencies.add("lucide-react");
|
|
1031
|
+
}
|
|
963
1032
|
if (allDependencies.size === 0) {
|
|
964
1033
|
return;
|
|
965
1034
|
}
|