minikit-limpo-template
Version:
A minimal Next.js app starter template with WorldCoin MiniKit authentication integration
116 lines (95 loc) • 4.46 kB
JavaScript
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const readline = require('readline');
// ANSI color codes for better terminal output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
green: '\x1b[32m',
blue: '\x1b[34m',
cyan: '\x1b[36m',
yellow: '\x1b[33m',
red: '\x1b[31m'
};
function printBanner() {
console.log(`${colors.cyan}${colors.bright}`);
console.log('╔═══════════════════════════════════════════════════╗');
console.log('║ ║');
console.log('║ 🌐 MiniKit Next.js Limpo Template Creator ║');
console.log('║ ║');
console.log('╚═══════════════════════════════════════════════════╝');
console.log(`${colors.reset}`);
}
printBanner();
// Parse arguments
const args = process.argv.slice(2);
const projectName = args[0];
if (!projectName) {
console.error(`${colors.red}Please specify a project name:${colors.reset}`);
console.error(` npx minikit-limpo-template ${colors.bright}my-app${colors.reset}`);
process.exit(1);
}
const projectPath = path.resolve(process.cwd(), projectName);
// Create project directory
if (fs.existsSync(projectPath)) {
console.error(`${colors.red}Error: Directory ${colors.bright}${projectName}${colors.reset}${colors.red} already exists.${colors.reset}`);
console.error(`Please choose a different name or delete the existing directory.`);
process.exit(1);
}
console.log(`${colors.bright}Creating a new MiniKit Next.js app in ${colors.green}${projectPath}${colors.reset}...\n`);
try {
// Create the project directory
fs.mkdirSync(projectPath, { recursive: true });
// Copy template files
const templatePath = path.resolve(__dirname, '../template');
if (!fs.existsSync(templatePath)) {
console.error(`${colors.red}Error: Template directory not found at ${templatePath}${colors.reset}`);
console.error(`This might be due to an improper installation of the package.`);
process.exit(1);
}
console.log(`${colors.blue}Copying template files...${colors.reset}`);
copyDirectoryRecursively(templatePath, projectPath);
// Create .env.local file
const envPath = path.join(projectPath, '.env.local');
fs.writeFileSync(
envPath,
'NEXT_PUBLIC_APP_ID=app_staging_...\n\n# Replace with your World ID App ID from https://developer.worldcoin.org/'
);
// Run setup script
console.log(`${colors.blue}Setting up project...${colors.reset}`);
// Install dependencies
console.log(`${colors.blue}Installing dependencies... ${colors.yellow}(This may take a few minutes)${colors.reset}`);
execSync('npm install', { cwd: projectPath, stdio: 'inherit' });
console.log(`\n${colors.green}${colors.bright}🎉 Success! Your MiniKit starter app is ready.${colors.reset}`);
console.log(`\n${colors.bright}Next steps:${colors.reset}`);
console.log(` 1. ${colors.cyan}cd ${projectName}${colors.reset}`);
console.log(` 2. ${colors.cyan}Add your World ID App ID to .env.local${colors.reset}`);
console.log(` 3. ${colors.cyan}npm run dev${colors.reset}`);
console.log(`\nFor more information, see the ${colors.bright}README.md${colors.reset} file.\n`);
} catch (error) {
console.error(`${colors.red}An error occurred during setup:${colors.reset}`, error);
console.error(`${colors.red}Please try again or report this issue.${colors.reset}`);
process.exit(1);
}
// Helper function to copy directory recursively
function copyDirectoryRecursively(source, destination) {
// Create destination directory if it doesn't exist
if (!fs.existsSync(destination)) {
fs.mkdirSync(destination, { recursive: true });
}
// Get all files and directories in the source directory
const entries = fs.readdirSync(source, { withFileTypes: true });
for (const entry of entries) {
const sourcePath = path.join(source, entry.name);
const destinationPath = path.join(destination, entry.name);
if (entry.isDirectory()) {
// Recursively copy directories
copyDirectoryRecursively(sourcePath, destinationPath);
} else {
// Copy files
fs.copyFileSync(sourcePath, destinationPath);
}
}
}