feat: add copy mode

This commit is contained in:
Shivam Mishra
2025-06-12 13:06:24 +05:30
parent 76e1643ccf
commit 90e212a81a
2 changed files with 33 additions and 23 deletions
+1 -1
View File
@@ -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",
+32 -22
View File
@@ -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...');