-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·78 lines (71 loc) · 2.03 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
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
#!/usr/bin/env node
import pkg from 'shelljs';
const { exec } = pkg;
import prompts from 'prompts';
import ora from 'ora';
import chalk from "chalk";
var logger = {
error(...args) {
console.log(chalk.red(...args));
},
warn(...args) {
console.log(chalk.yellow(...args));
},
info(...args) {
console.log(chalk.cyan(...args));
},
success(...args) {
console.log(chalk.green(...args));
}
};
const questions = [
{
type: 'select',
name: 'templateType',
message: 'What type of template do you want to generate?',
initial: 1,
choices: [
{ title: 'Javascript', value: 'javascript' },
{ title: 'TypeScript', value: 'typescript' },
],
},
{
type: 'text',
name: 'projectName',
message: 'What is the name of your project?',
validate: function (input) {
if (!input) {
return 'You must enter a name for your project';
}
return true;
},
},
];
async function main() {
logger.info('Welcome to the Next.js template generator!');
const { templateType, projectName } = await prompts(questions);
const repoUrl =
templateType === 'typescript'
? 'https://github.com/salvaoo/Next-template-typescript.git'
: 'https://github.com/salvaoo/Next-template-javascript.git';
const spinner = ora('Starting your project...').start();
exec(`git clone ${repoUrl} ${projectName} --quiet`, (error, stdout, stderr) => {
if (error) {
spinner.fail('Error cloning repository');
console.error(stderr);
return;
}
spinner.succeed('Project created');
spinner.start('Cleaning up repository...');
exec(`cd ${projectName} && rm -rf .git`, (error, stdout, stderr) => {
if (error) {
spinner.fail('Error cleaning up repository');
console.error(stderr);
return;
}
spinner.succeed('Repository cleaned up successfully');
logger.success("Project successfully created!");
});
});
}
main();