From 90e212a81ad20c78fd8814d66e6134473407562c Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 12 Jun 2025 13:06:24 +0530 Subject: [PATCH] feat: add copy mode --- package.json | 2 +- scripts/publish-react-components.js | 54 +++++++++++++++++------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index fbcb42608..428603d86 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,8 @@ "build:sdk": "BUILD_MODE=library vite build", "build:ui": "BUILD_MODE=ui vite build", "build:react": "BUILD_MODE=react-components vite build", + "dev:react": "BUILD_MODE=react-components vite build --watch", "package:react": "node scripts/publish-react-components.js", - "package:react:yalc-publish": "node scripts/yalc-publish-react.js", "prepare": "husky install", "size": "size-limit", "story:dev": "histoire dev", diff --git a/scripts/publish-react-components.js b/scripts/publish-react-components.js index a44857ace..367dd0a49 100644 --- a/scripts/publish-react-components.js +++ b/scripts/publish-react-components.js @@ -3,33 +3,43 @@ const path = require('path'); const { execSync } = require('child_process'); /* eslint-disable no-console */ -console.log('🚀 Building Chatwoot React Components for NPM...'); + +// Check for copy-only mode +const isCopyMode = process.argv.includes('--copyMode'); + +if (isCopyMode) { + console.log('📋 Copy mode: Copying built files to dist/react-components...'); +} else { + console.log('🚀 Building Chatwoot React Components for NPM...'); +} async function publishReactComponents() { try { - // Step 1: Clean previous builds - console.log('📦 Cleaning previous builds...'); - if (fs.existsSync('dist')) { - fs.rmSync('dist', { recursive: true, force: true }); - } - - // Clean previous React component builds - const reactFiles = [ - 'public/packs/react-components.es.js', - 'public/packs/react-components.cjs.js', - 'public/packs/style.css', - ]; - - reactFiles.forEach(file => { - if (fs.existsSync(file)) { - fs.unlinkSync(file); - console.log(` 🗑️ Removed ${file}`); + if (!isCopyMode) { + // Step 1: Clean previous builds + console.log('📦 Cleaning previous builds...'); + if (fs.existsSync('dist')) { + fs.rmSync('dist', { recursive: true, force: true }); } - }); - // Step 2: Build the React components library - console.log('🔨 Building React components...'); - execSync('pnpm build:react', { stdio: 'inherit' }); + // Clean previous React component builds + const reactFiles = [ + 'public/packs/react-components.es.js', + 'public/packs/react-components.cjs.js', + 'public/packs/style.css', + ]; + + reactFiles.forEach(file => { + if (fs.existsSync(file)) { + fs.unlinkSync(file); + console.log(` 🗑️ Removed ${file}`); + } + }); + + // Step 2: Build the React components library + console.log('🔨 Building React components...'); + execSync('pnpm build:react', { stdio: 'inherit' }); + } // Step 3: Create package directory console.log('📁 Creating package directory...');