netcore-blueprint
Version:
A custom project blueprint
60 lines (46 loc) • 1.71 kB
JavaScript
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const projectName = process.argv[2];
if (!projectName) {
console.error("❌ Please specify the project name.");
process.exit(1);
}
const templatePath = path.join(__dirname, "..", "BlueprintTemplate");
const destinationPath = path.join(process.cwd(), projectName);
if (fs.existsSync(destinationPath)) {
console.error(`❌ Project directory "${projectName}" already exists.`);
process.exit(1);
}
try {
// 1️⃣ Copy template
copyDirectory(templatePath, destinationPath);
// 2️⃣ Rename gitignore -> .gitignore
const gitignoreTemplatePath = path.join(destinationPath, 'gitignore');
const finalGitignorePath = path.join(destinationPath, '.gitignore');
if (fs.existsSync(gitignoreTemplatePath)) {
fs.renameSync(gitignoreTemplatePath, finalGitignorePath);
}
console.log(`🎉 Project "${projectName}" created successfully!`);
// 3️⃣ Initialize git
process.chdir(destinationPath);
execSync('git init', { stdio: 'inherit' });
execSync('git add .', { stdio: 'inherit' });
execSync('git commit -m "Initial commit from blueprint"', { stdio: 'inherit' });
} catch (err) {
console.error("⚠️ Git init failed:", err.message);
}
function copyDirectory(src, dest) {
fs.mkdirSync(dest, { recursive: true });
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirectory(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}