@tpitre/story-ui 2.1.1 → 2.1.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/dist/cli/setup.js +41 -5
- package/package.json +1 -1
package/dist/cli/setup.js
CHANGED
|
@@ -86,6 +86,28 @@ function setupStorybookPreview(designSystem) {
|
|
|
86
86
|
console.log(chalk.yellow('⚠️ .storybook directory not found. Please run storybook init first.'));
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
+
// Verify required packages are installed before creating preview
|
|
90
|
+
if (['antd', 'mantine', 'chakra'].includes(designSystem)) {
|
|
91
|
+
const packageJsonPath = path.join(process.cwd(), 'package.json');
|
|
92
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
93
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
94
|
+
const allDeps = { ...packageJson.dependencies, ...packageJson.devDependencies };
|
|
95
|
+
const config = DESIGN_SYSTEM_CONFIGS[designSystem];
|
|
96
|
+
if (config) {
|
|
97
|
+
const missingDeps = config.packages.filter(pkg => !allDeps[pkg]);
|
|
98
|
+
if (missingDeps.length > 0) {
|
|
99
|
+
console.log(chalk.red(`❌ Cannot create preview.tsx - missing dependencies: ${missingDeps.join(', ')}`));
|
|
100
|
+
console.log(chalk.yellow(`Please install them first: npm install ${missingDeps.join(' ')}`));
|
|
101
|
+
// Clean up existing preview.tsx if it has broken imports
|
|
102
|
+
if (fs.existsSync(previewTsxPath)) {
|
|
103
|
+
fs.unlinkSync(previewTsxPath);
|
|
104
|
+
console.log(chalk.yellow('⚠️ Removed existing preview.tsx with broken imports'));
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
89
111
|
const designSystemConfigs = {
|
|
90
112
|
chakra: {
|
|
91
113
|
imports: [
|
|
@@ -329,7 +351,7 @@ export async function setupCommand() {
|
|
|
329
351
|
const systemName = answers.designSystem === 'antd' ? 'Ant Design' :
|
|
330
352
|
answers.designSystem === 'mantine' ? 'Mantine' :
|
|
331
353
|
answers.designSystem === 'chakra' ? 'Chakra UI' : 'the design system';
|
|
332
|
-
return
|
|
354
|
+
return `🚨 IMPORTANT: Would you like to install ${systemName} packages now?\n (Required for Storybook to work properly)`;
|
|
333
355
|
},
|
|
334
356
|
when: (answers) => ['antd', 'mantine', 'chakra'].includes(answers.designSystem),
|
|
335
357
|
default: true
|
|
@@ -400,8 +422,16 @@ export async function setupCommand() {
|
|
|
400
422
|
console.log(chalk.yellow('Please install manually and run setup again:'));
|
|
401
423
|
const config = DESIGN_SYSTEM_CONFIGS[answers.designSystem];
|
|
402
424
|
console.log(chalk.cyan(`npm install ${config.packages.join(' ')}`));
|
|
425
|
+
// Clean up any existing preview.tsx that might cause issues
|
|
426
|
+
const previewTsxPath = path.join(process.cwd(), '.storybook', 'preview.tsx');
|
|
427
|
+
if (fs.existsSync(previewTsxPath)) {
|
|
428
|
+
fs.unlinkSync(previewTsxPath);
|
|
429
|
+
console.log(chalk.yellow('⚠️ Removed preview.tsx to prevent import errors'));
|
|
430
|
+
}
|
|
403
431
|
process.exit(1);
|
|
404
432
|
}
|
|
433
|
+
// Set up Storybook preview file after successful installation
|
|
434
|
+
setupStorybookPreview(answers.designSystem);
|
|
405
435
|
}
|
|
406
436
|
else if (['antd', 'mantine', 'chakra'].includes(answers.designSystem)) {
|
|
407
437
|
// User declined installation - verify dependencies exist
|
|
@@ -415,8 +445,18 @@ export async function setupCommand() {
|
|
|
415
445
|
console.log(chalk.red('❌ Required dependencies missing:'), missingDeps.join(', '));
|
|
416
446
|
console.log(chalk.yellow('Please install them manually:'));
|
|
417
447
|
console.log(chalk.cyan(`npm install ${missingDeps.join(' ')}`));
|
|
448
|
+
// Clean up any existing preview.tsx that might cause issues
|
|
449
|
+
const previewTsxPath = path.join(process.cwd(), '.storybook', 'preview.tsx');
|
|
450
|
+
if (fs.existsSync(previewTsxPath)) {
|
|
451
|
+
fs.unlinkSync(previewTsxPath);
|
|
452
|
+
console.log(chalk.yellow('⚠️ Removed preview.tsx to prevent import errors'));
|
|
453
|
+
}
|
|
418
454
|
process.exit(1);
|
|
419
455
|
}
|
|
456
|
+
else {
|
|
457
|
+
// Dependencies exist, set up Storybook preview
|
|
458
|
+
setupStorybookPreview(answers.designSystem);
|
|
459
|
+
}
|
|
420
460
|
}
|
|
421
461
|
}
|
|
422
462
|
// Generate configuration
|
|
@@ -648,10 +688,6 @@ export async function setupCommand() {
|
|
|
648
688
|
}
|
|
649
689
|
// Clean up default Storybook template components to prevent conflicts
|
|
650
690
|
cleanupDefaultStorybookComponents();
|
|
651
|
-
// Set up Storybook preview file for design systems that require JSX
|
|
652
|
-
if (['chakra', 'antd', 'mantine'].includes(answers.designSystem)) {
|
|
653
|
-
setupStorybookPreview(answers.designSystem);
|
|
654
|
-
}
|
|
655
691
|
// Update package.json with convenience scripts
|
|
656
692
|
if (packageJson) {
|
|
657
693
|
const scripts = packageJson.scripts || {};
|