-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (35 loc) · 1.38 KB
/
index.js
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
#!/usr/bin/env node
import { execa } from 'execa';
import path from 'path';
import { readFileSync } from 'fs';
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
async function initProject(template, projectName) {
const templates = {
"node-ts": "https://github.com/florob95/node-ts-starter-kit.git",
"node-grpc": "https://github.com/florob95/node-grpc-starter-kit.git",
"node-nest": "https://github.com/florob95/node-nest-starter-kit.git",
};
if (!templates[template]) {
console.error(`\x1b[31m Template not found: ${template} \x1b[0m`);
process.exit(1);
}
const projectPath = path.resolve(process.cwd(), projectName);
try {
await execa('git', ['clone', templates[template], projectPath]);
await execa('rm', ['-rf', `${projectPath}/.git`]);
console.log(`\x1b[32m Project "${projectName}" created successfully! \x1b[0m`);
} catch (error) {
console.error('\x1b[31m Error while cloning: \x1b[0m', error);
process.exit(1);
}
}
const [, , arg1, arg2] = process.argv;
if (arg1 === '-v' || arg1 === '--version') {
console.log(`\x1b[30m \x1b[42m Forge version: ${packageJson.version} \x1b[0m`);
process.exit(0);
}
if (!arg1 || !arg2) {
console.error("Usage: forge <template> <project-name>");
process.exit(1);
}
initProject(arg1, arg2);