From c6becacef078e046b6c8477549462e0f318b5d50 Mon Sep 17 00:00:00 2001 From: dobromirts Date: Thu, 28 May 2026 10:18:22 +0300 Subject: [PATCH] Fix code-viewer JSON paths and add boilerplate files for StackBlitz sdk.openProject() --- scripts/generate-code-viewer.js | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/scripts/generate-code-viewer.js b/scripts/generate-code-viewer.js index 79d7c6739..27f7d3410 100644 --- a/scripts/generate-code-viewer.js +++ b/scripts/generate-code-viewer.js @@ -80,8 +80,10 @@ async function collectSampleFiles(folderPath, group, component, name) { const mainTsPath = path.join(srcDir, 'index.ts'); const htmlPath = path.join(folderPath, 'index.html'); - const mainTsRelPath = `./samples/${group}/${component}/${name}/src/index.ts`; - const htmlRelPath = `./samples/${group}/${component}/${name}/index.html`; + // Use project-relative paths so StackBlitz sdk.openProject() receives "src/index.ts" + // instead of "./samples/{group}/{component}/{name}/src/index.ts". + const mainTsRelPath = `src/index.ts`; + const htmlRelPath = `index.html`; const items = []; @@ -112,7 +114,7 @@ async function collectSampleFiles(folderPath, group, component, name) { .map(async file => { const ext = path.extname(file).slice(1).toLowerCase(); const filePath = path.join(srcDir, file); - const relPath = `./samples/${group}/${component}/${name}/src/${file}`; + const relPath = `src/${file}`; if (!INCLUDE_EXTS.has('.' + ext)) return null; @@ -161,14 +163,13 @@ async function collectSampleFiles(folderPath, group, component, name) { if (dataFileItems.length === 1) { items.push(dataFileItems[0]); } else if (dataFileItems.length > 1) { - const dataFolder = `./samples/${group}/${component}/${name}/src`; let combinedContent = '// NOTE this file contains multiple data sources:'; for (let i = 0; i < dataFileItems.length; i++) { combinedContent += `\n\n// Data Source #${i + 1}\n`; combinedContent += dataFileItems[i].content + '\n'; } items.push({ - path: `${dataFolder}/DataSources.ts`, + path: `src/DataSources.ts`, content: combinedContent, fileExtension: 'ts', fileHeader: 'DATA', @@ -177,6 +178,26 @@ async function collectSampleFiles(folderPath, group, component, name) { }); } + // 4. Boilerplate files so StackBlitz sdk.openProject() has a complete runnable project. + const boilerplate = [ + { file: 'tsconfig.json', ext: 'json', header: 'json' }, + { file: 'webpack.config.js', ext: 'js', header: 'js' }, + { file: 'package.json', ext: 'json', header: 'json' }, + ]; + for (const b of boilerplate) { + const bPath = path.join(folderPath, b.file); + if (await fileExists(bPath)) { + items.push({ + path: b.file, + content: await fsp.readFile(bPath, 'utf8'), + fileExtension: b.ext, + fileHeader: b.header, + isMain: false, + hasRelativeAssetsUrls: false, + }); + } + } + return items; }