@foundrykit/cli 1.0.2 → 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.
@@ -12,15 +12,15 @@ interface InitOptions {
12
12
 
13
13
  export function initCommand() {
14
14
  return new Command('init')
15
- .description('Initialize FoundryKit in your Next.js project')
15
+ .description('Initialize FoundryKit in your project')
16
16
  .option('-f, --force', 'overwrite existing files')
17
17
  .option('--skip-install', 'skip installing dependencies')
18
18
  .action(async (options: InitOptions) => {
19
19
  try {
20
20
  console.log(chalk.blue('šŸš€ Initializing FoundryKit...'));
21
21
 
22
- // Check if it's a Next.js project
23
- await validateNextJsProject();
22
+ // Validate project
23
+ await validateProject();
24
24
 
25
25
  // Check if already initialized
26
26
  if (!options.force && (await isFoundryKitInitialized())) {
@@ -44,6 +44,12 @@ export function initCommand() {
44
44
  await installDependencies();
45
45
  }
46
46
 
47
+ // Create configuration file
48
+ await createConfigFile(options);
49
+
50
+ // Install utils
51
+ await installUtils();
52
+
47
53
  // Setup CSS with Tailwind v4
48
54
  await setupTailwindV4();
49
55
 
@@ -60,14 +66,18 @@ export function initCommand() {
60
66
  console.log(chalk.cyan('\nšŸ“¦ Next steps:'));
61
67
  console.log(
62
68
  chalk.gray(
63
- ' 1. Add a component: npx @foundrykit/cli add hero-minimal'
69
+ ' 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal'
64
70
  )
65
71
  );
66
72
  console.log(
67
- chalk.gray(' 2. List available components: npx @foundrykit/cli list')
73
+ chalk.gray(
74
+ ' 2. List available components: pnpm dlx @foundrykit/cli list'
75
+ )
68
76
  );
69
77
  console.log(
70
- chalk.gray(' 3. Check out the docs: https://foundrykit.dev')
78
+ chalk.gray(
79
+ ' 3. Check out the docs: https://foundry-docs.umiflow.com'
80
+ )
71
81
  );
72
82
  } catch (error) {
73
83
  console.error(chalk.red('āŒ Failed to initialize FoundryKit:'));
@@ -79,7 +89,7 @@ export function initCommand() {
79
89
  });
80
90
  }
81
91
 
82
- async function validateNextJsProject(): Promise<void> {
92
+ async function validateProject(): Promise<void> {
83
93
  const packageJsonPath = path.join(process.cwd(), 'package.json');
84
94
 
85
95
  if (!fs.existsSync(packageJsonPath)) {
@@ -104,46 +114,15 @@ async function validateNextJsProject(): Promise<void> {
104
114
  }
105
115
 
106
116
  async function isFoundryKitInitialized(): Promise<boolean> {
107
- const packageJsonPath = path.join(process.cwd(), 'package.json');
108
-
109
- if (fs.existsSync(packageJsonPath)) {
110
- const packageJson = await fs.readJson(packageJsonPath);
111
- const dependencies = {
112
- ...packageJson.dependencies,
113
- ...packageJson.devDependencies,
114
- };
115
-
116
- // Check if any FoundryKit packages are installed
117
- return Object.keys(dependencies).some(dep =>
118
- dep.startsWith('@foundrykit/')
119
- );
120
- }
121
-
122
- return false;
117
+ // Check for foundrykit.config.json
118
+ const configPath = path.join(process.cwd(), 'foundrykit.config.json');
119
+ return fs.existsSync(configPath);
123
120
  }
124
121
 
125
122
  async function installDependencies(): Promise<void> {
126
- console.log(chalk.blue('šŸ“¦ Installing FoundryKit dependencies...'));
127
-
128
- // Check if we're in a workspace (local development)
129
- const isWorkspace = await checkIfWorkspace();
130
-
131
- if (isWorkspace) {
132
- console.log(
133
- chalk.yellow('āš ļø Workspace detected - skipping dependency installation')
134
- );
135
- console.log(chalk.gray('Dependencies are already available via workspace'));
136
- return;
137
- }
123
+ console.log(chalk.blue('šŸ“¦ Installing base dependencies...'));
138
124
 
139
- const dependencies = [
140
- '@foundrykit/primitives',
141
- '@foundrykit/components',
142
- '@foundrykit/blocks',
143
- '@foundrykit/hooks',
144
- '@foundrykit/animation',
145
- '@foundrykit/tailwind',
146
- ];
125
+ const dependencies = ['clsx', 'tailwind-merge'];
147
126
 
148
127
  try {
149
128
  // Detect package manager
@@ -155,13 +134,19 @@ async function installDependencies(): Promise<void> {
155
134
  ? `npm install ${dependencies.join(' ')}`
156
135
  : packageManager === 'yarn'
157
136
  ? `yarn add ${dependencies.join(' ')}`
158
- : `pnpm add ${dependencies.join(' ')}`;
137
+ : packageManager === 'bun'
138
+ ? `bun add ${dependencies.join(' ')}`
139
+ : `pnpm add ${dependencies.join(' ')}`;
159
140
 
160
141
  execSync(installCmd, { stdio: 'inherit' });
161
142
  console.log(chalk.green('āœ… Dependencies installed'));
162
143
  } catch (error) {
163
- throw new Error(
164
- 'Failed to install dependencies. Please install them manually.'
144
+ console.log(
145
+ chalk.yellow('āš ļø Could not install dependencies automatically')
146
+ );
147
+ console.log(chalk.gray('Please install them manually:'));
148
+ console.log(
149
+ chalk.cyan(` ${detectPackageManager()} add ${dependencies.join(' ')}`)
165
150
  );
166
151
  }
167
152
  }
@@ -206,6 +191,7 @@ async function checkIfWorkspace(): Promise<boolean> {
206
191
  function detectPackageManager(): string {
207
192
  if (fs.existsSync('pnpm-lock.yaml')) return 'pnpm';
208
193
  if (fs.existsSync('yarn.lock')) return 'yarn';
194
+ if (fs.existsSync('bun.lockb')) return 'bun';
209
195
  return 'npm';
210
196
  }
211
197
 
@@ -540,7 +526,14 @@ async function updateLayoutImport(globalCssPath: string): Promise<void> {
540
526
  async function createDirectories(): Promise<void> {
541
527
  console.log(chalk.blue('šŸ“ Creating component directories...'));
542
528
 
543
- const dirs = ['components/ui', 'components/blocks', 'lib', 'hooks'];
529
+ const dirs = [
530
+ 'components/primitives',
531
+ 'components/components',
532
+ 'components/blocks',
533
+ 'components/animations',
534
+ 'lib',
535
+ 'hooks',
536
+ ];
544
537
 
545
538
  for (const dir of dirs) {
546
539
  await fs.ensureDir(path.join(process.cwd(), dir));
@@ -612,3 +605,125 @@ async function updatePackageScripts(): Promise<void> {
612
605
  await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
613
606
  console.log(chalk.green('āœ… Package scripts updated'));
614
607
  }
608
+
609
+ async function createConfigFile(options: InitOptions): Promise<void> {
610
+ console.log(chalk.blue('šŸ“ Creating configuration file...'));
611
+
612
+ const configPath = path.join(process.cwd(), 'foundrykit.config.json');
613
+
614
+ if (fs.existsSync(configPath) && !options.force) {
615
+ console.log(chalk.yellow('āš ļø Configuration file already exists'));
616
+ return;
617
+ }
618
+
619
+ // Detect framework
620
+ const framework = await detectFramework();
621
+
622
+ // Detect TypeScript
623
+ const isTypeScript = fs.existsSync(path.join(process.cwd(), 'tsconfig.json'));
624
+
625
+ // Create configuration
626
+ const config = {
627
+ version: '1.0.0',
628
+ registry: 'https://foundry.umiflow.com',
629
+ paths: {
630
+ utils: './src/lib/utils.ts',
631
+ primitives: './src/components/primitives',
632
+ components: './src/components/components',
633
+ blocks: './src/components/blocks',
634
+ hooks: './src/hooks',
635
+ animations: './src/components/animations',
636
+ },
637
+ packageManager: detectPackageManager(),
638
+ typescript: isTypeScript,
639
+ framework,
640
+ tailwind: {
641
+ config: './tailwind.config.js',
642
+ css: './src/styles/globals.css',
643
+ },
644
+ aliases: {
645
+ '@': './src',
646
+ '@/components': './src/components',
647
+ '@/lib': './src/lib',
648
+ '@/hooks': './src/hooks',
649
+ },
650
+ };
651
+
652
+ // Adjust paths based on framework
653
+ if (framework === 'next') {
654
+ const hasAppDir = fs.existsSync(path.join(process.cwd(), 'app'));
655
+ if (hasAppDir && !fs.existsSync(path.join(process.cwd(), 'src/app'))) {
656
+ // Using app directory without src
657
+ config.paths = {
658
+ utils: './lib/utils.ts',
659
+ primitives: './components/primitives',
660
+ components: './components/components',
661
+ blocks: './components/blocks',
662
+ hooks: './hooks',
663
+ animations: './components/animations',
664
+ };
665
+ config.tailwind.css = './app/globals.css';
666
+ config.aliases = {
667
+ '@': './',
668
+ '@/components': './components',
669
+ '@/lib': './lib',
670
+ '@/hooks': './hooks',
671
+ };
672
+ }
673
+ }
674
+
675
+ await fs.writeJson(configPath, config, { spaces: 2 });
676
+ console.log(chalk.green('āœ… Created foundrykit.config.json'));
677
+ }
678
+
679
+ async function installUtils(): Promise<void> {
680
+ console.log(chalk.blue('šŸ“¦ Installing utils...'));
681
+
682
+ // Read config to get utils path
683
+ const configPath = path.join(process.cwd(), 'foundrykit.config.json');
684
+ if (!fs.existsSync(configPath)) {
685
+ console.log(chalk.yellow('āš ļø Configuration file not found'));
686
+ return;
687
+ }
688
+
689
+ const config = await fs.readJson(configPath);
690
+ const utilsPath = path.join(process.cwd(), config.paths.utils);
691
+
692
+ // Check if utils already exists
693
+ if (fs.existsSync(utilsPath)) {
694
+ console.log(chalk.yellow('āš ļø Utils file already exists'));
695
+ return;
696
+ }
697
+
698
+ // Create utils file
699
+ await fs.ensureDir(path.dirname(utilsPath));
700
+
701
+ const utilsContent = `import { type ClassValue, clsx } from 'clsx';
702
+ import { twMerge } from 'tailwind-merge';
703
+
704
+ export function cn(...inputs: ClassValue[]) {
705
+ return twMerge(clsx(inputs));
706
+ }
707
+ `;
708
+
709
+ await fs.writeFile(utilsPath, utilsContent);
710
+ console.log(chalk.green('āœ… Created utils file'));
711
+ }
712
+
713
+ async function detectFramework(): Promise<string> {
714
+ const packageJsonPath = path.join(process.cwd(), 'package.json');
715
+ if (fs.existsSync(packageJsonPath)) {
716
+ const packageJson = await fs.readJson(packageJsonPath);
717
+ const deps = {
718
+ ...packageJson.dependencies,
719
+ ...packageJson.devDependencies,
720
+ };
721
+
722
+ if (deps.next) return 'next';
723
+ if (deps.remix) return 'remix';
724
+ if (deps.vite) return 'vite';
725
+ if (deps.react) return 'react';
726
+ }
727
+
728
+ return 'react';
729
+ }