@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/src/commands/init.ts
CHANGED
|
@@ -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
|
|
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
|
-
//
|
|
23
|
-
await
|
|
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:
|
|
69
|
+
' 1. Add a component: pnpm dlx @foundrykit/cli add hero-minimal'
|
|
64
70
|
)
|
|
65
71
|
);
|
|
66
72
|
console.log(
|
|
67
|
-
chalk.gray(
|
|
73
|
+
chalk.gray(
|
|
74
|
+
' 2. List available components: pnpm dlx @foundrykit/cli list'
|
|
75
|
+
)
|
|
68
76
|
);
|
|
69
77
|
console.log(
|
|
70
|
-
chalk.gray(
|
|
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
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
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
|
-
:
|
|
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
|
-
|
|
164
|
-
'
|
|
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
|
|
|
@@ -612,3 +598,125 @@ async function updatePackageScripts(): Promise<void> {
|
|
|
612
598
|
await fs.writeJson(packageJsonPath, packageJson, { spaces: 2 });
|
|
613
599
|
console.log(chalk.green('ā
Package scripts updated'));
|
|
614
600
|
}
|
|
601
|
+
|
|
602
|
+
async function createConfigFile(options: InitOptions): Promise<void> {
|
|
603
|
+
console.log(chalk.blue('š Creating configuration file...'));
|
|
604
|
+
|
|
605
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
606
|
+
|
|
607
|
+
if (fs.existsSync(configPath) && !options.force) {
|
|
608
|
+
console.log(chalk.yellow('ā ļø Configuration file already exists'));
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Detect framework
|
|
613
|
+
const framework = await detectFramework();
|
|
614
|
+
|
|
615
|
+
// Detect TypeScript
|
|
616
|
+
const isTypeScript = fs.existsSync(path.join(process.cwd(), 'tsconfig.json'));
|
|
617
|
+
|
|
618
|
+
// Create configuration
|
|
619
|
+
const config = {
|
|
620
|
+
version: '1.0.0',
|
|
621
|
+
registry: 'https://foundry.umiflow.com',
|
|
622
|
+
paths: {
|
|
623
|
+
utils: './src/lib/utils.ts',
|
|
624
|
+
primitives: './src/components/ui',
|
|
625
|
+
components: './src/components',
|
|
626
|
+
blocks: './src/components/blocks',
|
|
627
|
+
hooks: './src/hooks',
|
|
628
|
+
animations: './src/components/animations',
|
|
629
|
+
},
|
|
630
|
+
packageManager: detectPackageManager(),
|
|
631
|
+
typescript: isTypeScript,
|
|
632
|
+
framework,
|
|
633
|
+
tailwind: {
|
|
634
|
+
config: './tailwind.config.js',
|
|
635
|
+
css: './src/styles/globals.css',
|
|
636
|
+
},
|
|
637
|
+
aliases: {
|
|
638
|
+
'@': './src',
|
|
639
|
+
'@/components': './src/components',
|
|
640
|
+
'@/lib': './src/lib',
|
|
641
|
+
'@/hooks': './src/hooks',
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
// Adjust paths based on framework
|
|
646
|
+
if (framework === 'next') {
|
|
647
|
+
const hasAppDir = fs.existsSync(path.join(process.cwd(), 'app'));
|
|
648
|
+
if (hasAppDir && !fs.existsSync(path.join(process.cwd(), 'src/app'))) {
|
|
649
|
+
// Using app directory without src
|
|
650
|
+
config.paths = {
|
|
651
|
+
utils: './lib/utils.ts',
|
|
652
|
+
primitives: './components/ui',
|
|
653
|
+
components: './components',
|
|
654
|
+
blocks: './components/blocks',
|
|
655
|
+
hooks: './hooks',
|
|
656
|
+
animations: './components/animations',
|
|
657
|
+
};
|
|
658
|
+
config.tailwind.css = './app/globals.css';
|
|
659
|
+
config.aliases = {
|
|
660
|
+
'@': './',
|
|
661
|
+
'@/components': './components',
|
|
662
|
+
'@/lib': './lib',
|
|
663
|
+
'@/hooks': './hooks',
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
669
|
+
console.log(chalk.green('ā
Created foundrykit.config.json'));
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
async function installUtils(): Promise<void> {
|
|
673
|
+
console.log(chalk.blue('š¦ Installing utils...'));
|
|
674
|
+
|
|
675
|
+
// Read config to get utils path
|
|
676
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
677
|
+
if (!fs.existsSync(configPath)) {
|
|
678
|
+
console.log(chalk.yellow('ā ļø Configuration file not found'));
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
const config = await fs.readJson(configPath);
|
|
683
|
+
const utilsPath = path.join(process.cwd(), config.paths.utils);
|
|
684
|
+
|
|
685
|
+
// Check if utils already exists
|
|
686
|
+
if (fs.existsSync(utilsPath)) {
|
|
687
|
+
console.log(chalk.yellow('ā ļø Utils file already exists'));
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
// Create utils file
|
|
692
|
+
await fs.ensureDir(path.dirname(utilsPath));
|
|
693
|
+
|
|
694
|
+
const utilsContent = `import { type ClassValue, clsx } from 'clsx';
|
|
695
|
+
import { twMerge } from 'tailwind-merge';
|
|
696
|
+
|
|
697
|
+
export function cn(...inputs: ClassValue[]) {
|
|
698
|
+
return twMerge(clsx(inputs));
|
|
699
|
+
}
|
|
700
|
+
`;
|
|
701
|
+
|
|
702
|
+
await fs.writeFile(utilsPath, utilsContent);
|
|
703
|
+
console.log(chalk.green('ā
Created utils file'));
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
async function detectFramework(): Promise<string> {
|
|
707
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
708
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
709
|
+
const packageJson = await fs.readJson(packageJsonPath);
|
|
710
|
+
const deps = {
|
|
711
|
+
...packageJson.dependencies,
|
|
712
|
+
...packageJson.devDependencies,
|
|
713
|
+
};
|
|
714
|
+
|
|
715
|
+
if (deps.next) return 'next';
|
|
716
|
+
if (deps.remix) return 'remix';
|
|
717
|
+
if (deps.vite) return 'vite';
|
|
718
|
+
if (deps.react) return 'react';
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
return 'react';
|
|
722
|
+
}
|