@foundrykit/cli 1.0.7 → 1.0.9
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 +16 -0
- package/dist/cli.js +67 -19
- package/dist/cli.js.map +1 -1
- package/dist/index.js +67 -19
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/commands/add.ts +99 -14
- package/src/commands/init.ts +3 -2
- package/src/commands/list.ts +3 -0
- package/src/lib/constants.ts +15 -0
- package/src/lib/registry.ts +9 -4
package/src/commands/add.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
ComponentCategory,
|
|
17
17
|
} from '@foundrykit/types';
|
|
18
18
|
import { getRegistry } from '../lib/registry.js';
|
|
19
|
+
import { CLI_VERSION } from '../lib/constants.js';
|
|
19
20
|
|
|
20
21
|
const execAsync = promisify(exec);
|
|
21
22
|
|
|
@@ -228,6 +229,20 @@ async function addSingleComponent(
|
|
|
228
229
|
}
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Update config version to match CLI version
|
|
234
|
+
*/
|
|
235
|
+
async function updateConfigVersion(): Promise<void> {
|
|
236
|
+
const configPath = path.join(process.cwd(), 'foundrykit.config.json');
|
|
237
|
+
if (fs.existsSync(configPath)) {
|
|
238
|
+
const config = await fs.readJson(configPath);
|
|
239
|
+
if (config.version !== CLI_VERSION) {
|
|
240
|
+
config.version = CLI_VERSION;
|
|
241
|
+
await fs.writeJson(configPath, config, { spaces: 2 });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
231
246
|
/**
|
|
232
247
|
* Validate that the project is properly initialized
|
|
233
248
|
*/
|
|
@@ -245,6 +260,9 @@ async function validateProject(): Promise<void> {
|
|
|
245
260
|
if (!fs.existsSync(configPath)) {
|
|
246
261
|
throw new Error('FoundryKit not initialized. Run "foundrykit init" first.');
|
|
247
262
|
}
|
|
263
|
+
|
|
264
|
+
// Update config version if needed
|
|
265
|
+
await updateConfigVersion();
|
|
248
266
|
}
|
|
249
267
|
|
|
250
268
|
/**
|
|
@@ -316,11 +334,16 @@ async function installComponentFiles(
|
|
|
316
334
|
continue;
|
|
317
335
|
}
|
|
318
336
|
|
|
319
|
-
//
|
|
320
|
-
|
|
337
|
+
// Transform imports based on config
|
|
338
|
+
const transformedContent = transformImportsForConfig(file.content, config);
|
|
321
339
|
|
|
322
|
-
|
|
340
|
+
// Write the file
|
|
341
|
+
await fs.writeFile(filePath, transformedContent);
|
|
342
|
+
console.log(chalk.gray(` ✓ Created ${resolvedPath}`));
|
|
323
343
|
}
|
|
344
|
+
|
|
345
|
+
// Update config version after successful installation
|
|
346
|
+
await updateConfigVersion();
|
|
324
347
|
}
|
|
325
348
|
|
|
326
349
|
/**
|
|
@@ -447,6 +470,62 @@ async function loadConfig(): Promise<any> {
|
|
|
447
470
|
return fs.readJson(configPath);
|
|
448
471
|
}
|
|
449
472
|
|
|
473
|
+
/**
|
|
474
|
+
* Transform imports in file content based on config
|
|
475
|
+
*/
|
|
476
|
+
function transformImportsForConfig(content: string, config: any): string {
|
|
477
|
+
let transformed = content;
|
|
478
|
+
|
|
479
|
+
// Replace generic @/components/primitives with the actual primitives path
|
|
480
|
+
const primitivesPath = config.paths.primitives
|
|
481
|
+
.replace(/^\.\//, '')
|
|
482
|
+
.replace(/\/$/, '');
|
|
483
|
+
transformed = transformed.replace(
|
|
484
|
+
/@\/components\/primitives/g,
|
|
485
|
+
`@/${primitivesPath}`
|
|
486
|
+
);
|
|
487
|
+
|
|
488
|
+
// Also handle legacy @/components/ui imports
|
|
489
|
+
transformed = transformed.replace(
|
|
490
|
+
/@\/components\/ui/g,
|
|
491
|
+
`@/${primitivesPath}`
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
// Replace other standard imports with config paths
|
|
495
|
+
const componentsPath = config.paths.components
|
|
496
|
+
.replace(/^\.\//, '')
|
|
497
|
+
.replace(/\/$/, '');
|
|
498
|
+
transformed = transformed.replace(
|
|
499
|
+
/@\/components\/components/g,
|
|
500
|
+
`@/${componentsPath}`
|
|
501
|
+
);
|
|
502
|
+
|
|
503
|
+
const blocksPath = config.paths.blocks
|
|
504
|
+
.replace(/^\.\//, '')
|
|
505
|
+
.replace(/\/$/, '');
|
|
506
|
+
transformed = transformed.replace(
|
|
507
|
+
/@\/components\/blocks/g,
|
|
508
|
+
`@/${blocksPath}`
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
const animationsPath = config.paths.animations
|
|
512
|
+
.replace(/^\.\//, '')
|
|
513
|
+
.replace(/\/$/, '');
|
|
514
|
+
transformed = transformed.replace(
|
|
515
|
+
/@\/components\/animations/g,
|
|
516
|
+
`@/${animationsPath}`
|
|
517
|
+
);
|
|
518
|
+
|
|
519
|
+
// Handle utils imports
|
|
520
|
+
const utilsPath = config.paths.utils
|
|
521
|
+
.replace(/^\.\//, '')
|
|
522
|
+
.replace(/\/$/, '')
|
|
523
|
+
.replace(/\.(ts|js)$/, '');
|
|
524
|
+
transformed = transformed.replace(/@\/lib\/utils/g, `@/${utilsPath}`);
|
|
525
|
+
|
|
526
|
+
return transformed;
|
|
527
|
+
}
|
|
528
|
+
|
|
450
529
|
/**
|
|
451
530
|
* Resolve component path based on category and configuration
|
|
452
531
|
*/
|
|
@@ -471,12 +550,7 @@ function resolveComponentPath(
|
|
|
471
550
|
if (category === 'primitives') {
|
|
472
551
|
return path.join(categoryPath, componentName, fileName);
|
|
473
552
|
} else if (category === 'components') {
|
|
474
|
-
return path.join(
|
|
475
|
-
config.paths.components,
|
|
476
|
-
'components',
|
|
477
|
-
componentName,
|
|
478
|
-
fileName
|
|
479
|
-
);
|
|
553
|
+
return path.join(config.paths.components, componentName, fileName);
|
|
480
554
|
} else if (category === 'blocks') {
|
|
481
555
|
return path.join(
|
|
482
556
|
config.paths.blocks || path.join(config.paths.components, 'blocks'),
|
|
@@ -500,17 +574,28 @@ function resolveComponentPath(
|
|
|
500
574
|
* Get import path for a component
|
|
501
575
|
*/
|
|
502
576
|
function getImportPath(componentData: ComponentData, config: any): string {
|
|
503
|
-
const aliases = config.aliases || {};
|
|
504
577
|
const componentName = path.basename(componentData.files[0].path, '.tsx');
|
|
505
578
|
|
|
506
579
|
if (componentData.category === 'primitives') {
|
|
507
|
-
|
|
580
|
+
const primitivesPath = config.paths.primitives
|
|
581
|
+
.replace(/^\.\//, '')
|
|
582
|
+
.replace(/\/$/, '');
|
|
583
|
+
return `@/${primitivesPath}/${componentName}`;
|
|
508
584
|
} else if (componentData.category === 'components') {
|
|
509
|
-
|
|
585
|
+
const componentsPath = config.paths.components
|
|
586
|
+
.replace(/^\.\//, '')
|
|
587
|
+
.replace(/\/$/, '');
|
|
588
|
+
return `@/${componentsPath}/${componentName}`;
|
|
510
589
|
} else if (componentData.category === 'blocks') {
|
|
511
|
-
|
|
590
|
+
const blocksPath = config.paths.blocks
|
|
591
|
+
.replace(/^\.\//, '')
|
|
592
|
+
.replace(/\/$/, '');
|
|
593
|
+
return `@/${blocksPath}/${componentName}`;
|
|
512
594
|
} else if (componentData.category === 'animations') {
|
|
513
|
-
|
|
595
|
+
const animationsPath = config.paths.animations
|
|
596
|
+
.replace(/^\.\//, '')
|
|
597
|
+
.replace(/\/$/, '');
|
|
598
|
+
return `@/${animationsPath}/${componentName}`;
|
|
514
599
|
}
|
|
515
600
|
|
|
516
601
|
return `@/components/${componentName}`;
|
package/src/commands/init.ts
CHANGED
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import inquirer from 'inquirer';
|
|
6
6
|
import { exec, execSync } from 'child_process';
|
|
7
7
|
import { promisify } from 'util';
|
|
8
|
+
import { CLI_VERSION, DEFAULT_REGISTRY_URL } from '../lib/constants.js';
|
|
8
9
|
|
|
9
10
|
interface InitOptions {
|
|
10
11
|
force?: boolean;
|
|
@@ -847,8 +848,8 @@ async function createConfigFile(
|
|
|
847
848
|
|
|
848
849
|
// Create configuration with custom paths
|
|
849
850
|
const config = {
|
|
850
|
-
version:
|
|
851
|
-
registry:
|
|
851
|
+
version: CLI_VERSION,
|
|
852
|
+
registry: DEFAULT_REGISTRY_URL,
|
|
852
853
|
paths: {
|
|
853
854
|
utils: pathConfig.utils,
|
|
854
855
|
primitives: pathConfig.primitives,
|
package/src/commands/list.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
import { Command } from 'commander';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
|
+
import inquirer from 'inquirer';
|
|
9
|
+
import fs from 'fs-extra';
|
|
10
|
+
import path from 'path';
|
|
8
11
|
import type { ComponentMeta, ComponentCategory } from '@foundrykit/types';
|
|
9
12
|
import { getRegistry } from '../lib/registry.js';
|
|
10
13
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared constants for FoundryKit CLI
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// CLI version - update this when publishing new versions
|
|
6
|
+
// This should match the version in package.json
|
|
7
|
+
export const CLI_VERSION = '1.0.8';
|
|
8
|
+
|
|
9
|
+
// Default registry URL
|
|
10
|
+
export const DEFAULT_REGISTRY_URL = 'https://foundry.umiflow.com';
|
|
11
|
+
|
|
12
|
+
// Cache settings
|
|
13
|
+
export const CACHE_TTL = 24 * 60 * 60 * 1000; // 24 hours in milliseconds
|
|
14
|
+
export const CACHE_DIR = '.foundrykit';
|
|
15
|
+
export const CACHE_FILE = 'registry-cache.json';
|
package/src/lib/registry.ts
CHANGED
|
@@ -7,6 +7,12 @@ import fs from 'fs-extra';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import os from 'os';
|
|
9
9
|
import chalk from 'chalk';
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_REGISTRY_URL,
|
|
12
|
+
CACHE_DIR,
|
|
13
|
+
CACHE_FILE,
|
|
14
|
+
CACHE_TTL,
|
|
15
|
+
} from './constants.js';
|
|
10
16
|
import type {
|
|
11
17
|
ComponentMeta,
|
|
12
18
|
ComponentData,
|
|
@@ -21,10 +27,9 @@ import type {
|
|
|
21
27
|
* Default configuration
|
|
22
28
|
*/
|
|
23
29
|
const DEFAULT_CONFIG: CLIConfig = {
|
|
24
|
-
registryUrl:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
cacheMaxAge: 1000 * 60 * 60 * 24, // 24 hours
|
|
30
|
+
registryUrl: process.env.FOUNDRYKIT_REGISTRY_URL || DEFAULT_REGISTRY_URL,
|
|
31
|
+
cacheDir: path.join(os.homedir(), CACHE_DIR, 'cache'),
|
|
32
|
+
cacheMaxAge: CACHE_TTL,
|
|
28
33
|
};
|
|
29
34
|
|
|
30
35
|
/**
|