selah-cli
Version:
Zero-setup AWS deployment for Bolt.new apps. Build in Bolt, deploy to production in 3 minutes with AI guidance.
118 lines (94 loc) • 3.92 kB
JavaScript
// Simple obfuscation script using built-in Node.js only
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
console.log('🔒 Starting code obfuscation...');
// Simple but effective obfuscation function
function obfuscateCode(code) {
// Add protection header
const header = `#!/usr/bin/env node
// Selah CLI - Production Build (Protected)
// Code obfuscated for IP protection - ${new Date().toISOString()}
// Original functionality preserved
`;
// Basic string obfuscation - encode sensitive strings
let obfuscated = code
// Obfuscate API endpoints
.replace(/https:\/\/[a-zA-Z0-9.-]+\.supabase\.co/g, 'atob("aHR0cHM6Ly9pcXFub2xxaGVjcWlxeHZlY2tjcS5zdXBhYmFzZS5jbw==")')
// Obfuscate sensitive function names
.replace(/tavusConsultation/g, '_0x1a2b3c')
.replace(/vertexAIAnalysis/g, '_0x4d5e6f')
.replace(/awsDeployment/g, '_0x7g8h9i')
// Obfuscate console logs with sensitive info
.replace(/console\.log\('(.*API.*|.*secret.*|.*key.*|.*token.*)'\)/gi, '// Protected log removed')
// Add some fake complexity
.replace(/export/g, `(function(){const _0x${Math.random().toString(36).substr(2,9)}='obfuscated';return export})()`)
// Obfuscate import paths slightly
.replace(/from '\.\/(.+)\.js'/g, `from './$1.js' /* ${Math.random().toString(36).substr(2,5)} */`);
return header + obfuscated;
}
// Function to process a file
function processFile(filePath) {
try {
console.log(`🔄 Processing: ${filePath}`);
const code = fs.readFileSync(filePath, 'utf8');
// Skip if already processed
if (code.includes('Production Build (Protected)')) {
console.log(`⏭️ Already protected: ${filePath}`);
return;
}
// Create backup
const backupPath = filePath + '.original';
if (!fs.existsSync(backupPath)) {
fs.writeFileSync(backupPath, code);
console.log(`💾 Backup created: ${backupPath}`);
}
// Obfuscate and save
const obfuscated = obfuscateCode(code);
fs.writeFileSync(filePath, obfuscated);
console.log(`✅ Protected: ${filePath}`);
} catch (error) {
console.error(`❌ Error processing ${filePath}:`, error.message);
}
}
// Function to process directory recursively
function processDirectory(dirPath) {
if (!fs.existsSync(dirPath)) {
console.error(`❌ Directory not found: ${dirPath}`);
return;
}
const items = fs.readdirSync(dirPath);
for (const item of items) {
const itemPath = path.join(dirPath, item);
const stat = fs.statSync(itemPath);
if (stat.isDirectory()) {
processDirectory(itemPath);
} else if (item.endsWith('.js') && !item.endsWith('.original')) {
processFile(itemPath);
}
}
}
// Main execution
try {
const distPath = path.join(__dirname, '..', 'dist', 'cli');
if (!fs.existsSync(distPath)) {
console.error('❌ CLI build not found. Run npm run build:cli first.');
process.exit(1);
}
console.log('🔒 Starting code protection...');
console.log(`📁 Target: ${distPath}`);
processDirectory(distPath);
console.log('');
console.log('✅ Code protection complete!');
console.log('🔐 Your CLI code is now protected for NPM publication');
console.log('💡 Original files backed up with .original extension');
console.log('');
console.log('🚀 Ready to publish:');
console.log(' npm publish');
} catch (error) {
console.error('❌ Protection failed:', error.message);
process.exit(1);
}