#!/usr/bin/env node /** * Script to create the first superuser account * Run this script to set up the initial admin user for ScriptShare * * Usage: node scripts/create-superuser.js */ import readline from 'readline'; import crypto from 'crypto'; import fs from 'fs'; const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); function question(prompt) { return new Promise((resolve) => { rl.question(prompt, resolve); }); } function generateId() { return crypto.randomBytes(16).toString('hex'); } function createSuperUser(userData) { const now = new Date().toISOString(); return { id: generateId(), email: userData.email, username: userData.username, displayName: userData.displayName, avatarUrl: userData.avatarUrl, bio: userData.bio, isAdmin: true, isModerator: true, isSuperUser: true, permissions: [ 'user:create', 'user:read', 'user:update', 'user:delete', 'user:promote', 'script:approve', 'script:reject', 'script:delete', 'comment:moderate', 'system:configure', 'analytics:view', 'backup:manage' ], createdAt: now, updatedAt: now, // In a real app, this would be hashed passwordHash: crypto.createHash('sha256').update(userData.password).digest('hex') }; } async function main() { console.log('šŸš€ ScriptShare Super User Creation Tool'); console.log('=====================================\n'); try { const email = await question('Email address: '); const username = await question('Username: '); const displayName = await question('Display Name: '); const password = await question('Password: '); const bio = await question('Bio (optional): ') || ''; const avatarUrl = await question('Avatar URL (optional): ') || ''; if (!email || !username || !displayName || !password) { console.error('āŒ All required fields must be provided'); process.exit(1); } const superUser = createSuperUser({ email, username, displayName, password, bio, avatarUrl }); console.log('\nāœ… Super User Created Successfully!'); console.log('====================================='); console.log(`ID: ${superUser.id}`); console.log(`Email: ${superUser.email}`); console.log(`Username: @${superUser.username}`); console.log(`Display Name: ${superUser.displayName}`); console.log(`Super User: ${superUser.isSuperUser ? 'Yes' : 'No'}`); console.log(`Admin: ${superUser.isAdmin ? 'Yes' : 'No'}`); console.log(`Moderator: ${superUser.isModerator ? 'Yes' : 'No'}`); console.log(`Permissions: ${superUser.permissions.length} total`); console.log(`Created: ${superUser.createdAt}`); console.log('\nšŸ“‹ Next Steps:'); console.log('1. Save this user data to your database'); console.log('2. Use these credentials to log into the admin panel'); console.log('3. Create additional admin users through the web interface'); // Save to a JSON file for reference const outputPath = './superuser-account.json'; fs.writeFileSync(outputPath, JSON.stringify(superUser, null, 2)); console.log(`\nšŸ’¾ User data saved to: ${outputPath}`); } catch (error) { console.error('āŒ Error creating super user:', error.message); process.exit(1); } finally { rl.close(); } } // Handle Ctrl+C gracefully process.on('SIGINT', () => { console.log('\n\nāŒ Operation cancelled by user'); process.exit(0); }); // Run the main function main();