-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnql.js
More file actions
69 lines (61 loc) · 1.35 KB
/
nql.js
File metadata and controls
69 lines (61 loc) · 1.35 KB
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
#!/usr/bin/env node
const inquirer = require("inquirer"); // cmd
const chalk = require("chalk");
const figlet = require("figlet");
// const shell = require("shelljs");
let path = require('path')
let baseUrl = path.join(__dirname , '/data')
let nodedb = require('node-edb')
nodedb.init(baseUrl,'db')
const init = () => {
console.log(chalk.green(
figlet.textSync("node db", {
font: "Ghost",
horizontalLayout: "default",
verticalLayout: "default"
})
));
}
const askQuestions = () => {
const questions = [
{
name: "cmd",
type: "input",
message: "->"
},
];
return inquirer.prompt(questions);
};
const reCmd = async() => {
const answers = await askQuestions();
const { cmd } = answers;
let str = ''
switch(cmd){
case 'exit':
break;
default:
try{
let result = eval(`nodedb.execute.${cmd}`)
if(result){
str = result
}else{
str = `${cmd} is not a normal command!`
}
}catch(e){
console.log(e)
str = `${cmd} is not a normal command!`
}
console.log(str)
reCmd();
break;
}
}
const run = async () => {
// show script introduction
init();
// ask questions
reCmd();
// create the file
// show success message
};
run();