Skip to content

Commit 13257ce

Browse files
fix(cli): update render block transformation by removing legacy regex handling
1 parent ceed67b commit 13257ce

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

.changeset/heavy-lands-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-o2s-app': patch
3+
---
4+
5+
update render block transformation by removing legacy regex handling

packages/cli/create-o2s-app/src/scaffold/transform-render-blocks.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ const FILE_PATH = 'apps/frontend/src/blocks/renderBlocks.tsx';
66
// Regex matches: import * as Alias from '@o2s/blocks.<name>/frontend';
77
const BLOCK_IMPORT_REGEX = /^import \* as (\w+) from '@o2s\/blocks\.([^/]+)\/frontend';$/;
88

9-
// Regex matches: case 'SomeBlock':
10-
const CASE_LINE_REGEX = /^\s+case '(\w+)':\s*$/;
11-
12-
// Regex matches: return <Alias.Renderer (handles extra props like onSignOut, renderBlocks)
13-
const RETURN_RENDERER_REGEX = /^\s+return <(\w+)\.Renderer/;
9+
// Regex matches: SomeBlock: (blockProps) => <Alias.Renderer ...
10+
const REGISTRY_ENTRY_REGEX = /^\s+\w+:\s*\(blockProps\)\s*=>\s*<(\w+)\.Renderer/;
1411

1512
export const transformRenderBlocks = async (projectDir: string, selectedBlockNames: string[]): Promise<void> => {
1613
const filePath = path.join(projectDir, FILE_PATH);
@@ -39,16 +36,10 @@ export const transformRenderBlocks = async (projectDir: string, selectedBlockNam
3936

4037
if (aliasesToRemove.size === 0) return;
4138

42-
// Process line by line — switch case/return pairs must be removed together
39+
// Process line by line
4340
const result: string[] = [];
44-
let skipNext = false;
4541

4642
for (let i = 0; i < lines.length; i++) {
47-
if (skipNext) {
48-
skipNext = false;
49-
continue;
50-
}
51-
5243
const line = lines[i];
5344
if (line === undefined) continue;
5445

@@ -58,18 +49,10 @@ export const transformRenderBlocks = async (projectDir: string, selectedBlockNam
5849
continue;
5950
}
6051

61-
// Detect switch case line and peek at the return line below it
62-
const caseMatch = line.match(CASE_LINE_REGEX);
63-
if (caseMatch && i + 1 < lines.length) {
64-
const nextLine = lines[i + 1];
65-
if (nextLine !== undefined) {
66-
const returnMatch = nextLine.match(RETURN_RENDERER_REGEX);
67-
if (returnMatch && returnMatch[1] && aliasesToRemove.has(returnMatch[1])) {
68-
// Skip both the case line (current) and the return line (next)
69-
skipNext = true;
70-
continue;
71-
}
72-
}
52+
// Remove BLOCK_REGISTRY entries for unselected blocks
53+
const registryMatch = line.match(REGISTRY_ENTRY_REGEX);
54+
if (registryMatch && registryMatch[1] && aliasesToRemove.has(registryMatch[1])) {
55+
continue;
7356
}
7457

7558
result.push(line);

0 commit comments

Comments
 (0)