-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
95 lines (79 loc) · 2.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
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
#!/usr/bin/env node
const yargs = require("yargs");
const chalk = require("chalk");
const boxen = require("boxen");
const clear = require('clear');
const figlet = require('figlet');
const os = require('os');
const _7z = require('7zip-min'); // 7z extract
const ora = require('ora'); // Loading animation
/******************
* Reading Arguments
******************/
const options = yargs
.usage("Usage: -n <name>")
.option("n", {
alias: "name",
describe: "Your project name",
type: "string",
demandOption: true
})
.argv;
// A message to user
msg = `
Creat react app offline
Hello! i'm going to make it as fast as i can.`
createContent(msg,true);
// unzip project to folder
UnzipToFolder(__dirname + '/react-src/react.7z', options.name)
// Just succsess MSG
function succsessMSG(foldername) {
usefulCMD = chalk.blue.bold('Enjoy, here are some useful commands.') + "\n\n";
usefulCMD += "- Go to your project folder \n" + chalk.red.bold(' cd ' + foldername) + '\n\n';
usefulCMD += "- Runs the app in development mode. \n" + chalk.red.bold(' npm start ') + '\n\n';
usefulCMD += "- Runs the test watcher in an interactive mode. \n" + chalk.red.bold(' npm test') + '\n\n';
usefulCMD += "- Builds the app for production to the build folder. \n" + chalk.red.bold(' npm run build') + '\n\n';
console.log(usefulCMD);
}
// for unzipping react to process folder
function UnzipToFolder(src, foldername) {
const spinner = ora('Making some magic !').start();
let target = process.cwd() + '/' + foldername
_7z.unpack(src, target, (err, result) => {
if(err){
message = chalk.white.bold('Something bad happend here is the error msg :\n\n\n' + err);
createContent(message, true);
}else{
spinner.stop();
message = chalk.white.bold('Project Created successfully');
createContent(message, true);
succsessMSG(foldername);
}
});
}
// for creating the Header
function createHeader() {
clear();
console.log(
chalk.yellow(
figlet.textSync('C-R-A-O', {
horizontalLayout: 'full'
})
)
);
}
// For Creating nice content
function createContent(message, wh = false) {
if (wh) {
createHeader()
}
const boxenOptions = {
padding: 1,
margin: 1,
borderStyle: "round",
borderColor: "green",
align: "canter"
};
const msgBox = boxen(message, boxenOptions);
console.log(msgBox);
}