UNPKG

netcore-blueprint

Version:

A custom .NET Core project blueprint

76 lines (59 loc) 2.66 kB
#!/usr/bin/env node const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); // ✅ Fix: Import execSync // Get the project name from command-line arguments const projectName = process.argv[2]; if (!projectName) { console.error("❌ Please specify the project name."); process.exit(1); } const templatePath = path.join(__dirname, "BlueprintTemplate"); // Copy from BlueprintTemplate const destinationPath = path.join(process.cwd(), projectName); // Function to copy and rename files function copyAndRenameFiles(src, dest, oldName, newName) { if (fs.lstatSync(src).isDirectory()) { fs.mkdirSync(dest, { recursive: true }); const entries = fs.readdirSync(src, { withFileTypes: true }); for (let entry of entries) { let srcPath = path.join(src, entry.name); let destPath = path.join(dest, entry.name.replace(new RegExp(oldName, 'g'), newName)); copyAndRenameFiles(srcPath, destPath, oldName, newName); } } else { let content = fs.readFileSync(src, 'utf8'); content = content.replace(new RegExp(oldName, 'g'), newName); // Replace occurrences of Blueprint fs.writeFileSync(dest, content, 'utf8'); } } // Ensure the destination folder doesn't already exist if (fs.existsSync(destinationPath)) { console.error(`❌ Project directory "${projectName}" already exists.`); process.exit(1); } fs.mkdirSync(destinationPath, { recursive: true }); // Copy and rename all files fs.readdirSync(templatePath).forEach(item => { const srcPath = path.join(templatePath, item); let destPath = path.join(destinationPath, item.replace(/Blueprint/g, projectName)); if (item === "gitignore") { destPath = path.join(destinationPath, ".gitignore"); // Rename gitignore } console.log(`✅ Copying and renaming ${item}...`); copyAndRenameFiles(srcPath, destPath, "Blueprint", projectName); }); console.log(`🎉 Project "${projectName}" created successfully at ${destinationPath}`); console.log(`📌 Open "${projectName}.sln" in Visual Studio to get started!`); // Initialize Git and commit the first commit try { process.chdir(destinationPath); // Move into project directory console.log("🚀 Initializing Git repository..."); execSync('git init', { stdio: 'inherit' }); console.log("📂 Adding all files..."); execSync('git add .', { stdio: 'inherit' }); console.log("✅ Creating first commit..."); execSync('git commit -m "Initial commit from netcore-blueprint"', { stdio: 'inherit' }); console.log("🎉 Git repository initialized successfully!"); } catch (error) { console.error("❌ Failed to initialize Git:", error); }