-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
105 lines (87 loc) · 3.28 KB
/
Copy pathinit.js
File metadata and controls
105 lines (87 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Parse command line arguments
const args = process.argv.slice(2);
let targetDir = process.cwd();
let templateName = 'default';
// Parse directory and template options
for (let i = 0; i < args.length; i++) {
if (args[i] === '--template' && args[i + 1]) {
templateName = args[i + 1];
i++;
} else if (!args[i].startsWith('-')) {
targetDir = path.resolve(process.cwd(), args[i]);
}
}
const validTemplates = ['default', 'blog', 'portfolio', 'docs'];
if (!validTemplates.includes(templateName)) {
console.error(`❌ Error: Invalid template "${templateName}"`);
console.error(` Valid templates: ${validTemplates.join(', ')}`);
process.exit(1);
}
function copyRecursive(src, dest, stats) {
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()) {
if (!fs.existsSync(destPath)) {
fs.mkdirSync(destPath, { recursive: true });
}
copyRecursive(srcPath, destPath, stats);
} else {
if (!fs.existsSync(destPath)) {
fs.copyFileSync(srcPath, destPath);
console.log(` ✓ Created ${path.relative(targetDir, destPath)}`);
stats.filesCreated++;
} else {
console.log(` ⊘ Skipped ${path.relative(targetDir, destPath)} (already exists)`);
stats.filesSkipped++;
}
}
}
}
function init() {
console.log(`🎬 Initializing Minuto project with "${templateName}" template...\n`);
// Create target directory if it doesn't exist
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
console.log(` ✓ Created directory: ${targetDir}\n`);
}
// Find template source directory
const templateSrc = path.join(__dirname, 'templates', templateName);
// Check if template exists
if (!fs.existsSync(templateSrc)) {
console.error(`❌ Error: Template directory not found: ${templateSrc}`);
console.error(' Please ensure templates are installed correctly.');
process.exit(1);
}
// Check if project already has content
const contentExists = fs.existsSync(path.join(targetDir, 'content'));
const templatesExists = fs.existsSync(path.join(targetDir, 'templates'));
if (contentExists || templatesExists) {
console.log('⚠️ Warning: content/ or templates/ already exists.');
console.log('This will create example files but won\'t overwrite existing ones.\n');
}
const stats = { filesCreated: 0, filesSkipped: 0 };
// Copy template files
copyRecursive(templateSrc, targetDir, stats);
console.log(`\n✨ Initialization complete!`);
console.log(` Template: ${templateName}`);
console.log(` Created ${stats.filesCreated} files`);
if (stats.filesSkipped > 0) {
console.log(` Skipped ${stats.filesSkipped} files (already existed)`);
}
console.log('\n📦 Next steps:');
if (targetDir !== process.cwd()) {
console.log(` 1. cd ${path.relative(process.cwd(), targetDir)}`);
console.log(' 2. npm install');
console.log(' 3. npm run dev');
} else {
console.log(' 1. npm install');
console.log(' 2. npm run dev');
}
console.log(' 4. Open http://localhost:3000\n');
}
init();