-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
147 lines (118 loc) · 2.92 KB
/
index.js
File metadata and controls
147 lines (118 loc) · 2.92 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
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
#!/usr/bin/env node
/**
* @author manelcecs
* @email manuelc.p.g@gmail.com
* @create date 2020-07-20 10:13
* @modify date 2020-07-20 10:13
* @desc main file for NSSPA-CLI
*/
//Require libs
const chalk = require('chalk'),
clear = require('clear'),
figlet = require('figlet');
const version = require('./package.json').version;
const files = require('./lib/files');
const inquirer = require('./lib/inquirer');
//Shared variables
var serverFileName = '';
/**
* Step 1
*
* Start CLI
*/
greetings();
/**
* Step 2
*
* Basic info CLI
*/
basicInfo();
/**
* Step 3
*
* Request data and write file
*/
requestData();
//Private methods
//Greetings
function greetings() {
//Clear console
clear();
//CLI name
console.log(
chalk.green(
figlet.textSync('NSSPA - CLI', { horizontalLayout: 'full' })
)
);
//Description & author
console.log(
chalk.yellow(
'\t Simple Express Server for SPA. '
+
'v' + version
+
'\n'
+
'\t Author: @manelcecs'
)
);
}
//BasicInfo
function basicInfo() {
console.log(
chalk.magenta(
'\n\t Please, be conscient of your inputs.\n'
+
'\t Besides all prompted input will be validated,\n'
+
'\t I cannot ensure if your dir paths, variables or scripts\n'
+
'\t are correct. Thanks for using me.\n'
)
);
}
//Request Data
function requestData() {
getServerName().then((serverName) => {
//We have the server file
serverFileName = serverName;
//Lets get the config data
getServerConfigData().then((data) => {
files.writeServerFile(serverFileName, data);
}).finally(() => {
files.editPackage();
goodBye();
});
});
}
async function getServerName() {
let name = await inquirer.askServerFilename();
if (name) {
name = inquirer.validateExtension(name.name, 'js', 'server.js');
}
return name;
};
async function getServerConfigData() {
var data = await inquirer.askServerConfigData();
if (data) {
data.access = inquirer.validateExtension(data.access, 'html', 'index.js');
data.localPort = (data.localPort == '') ? '3030' : data.localPort;
data.distDir = (data.distDir == '') ? '<rootFolder>/dist/<appName>' : data.distDir;
}
return data;
}
function writeServerFile(serverFileName, data) {
files.writeServerFile(serverFileName, data);
}
//GoodBye
function goodBye() {
console.log(
chalk.yellow(
"\nThanks for using NSSPA-CLi" +
"\nDo no forget to run: npm install express." +
"\nCheck if the server file was correclty creadted." +
"\nIf not, don't hesitate to contact me to solve the error." +
"\nSincerely, @manelececs"
)
);
}