@tpitre/story-ui 2.1.0 → 2.1.2

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.
Files changed (2) hide show
  1. package/dist/cli/setup.js +72 -7
  2. package/package.json +1 -1
package/dist/cli/setup.js CHANGED
@@ -86,6 +86,23 @@ 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
+ return;
102
+ }
103
+ }
104
+ }
105
+ }
89
106
  const designSystemConfigs = {
90
107
  chakra: {
91
108
  imports: [
@@ -115,6 +132,7 @@ function setupStorybookPreview(designSystem) {
115
132
  imports: [
116
133
  "import type { Preview } from '@storybook/react-vite'",
117
134
  "import { MantineProvider } from '@mantine/core'",
135
+ "import '@mantine/core/styles.css'",
118
136
  "import React from 'react'"
119
137
  ],
120
138
  decorator: `(Story) => (
@@ -201,11 +219,56 @@ async function installDesignSystem(systemKey) {
201
219
  try {
202
220
  console.log(chalk.gray(`Running: ${installCommand}`));
203
221
  execSync(installCommand, { stdio: 'inherit' });
222
+ // Verify installation was successful by re-checking package.json
223
+ const updatedPackageJson = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));
224
+ const updatedDeps = { ...updatedPackageJson.dependencies, ...updatedPackageJson.devDependencies };
225
+ const stillMissingPackages = config.packages.filter(pkg => !updatedDeps[pkg]);
226
+ if (stillMissingPackages.length > 0) {
227
+ throw new Error(`Installation failed: packages still missing: ${stillMissingPackages.join(', ')}`);
228
+ }
204
229
  console.log(chalk.green(`✅ ${config.name} installed successfully!`));
205
230
  if (config.additionalSetup) {
206
- console.log(chalk.blue('\n📋 Additional setup required:'));
207
- console.log(chalk.gray(`Add this import to your main CSS/index file:`));
208
- console.log(chalk.cyan(`${config.additionalSetup}`));
231
+ // Try to automatically add CSS import for Mantine
232
+ if (systemKey === 'mantine') {
233
+ const cssFiles = [
234
+ path.join(process.cwd(), 'src', 'index.css'),
235
+ path.join(process.cwd(), 'src', 'main.css'),
236
+ path.join(process.cwd(), 'src', 'App.css')
237
+ ];
238
+ let cssAdded = false;
239
+ for (const cssFile of cssFiles) {
240
+ if (fs.existsSync(cssFile)) {
241
+ try {
242
+ const cssContent = fs.readFileSync(cssFile, 'utf-8');
243
+ if (!cssContent.includes('@mantine/core/styles.css')) {
244
+ const newContent = `@import "@mantine/core/styles.css";\n\n${cssContent}`;
245
+ fs.writeFileSync(cssFile, newContent);
246
+ console.log(chalk.green(`✅ Added Mantine CSS import to ${path.relative(process.cwd(), cssFile)}`));
247
+ cssAdded = true;
248
+ break;
249
+ }
250
+ else {
251
+ console.log(chalk.blue(`ℹ️ Mantine CSS already imported in ${path.relative(process.cwd(), cssFile)}`));
252
+ cssAdded = true;
253
+ break;
254
+ }
255
+ }
256
+ catch (error) {
257
+ console.warn(chalk.yellow(`⚠️ Could not modify ${cssFile}:`, error));
258
+ }
259
+ }
260
+ }
261
+ if (!cssAdded) {
262
+ console.log(chalk.blue('\n📋 Manual setup required:'));
263
+ console.log(chalk.gray(`Add this import to your main CSS file:`));
264
+ console.log(chalk.cyan(`${config.additionalSetup}`));
265
+ }
266
+ }
267
+ else {
268
+ console.log(chalk.blue('\n📋 Additional setup required:'));
269
+ console.log(chalk.gray(`Add this import to your main CSS/index file:`));
270
+ console.log(chalk.cyan(`${config.additionalSetup}`));
271
+ }
209
272
  }
210
273
  return true;
211
274
  }
@@ -356,6 +419,8 @@ export async function setupCommand() {
356
419
  console.log(chalk.cyan(`npm install ${config.packages.join(' ')}`));
357
420
  process.exit(1);
358
421
  }
422
+ // Set up Storybook preview file after successful installation
423
+ setupStorybookPreview(answers.designSystem);
359
424
  }
360
425
  else if (['antd', 'mantine', 'chakra'].includes(answers.designSystem)) {
361
426
  // User declined installation - verify dependencies exist
@@ -371,6 +436,10 @@ export async function setupCommand() {
371
436
  console.log(chalk.cyan(`npm install ${missingDeps.join(' ')}`));
372
437
  process.exit(1);
373
438
  }
439
+ else {
440
+ // Dependencies exist, set up Storybook preview
441
+ setupStorybookPreview(answers.designSystem);
442
+ }
374
443
  }
375
444
  }
376
445
  // Generate configuration
@@ -602,10 +671,6 @@ export async function setupCommand() {
602
671
  }
603
672
  // Clean up default Storybook template components to prevent conflicts
604
673
  cleanupDefaultStorybookComponents();
605
- // Set up Storybook preview file for design systems that require JSX
606
- if (['chakra', 'antd', 'mantine'].includes(answers.designSystem)) {
607
- setupStorybookPreview(answers.designSystem);
608
- }
609
674
  // Update package.json with convenience scripts
610
675
  if (packageJson) {
611
676
  const scripts = packageJson.scripts || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpitre/story-ui",
3
- "version": "2.1.0",
3
+ "version": "2.1.2",
4
4
  "description": "AI-powered Storybook story generator with dynamic component discovery",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",