From 1ff7eaff3a72facb27fed178193cb5d0cb4d6bea Mon Sep 17 00:00:00 2001 From: Carlos Reyes Date: Sat, 25 Oct 2025 19:45:31 -0700 Subject: [PATCH 1/3] Enhance build scripts: clean up dist and public/chartifact, add asset copying and prebuild step --- packages/editor/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/editor/package.json b/packages/editor/package.json index e2628f76..e9675a0b 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -6,8 +6,11 @@ "main": "dist/esnext/index.js", "types": "dist/esnext/index.d.ts", "scripts": { - "clean": "rimraf dist", + "clean": "rimraf dist && rimraf public/chartifact", + "copy-assets": "mkdir -p public/chartifact/dist/v1 && cp -r ../../docs/dist/v1/* public/chartifact/dist/v1/ 2>/dev/null || echo 'Assets not found, run npm run build in workspace root first'", + "predev": "npm run copy-assets", "dev": "vite --config vite.config.js", + "prebuild": "npm run clean", "tsc": "tsc -p .", "bundle": "vite build --config vite.bundle.config.js", "build": "npm run tsc", From e188795d573af3883d10d7abbc159a551a7a1b99 Mon Sep 17 00:00:00 2001 From: Carlos Reyes Date: Fri, 31 Oct 2025 20:10:11 -0700 Subject: [PATCH 2/3] Refactor asset copying: replace inline script with dedicated copy-assets.js script --- packages/editor/package.json | 6 +++--- packages/editor/scripts/copy-assets.js | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 packages/editor/scripts/copy-assets.js diff --git a/packages/editor/package.json b/packages/editor/package.json index e9675a0b..57be1e7e 100644 --- a/packages/editor/package.json +++ b/packages/editor/package.json @@ -7,11 +7,11 @@ "types": "dist/esnext/index.d.ts", "scripts": { "clean": "rimraf dist && rimraf public/chartifact", - "copy-assets": "mkdir -p public/chartifact/dist/v1 && cp -r ../../docs/dist/v1/* public/chartifact/dist/v1/ 2>/dev/null || echo 'Assets not found, run npm run build in workspace root first'", - "predev": "npm run copy-assets", + "copy-assets": "node scripts/copy-assets.js", "dev": "vite --config vite.config.js", - "prebuild": "npm run clean", "tsc": "tsc -p .", + "predev": "npm run copy-assets", + "postbundle": "npm run copy-assets", "bundle": "vite build --config vite.bundle.config.js", "build": "npm run tsc", "build:06": "npm run build" diff --git a/packages/editor/scripts/copy-assets.js b/packages/editor/scripts/copy-assets.js new file mode 100644 index 00000000..bd82c322 --- /dev/null +++ b/packages/editor/scripts/copy-assets.js @@ -0,0 +1,25 @@ +import fs from 'fs'; +import path from 'path'; + +const sourceDir = '../../docs/dist/v1'; +const targetDir = 'public/chartifact/dist/v1'; + +// Check if source exists +if (!fs.existsSync(sourceDir)) { + console.log('Assets not found, run npm run build in workspace root first'); + process.exit(0); +} + +// Create target directory +fs.mkdirSync(targetDir, { recursive: true }); + +// Copy all files +const files = fs.readdirSync(sourceDir); +files.forEach(file => { + fs.copyFileSync( + path.join(sourceDir, file), + path.join(targetDir, file) + ); +}); + +console.log(`Copied ${files.length} assets to ${targetDir}`); From dcd450ecd8282074bb0626aa66a28d5f612934b6 Mon Sep 17 00:00:00 2001 From: Carlos Reyes Date: Fri, 31 Oct 2025 20:29:06 -0700 Subject: [PATCH 3/3] Improve asset copying logic: skip directories and count copied files --- packages/editor/scripts/copy-assets.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/editor/scripts/copy-assets.js b/packages/editor/scripts/copy-assets.js index bd82c322..546dafd6 100644 --- a/packages/editor/scripts/copy-assets.js +++ b/packages/editor/scripts/copy-assets.js @@ -13,13 +13,19 @@ if (!fs.existsSync(sourceDir)) { // Create target directory fs.mkdirSync(targetDir, { recursive: true }); -// Copy all files +// Copy all files (skip directories) const files = fs.readdirSync(sourceDir); +let copiedCount = 0; + files.forEach(file => { - fs.copyFileSync( - path.join(sourceDir, file), - path.join(targetDir, file) - ); + const sourcePath = path.join(sourceDir, file); + const targetPath = path.join(targetDir, file); + + // Only copy if it's a file (not a directory) + if (fs.statSync(sourcePath).isFile()) { + fs.copyFileSync(sourcePath, targetPath); + copiedCount++; + } }); -console.log(`Copied ${files.length} assets to ${targetDir}`); +console.log(`Copied ${copiedCount} assets to ${targetDir}`);