-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (49 loc) · 1.57 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
#!/usr/bin/env node
const { program } = require('commander');
const chalk = require('chalk');
const createFileFolder = require('./utils');
const { createSpinner } = require('nanospinner');
const package = require('./package.json');
const log = console.log;
program
.version(package.version)
.description('A React Component Generator')
.parse();
const path = process.cwd();
const spinner = createSpinner(chalk.yellow('Creating File...')).start();
if (program.args.length === 0) {
setTimeout(() => {
log(chalk.redBright('Please Enter a Folder(s)/File Name !'));
}, 500);
} else if (program.args.length === 1) {
let fileName = program.args[0];
fileName = fileName[0].toUpperCase() + fileName.slice(1);
if (path.includes('src') || path.includes('public')) {
log(chalk.red('You should be in the root directory of your project!'));
} else {
setTimeout(() => {
createFileFolder(fileName);
spinner.success({
text: chalk.green(`${fileName} Component Created...`),
});
}, 2000);
}
} else {
try {
const folderName = program.args[0];
let fileName = program.args[1];
fileName = fileName[0].toUpperCase() + fileName.slice(1);
if (path.includes('src') || path.includes('public')) {
log(chalk.red('You should be in the root directory of your project!'));
} else {
setTimeout(() => {
createFileFolder(fileName, folderName, true);
spinner.success({
text: chalk.green(`${fileName} Component Created...`),
});
}, 2000);
}
} catch (err) {
log(chalk.bgRed.white(err.message));
}
}