-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
76 lines (57 loc) · 1.46 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
#!/usr/bin/env node
const inquirer = require("inquirer");
const chalk = require("chalk");
const shell = require("shelljs");
const figlet = require("figlet");
const init = () => {
console.log(
chalk.bgBlue.yellow(
figlet.textSync("Simple Node CLI\n\n", {
// font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default"
})
)
);
};
const askQuestions = () => {
const questions = [
{
name: "FILENAME",
type: "input",
message: "What is the name of the file without extension?"
},
{
type: "list",
name: "EXTENSION",
message: "What is the file extension?",
choices: [".rb", ".js", ".txt", ".html", ".php", ".css"],
filter: function(val) {
return val.split(".")[1];
}
}
];
return inquirer.prompt(questions);
};
const createFile = (filename,extension) => {
const filePath = `${process.cwd()}/${filename}.${extension}`
shell.touch(filePath);
return filePath;
};
const success = (filepath) => {
console.log(
chalk.white.bgGreen.bold(`Done! file created at ${filepath}`)
);
};
const run = async () => {
//show script intro
init();
// ask questions
const answers = await askQuestions();
const { FILENAME, EXTENSION } = answers;
//create file
const filePath = createFile(FILENAME,EXTENSION);
// show success
success(filePath);
};
run();