UNPKG

@tixae-labs/web-sdk

Version:

Javascript Web SDK for doing WebRTC AI Voice Calls with Convocore.

84 lines (71 loc) 2.88 kB
import * as fs from 'fs/promises'; import * as path from 'path'; /** * Deletes all files and folders inside `rootPath` except for those * whose relative paths (from rootPath) appear in the `exceptions` array. * * @param rootPath - The directory to process. * @param exceptions - An array of paths (relative to rootPath) to keep. */ async function deleteAllExcept(rootPath: string, exceptions: string[]): Promise<void> { // Normalize exception paths for consistent matching. const exceptionsSet = new Set(exceptions.map(e => path.normalize(e))); /** * Recursively processes the directory at `currentPath`. * * @param currentPath - Absolute path of the current directory. * @param relativePath - The path relative to the original rootPath. */ async function processDirectory(currentPath: string, relativePath: string): Promise<void> { // Read the directory entries. const items = await fs.readdir(currentPath); for (const item of items) { // Build the relative path for the item. const itemRelPath = relativePath ? path.join(relativePath, item) : item; const fullItemPath = path.join(currentPath, item); // If the item is in the exceptions list, skip processing it. if (exceptionsSet.has(path.normalize(itemRelPath))) { // Do not process inside an exception folder (or delete an exception file). continue; } const stats = await fs.lstat(fullItemPath); if (stats.isDirectory()) { // Process the contents of the directory. await processDirectory(fullItemPath, itemRelPath); // After processing, check if the directory is now empty. const remaining = await fs.readdir(fullItemPath); if (remaining.length === 0) { await fs.rmdir(fullItemPath); } } else { // Delete the file. await fs.unlink(fullItemPath); } } } // Process the root directory but never remove the root itself. await processDirectory(rootPath, ''); } // --- Main build cleanup --- async function main() { // First, delete everything except the web-call src await deleteAllExcept('./dist', ['src/public_packages/web-call']); // Move files from nested location to dist root const nestedSrc = './dist/src/public_packages/web-call/src'; const distRoot = './dist'; // Check if the nested structure exists try { const files = await fs.readdir(nestedSrc); // Move each file to dist root for (const file of files) { const srcPath = path.join(nestedSrc, file); const destPath = path.join(distRoot, file); await fs.rename(srcPath, destPath); } // Clean up empty nested directories await fs.rm('./dist/src', { recursive: true, force: true }); } catch (err) { console.error('Error moving files:', err); } } main().catch(console.error);