This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
149 lines (135 loc) · 4.19 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env node
'esversion: 6';
const chalk = require("chalk");
const figlet = require("figlet");
const inquirer = require("inquirer");
const fs = require("fs");
const {
cwd
} = require("process");
const pathBase = process.cwd(); // Get current working directory.
const msn = (msn) => {
console.log(
chalk.bold.red(
figlet.textSync(msn, {
font: "ANSI Shadow",
horizontalLayout: "default",
verticalLayout: "default",
})
)
);
}; // Customize our nice message.
const queryParams = () => { //Questions!
const qs = [{
name: "name",
type: "input",
message: "Please specify your game name.\n",
},
{
name: "port",
type: "input",
message: "Please specify your preferred Port.\n",
},
{
name: "gameid",
type: "input",
message: "Please specify your game ID.\n",
},
{
name: "local",
type: "confirm",
message: "Run the server locally?.\n",
},
{
name: "template",
type: "list",
message: "Select a template",
choices: [
"Empty Installation",
"Data Saving Template",
"Sword Fighting Template",
"Gun Fighting Template",
],
},
{
name: "version",
type: "list",
message: "Select a node-hill version. (Latest is the best)",
choices: [
"Node-Hill 8.5.0 [Important Fixes]",
"Node-Hill 8.4.6 [MessageAll replacement]",
"Node-Hill 8.4.5 [Security patch]",
"Node-Hull 8.4.4 [Various Fixes]",
"Node-Hill 8.4.3 [Player Moved Event]",
"Node-hill 8.4.2 [Brick Collision Detection]",
],
},
];
return inquirer.prompt(qs);
};
const createFile = (data) => {
try {
var fs = require('fs');
scripts = `${data.name}/user_scripts`
maps = `${data.name}/maps`
fs.mkdirSync(scripts,{recursive: true});
fs.mkdirSync(maps, {recursive: true});
fs.writeFile(`${process.cwd()}/${data.name}/user_scripts/index.js`, `console.log("Here goes your script bois!");`, function (err) {
if (err) {
return console.log(err);
}
console.log("Done");
});
fs.writeFile(`${process.cwd()}/${data.name}/start.js`, `
// Generated using Node-Hill-CLI by Edge.
const nh = require('node-hill');
nh.startServer({
gameId: ${data.gameid} ,
port: ${data.port},
local: ${data.local} ,
map: './maps/example.brk',
scripts: './user_scripts',
modules: []
})
`, function (err) {
if (err) {
return console.log(err);
}
console.log("Done");
});
switch (data.template) {
case "Sword Fighting Template":
console.log("Starting to generate files...");
console.log("Sorry but this is work in progress!");
break;
case "Empty Installation":
break;
case "Data Saving Template":
console.log("Generating Data Saving Template...");
console.log("Sorry but this is work in progress!")
break;
case "Gun Fighting Template":
console.log("Generating Gun Fighting Template...");
console.log("Sorry but this is work in progress!")
break;
case null || undefined:
console.log("Empty input, generating default...");
break;
}
} catch (err) {
console.log(err);
} finally {
console.log(`
------ CREATED ------\n
The Template has been created.\n
- PORT: ${chalk.blue.bold(data.port)}\n
- TEMPLATE: ${chalk.blue.bold(data.template)}\n
----------------------------------\n
`);
}
};
// Invoke a function...
(async () => {
msn("NH-CLI");
createFile(await queryParams());
})();