// CAUTION ==== CAUTION ==== CAUTION ==== CAUTION ==== // !!! Modifying this file is NOT recommended !!! // Incorrect modification of this file may result // in inability to start this application // =================================================== const { exec } = require('child_process'); const fs = require('fs'); const util = require('util'); const execProm = util.promisify(exec); const repoName = 'website' // Change to match actual repo name on git.tcf.ventures // Simple sleep function using a promise function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } // Simulated progress bar to enhance visual appeal during operations async function showLoadingBar(chalkColor) { const progressBarLength = 20; // Length of the progress bar let progressBar = ''; process.stdout.write(chalkColor(`\r[${progressBar}${' '.repeat(progressBarLength)}] 0%`)); return (progress) => { const filledLength = Math.round(progressBarLength * progress); progressBar = chalkColor('ā–ˆ'.repeat(filledLength)); const emptyBar = ' '.repeat(progressBarLength - filledLength); process.stdout.write(chalkColor(`\r[${progressBar}${emptyBar}] ${Math.round(progress * 100)}%`)); if (progress === 1) { console.log(); // Finish with a newline when complete } }; } // Function to execute shell commands with progress tracking and minimal logging async function executeCommand(command, preMessage, successMessage, chalkColor) { console.log(chalkColor(preMessage)); const updateProgress = await showLoadingBar(chalkColor); try { await execProm(command, { maxBuffer: 1024 * 5000 }); updateProgress(1); // Ensure the bar fills to 100% once command execution completes console.log(chalkColor(`āœØ ${successMessage}`)); } catch (error) { updateProgress(1); // Ensure the bar fills to 100% even on error console.error(chalkColor(`āŒ Error during ${command}: ${error.message}`)); } } // Read the 'main' script from package.json and run it async function runMainScript() { const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')); const mainScript = packageJson.main || 'index.js'; // Default to index.js if not specified return `node ${mainScript}`; } // Main function to orchestrate the setup and run with enhanced visuals async function main() { console.log("\n\nšŸŒŸ Welcome to the Setup Wizard! Let's get started... šŸŒŸ\n"); // Install chalk version 4.1.2 specifically await executeCommand( 'npm install chalk@4.1.2', 'šŸŽØ Installing chalk 4.1.2... Please wait as we add some color to your life!.', 'Chalk 4.1.2 installed\n', msg => msg ); // Now that chalk is installed, require it for future logs const chalk = require('chalk'); // Initialize fresh git just in case its not already await executeCommand( 'git init', 'āš™ļø Initializing git... Git-er done.', 'Git initialized\n', chalk.yellow ); // Pull latest files from #main branch // Its a read-only access token, don't worry await executeCommand( 'git pull https://username:access-token@git.tcf.ventures/TCF-Ventures-LLC/' + repoName, 'šŸ“„ Importing repo files... Are these your files? šŸƒ', 'Files Imported\n', chalk.green ); // Install remaining dependencies await executeCommand( 'npm install', 'šŸ”§ Installing other dependencies... This might take a few seconds.', 'Dependencies installed\n', chalk.blue ); // Run the main script from package.json const runCommand = await runMainScript(); await executeCommand( runCommand, 'šŸŒˆ Setup Complete! Your application is ready to go! šŸš€\n', // 'šŸš€ Launching the application... Hold tight, we're almost there!', //'šŸŒˆ Setup Complete! Your application is ready to go! šŸš€\n', '\n', chalk.magentaBright ); console.log(chalk.magentaBright('\n')); } main();