Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/cli/create-o2s-app/src/scaffold/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,28 @@ import { ALWAYS_REMOVE_DIRS, ALWAYS_REMOVE_FILES } from '../constants';
import * as fs from 'fs-extra';
import * as path from 'path';

/**
* Removes @o2s/framework references from .storybook/main.ts after scaffolding.
* The packages/framework directory is always removed, so these aliases and
* optimizeDeps entries would cause Storybook to fail.
*/
const cleanStorybookConfig = async (projectDir: string): Promise<void> => {
const configPath = path.join(projectDir, '.storybook', 'main.ts');
if (!(await fs.pathExists(configPath))) return;

let content = await fs.readFile(configPath, 'utf-8');

// Remove @o2s/framework lines from optimizeDeps.include
content = content.replace(/\s*'@o2s\/framework\/modules',?\n?/g, '');
content = content.replace(/\s*'@o2s\/framework\/sdk',?\n?/g, '');

// Remove @o2s/framework alias lines from resolve.alias
content = content.replace(/\s*'@o2s\/framework\/sdk':.*\n/g, '');
content = content.replace(/\s*'@o2s\/framework\/modules':.*\n/g, '');
Comment on lines +16 to +22
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Storybook cleanup uses several near-identical regex replace calls. This duplication makes it easy to miss future framework entrypoints (or introduce inconsistencies between optimizeDeps and resolve.alias removals). Consider centralizing the list of framework specifiers/aliases and applying the removals in a loop so it stays consistent as the template evolves.

Copilot uses AI. Check for mistakes.

await fs.writeFile(configPath, content, 'utf-8');
};
Comment on lines +14 to +25
Copy link

Copilot AI Mar 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanStorybookConfig always rewrites .storybook/main.ts even when none of the patterns match (e.g., templates without the framework aliases). This adds unnecessary I/O and can change file timestamps during scaffolding. Consider only calling writeFile when the transformed content differs from the original read content.

Copilot uses AI. Check for mistakes.

export const cleanupProject = async (projectDir: string): Promise<void> => {
console.log('Organizing project structure...');

Expand All @@ -18,4 +40,7 @@ export const cleanupProject = async (projectDir: string): Promise<void> => {
await fs.remove(fullPath);
}
}

// Clean storybook config after removing framework directory
await cleanStorybookConfig(projectDir);
};
Loading