cindy-ai-chatbot
Version:
An AI-powered chatbot component for React applications
63 lines (51 loc) • 1.76 kB
JavaScript
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
// Get __dirname equivalent in ES module
const __dirname = dirname(fileURLToPath(import.meta.url));
// Create the directory structure if it doesn't exist
const createDirIfNotExists = (dirPath) => {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
};
// Copy a file from source to destination
const copyFile = (source, destination) => {
fs.copyFileSync(source, destination);
console.log(`Copied: ${source} -> ${destination}`);
};
// Copy a 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 {
copyFile(sourcePath, destPath);
}
});
};
// Main execution
console.log('Copying assets to dist folder...');
// Create the images directory in dist
createDirIfNotExists(path.resolve(__dirname, '../dist/images'));
createDirIfNotExists(path.resolve(__dirname, '../dist/images/graph'));
// Copy images from public folder
if (fs.existsSync(path.resolve(__dirname, '../public/images'))) {
copyDir(
path.resolve(__dirname, '../public/images'),
path.resolve(__dirname, '../dist/images')
);
}
// Copy images from src/assets folder
if (fs.existsSync(path.resolve(__dirname, '../src/assets/images'))) {
copyDir(
path.resolve(__dirname, '../src/assets/images'),
path.resolve(__dirname, '../dist/images')
);
}
console.log('Assets copied successfully!');