UNPKG

local-id-scan-journey

Version:

A React component for GBG ID verification and document scanning with bundled SDK

120 lines (100 loc) 4.53 kB
#!/usr/bin/env node import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); // Function to copy SDK files to the consuming project's public directory function copySdkFiles() { try { const packageDir = path.dirname(__dirname); const distDir = path.join(packageDir, 'dist'); // Find the consuming project's public directory let currentDir = process.cwd(); let publicDir = null; // Look for public directory in the current project while (currentDir !== path.dirname(currentDir)) { const potentialPublicDir = path.join(currentDir, 'public'); if (fs.existsSync(potentialPublicDir)) { publicDir = potentialPublicDir; break; } currentDir = path.dirname(currentDir); } if (!publicDir) { console.warn('Warning: Could not find public directory. Please manually copy SDK files from node_modules/local-id-scan-journey/dist/ to your public directory.'); return; } // Check if SDK files already exist in public directory (from workspace) const workspacePublicDir = path.resolve(packageDir, '../../public'); const sourceDir = fs.existsSync(workspacePublicDir) ? workspacePublicDir : distDir; console.log(`Copying SDK files from: ${sourceDir}`); console.log(`Copying SDK files to: ${publicDir}`); if (!fs.existsSync(sourceDir)) { console.warn(`Source directory not found: ${sourceDir}`); return; } // Get all files from source directory const allFiles = fs.readdirSync(sourceDir); // Filter for SDK-related files const sdkFiles = allFiles.filter(file => { return file.includes('vendor.') || file.includes('idscan-jcs-') || file.includes('ides-micro.') || file.includes('idesmicro_asm') || file.endsWith('.wasm') || file.endsWith('.js') && ( file.includes('vendor') || file.includes('idscan') || file.includes('ides') ); }); let copiedCount = 0; sdkFiles.forEach(fileName => { const srcPath = path.join(sourceDir, fileName); const destPath = path.join(publicDir, fileName); try { if (fs.existsSync(srcPath)) { // Only copy if file doesn't exist or is different let shouldCopy = true; if (fs.existsSync(destPath)) { const srcStats = fs.statSync(srcPath); const destStats = fs.statSync(destPath); shouldCopy = srcStats.size !== destStats.size || srcStats.mtime > destStats.mtime; } if (shouldCopy) { fs.copyFileSync(srcPath, destPath); console.log(`✓ Copied ${fileName}`); copiedCount++; } else { console.log(`- Skipped ${fileName} (already up to date)`); } } } catch (error) { console.error(`Error copying ${fileName}:`, error.message); } }); if (copiedCount > 0) { console.log(`\n✓ Successfully copied ${copiedCount} SDK files to public directory!`); } else { console.log('\n✓ All SDK files are already up to date in public directory!'); } // List all vendor files found for debugging const vendorFiles = allFiles.filter(f => f.includes('vendor.')); if (vendorFiles.length > 0) { console.log(`\nFound ${vendorFiles.length} vendor files:`); vendorFiles.slice(0, 5).forEach(f => console.log(` - ${f}`)); if (vendorFiles.length > 5) { console.log(` ... and ${vendorFiles.length - 5} more`); } } } catch (error) { console.error('Error copying SDK files:', error); console.log('Please manually copy the files from the GBG SDK to your public directory.'); } } // Run the function if this script is executed directly if (import.meta.url === `file://${process.argv[1]}`) { copySdkFiles(); } export default copySdkFiles;