UNPKG

cindy-ai-chatbot

Version:

An AI-powered chatbot component for React applications

59 lines (47 loc) 1.82 kB
/* eslint-disable @typescript-eslint/no-require-imports */ const fs = require('fs'); const path = require('path'); // Function to create directory if it doesn't exist const createDirIfNotExists = (dirPath) => { if (!fs.existsSync(dirPath)) { fs.mkdirSync(dirPath, { recursive: true }); } }; // Function to copy directory recursively const copyDir = (source, destination) => { createDirIfNotExists(destination); const files = fs.readdirSync(source); files.forEach(file => { const sourcePath = path.join(source, file); const destPath = path.join(destination, file); if (fs.statSync(sourcePath).isDirectory()) { copyDir(sourcePath, destPath); } else { fs.copyFileSync(sourcePath, destPath); console.log(`Copied: ${sourcePath} -> ${destPath}`); } }); }; // Main execution try { // Get the path to the package installation directory const nodeModulesDir = path.resolve(__dirname, '..'); // Source paths const sourceImagesDir = path.join(nodeModulesDir, 'dist', 'images'); // Destination paths (project's public directory) const projectRootDir = path.resolve(nodeModulesDir, '..', '..'); const destImagesDir = path.join(projectRootDir, 'public', 'images'); // Only proceed if we're installed as a dependency if (fs.existsSync(sourceImagesDir)) { console.log('Copying Cindy ChatBot assets to public directory...'); // Create public/images directory if it doesn't exist createDirIfNotExists(path.join(projectRootDir, 'public')); // Copy images directory copyDir(sourceImagesDir, destImagesDir); console.log('Assets copied successfully!'); } } catch (error) { console.error('Error during postinstall:', error); // Don't exit with error code as it might prevent installation process.exit(0); }