From 20898b7713bd11a87af9604d06d6e3af8f75c3fa Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 21 Jul 2025 14:57:18 -0600 Subject: [PATCH] buster workspace needs sandbox --- .vscode/buster.code-workspace | 3 +- scripts/new-package.ts | 100 ++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/.vscode/buster.code-workspace b/.vscode/buster.code-workspace index 71b5fb17d..8e8b620e4 100644 --- a/.vscode/buster.code-workspace +++ b/.vscode/buster.code-workspace @@ -17,7 +17,8 @@ { "path": "../packages/test-utils" }, { "path": "../packages/typescript-config" }, { "path": "../packages/vitest-config" }, - { "path": "../packages/web-tools" } + { "path": "../packages/web-tools" }, + { "path": "../packages/sandbox" } ], "settings": { "editor.defaultFormatter": "biomejs.biome", diff --git a/scripts/new-package.ts b/scripts/new-package.ts index e94fb052e..87cb5ef0d 100755 --- a/scripts/new-package.ts +++ b/scripts/new-package.ts @@ -156,6 +156,102 @@ async function updatePnpmWorkspace(config: PackageConfig) { } } +async function updateVsCodeWorkspace(config: PackageConfig) { + try { + const workspaceFile = join(process.cwd(), '.vscode', 'buster.code-workspace'); + let content = await readFile(workspaceFile, 'utf-8'); + + // Clean up trailing commas that might cause JSON.parse to fail + content = content.replace(/,(\s*[}\]])/g, '$1'); + + // Parse the JSON + const workspace = JSON.parse(content); + + // Create the new folder entry + const newFolderEntry = { + path: `../packages/${config.name}` + }; + + if (config.type === 'app') { + newFolderEntry.path = `../apps/${config.name}`; + } + + // Check if the entry already exists + const existingIndex = workspace.folders.findIndex((folder: any) => folder.path === newFolderEntry.path); + if (existingIndex !== -1) { + console.log("āœ… Entry already exists in VS Code workspace"); + return; + } + + // Find the correct insertion point to maintain alphabetical order within the type + let insertIndex = -1; + const basePath = config.type === 'app' ? '../apps/' : '../packages/'; + + for (let i = 0; i < workspace.folders.length; i++) { + const folder = workspace.folders[i]; + + // If we're adding a package, find where packages start and end + if (config.type === 'package' && folder.path.startsWith('../packages/')) { + // Keep looking for the right alphabetical spot + if (folder.path > newFolderEntry.path) { + insertIndex = i; + break; + } + } + // If we're adding an app, find where apps start and end + else if (config.type === 'app' && folder.path.startsWith('../apps/')) { + // Keep looking for the right alphabetical spot + if (folder.path > newFolderEntry.path) { + insertIndex = i; + break; + } + } + // If we've moved past the section we care about, insert here + else if (config.type === 'package' && folder.path.startsWith('../packages/')) { + // We're in the packages section, continue + continue; + } else if (config.type === 'app' && folder.path.startsWith('../apps/')) { + // We're in the apps section, continue + continue; + } else if (config.type === 'package' && !folder.path.startsWith('../apps/') && !folder.path.startsWith('../packages/')) { + // We've reached non-package/app entries, insert before this + insertIndex = i; + break; + } + } + + // If we didn't find a spot, add to the end of the appropriate section + if (insertIndex === -1) { + // Find the last entry of our type + for (let i = workspace.folders.length - 1; i >= 0; i--) { + const folder = workspace.folders[i]; + if (folder.path.startsWith(basePath)) { + insertIndex = i + 1; + break; + } + } + + // If still no index found, just append + if (insertIndex === -1) { + insertIndex = workspace.folders.length; + } + } + + // Insert the new folder entry + workspace.folders.splice(insertIndex, 0, newFolderEntry); + + // Write the updated workspace file with proper formatting + const newContent = JSON.stringify(workspace, null, 2) + '\n'; + await writeFile(workspaceFile, newContent); + console.log("āœ… Updated VS Code workspace file"); + + } catch (error) { + console.warn("āš ļø Warning: Failed to update VS Code workspace file. Please add manually:"); + console.warn(` { "path": "../${config.type === 'package' ? 'packages' : 'apps'}/${config.name}" }`); + console.warn(error); + } +} + async function main() { const rl = createReadlineInterface(); @@ -229,6 +325,10 @@ async function main() { await updatePnpmWorkspace(config); } + // Update VS Code workspace + console.log("šŸ“ Updating VS Code workspace..."); + await updateVsCodeWorkspace(config); + // Install dependencies console.log("\nšŸ“¦ Installing dependencies..."); await installDependencies(config);