This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.js
269 lines (267 loc) · 10.6 KB
/
start.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/* EnderAdel */
const { start } = require("repl");
const readline = require("readline"), fs = require("fs"), spawn = require('child_process').spawn, execute = (content = null, exit_callback = function(){}, stdout_callback = function(){}, stderr_callback = function(){}) => {
if(content == null || content === undefined){
console.warn("The content is missing!");
}else{
const path_ = __dirname + "\\process\\executables\\", filePath_ = path_ + "executable-" + Math.round(Math.random()*10000000000000000000) + ".bat";
fs.writeFile(filePath_, content, function(error){
if(error){
console.error(error);
}else{
var process_ = spawn('cmd.exe', ['/c', filePath_]);
process_.stdout.on('data', function(data){
stdout_callback(data);
});
process_.stderr.on('data', function(data){
stderr_callback(data);
});
process_.on('exit', function(code){
exit_callback(code);
});
}
});
}
}, rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
}), parse = data => {
console.log("[EnderHelper] DEBUG: " + data);
return data.replace(/\s/g, "").toLocaleLowerCase();
}, _parse = data => {
var loop = function(){
if(data.substring(0, 1) == " "){
data = data.substring(1);
loop();
}
};
loop();
loop = function(){
if(data.substring(data.length - 1) == " "){
data = data.substring(0, data.length - 1);
loop();
}
};
loop();
if(data.substring(data.length - 1) !== "\\")
data += "\\";
console.log("[EnderHelper] DEBUG: " + data);
return data;
};
var helpMessage = "[EnderHelper] MESSAGE: Here is a list of the avaliable commands to use:\n - help\n - close\n - clear\n - save\n - build\n - build-full", processPath;
rl.question("Enter your project's path: ", function(data){
processPath = _parse(data);
startFunction();
});
const d = data => {
if(data.indexOf("help") == 0){
console.log(helpMessage);
startFunction();
}else if(data.indexOf("close") == 0){
process.exit(0);
}else if(data.indexOf("clear") == 0){
console.clear();
startFunction();
}else if(data.indexOf("build") == 0){
build();
}else if(data.indexOf("build-full") == 0){
build(function(path){
pack(path);
});
}else if(data.indexOf("save") == 0){
save();
}else{
console.log("[EnderHelper] ERROR: There is no such command");
console.log(helpMessage);
startFunction();
}
}, startFunction = () => {
rl.question("EnderHelper ~ ", function(command){
command = parse(command);
d(command);
});
}, save = () => {//Fix this!
(function(){
fs.access(processPath + ".git/", function(error){
var done = function(){
rl.question("EnderHelper [Save] ~ Enter a tag: ", function(data){
rl.question("EnderHelper [Save] ~ Enter a comment: ", function(data2){
execute("cd \"" + processPath + "\ngit tag \"" + data + "\"\n git commit -m \"" + data2 + "\"\ngit status\ngit pull origin master\ngit push -u origin master", function(code){
console.log("[Git] exit code: " + code);
if(code === 0){
console.log("[EnderHelper] MESSAGE: Done!");
startFunction();
}else{
console.log("[EnderHelper] ERROR: An error has occurred!");
startFunction();
}
}, function(data){
console.log(data.toString('utf8'));
}, function(data){
console.log(data.toString('utf8'));
});
});
});
};
if(error){
//It's the first time
/*
git init
git add .
git commit -m "first commit"
git remote add origin [origin_link] ##https://github.com/EnderAdel/EnderFramework.git
git tag v0.000.00-first
git push -u origin master
*/
rl.question("EnderHelper [Save] ~ Enter your origin link: ", function(data){
//
execute("cd \"" + processPath + "\"\ngit init\ngit add .\ngit commit -m \"first commit\"\ngit remote add origin " + data + "\ngit tag v0.000.00-first\n", function(code){
console.log("[Git] exit code: " + code);
if(code === 0){
//done
console.log("[EnderHelper] MESSAGE: this project is ready!");
done();
}else{
console.log("[EnderHelper] ERROR: An error has occurred!");
startFunction();
}
//done();
}, function(data){
console.log(data.toString('utf8'));
}, function(data){
console.log(data.toString('utf8'));
});
});
}else{
done();
}
});
})();
}, build = (callback = null) => {
rl.question("EnderHelper [Build] ~ Enter the output folder path: ", function(outputPath){
outputPath = _parse(outputPath);
rl.question("EnderHelper [Build] ~ Enter your project's name: ", function(name){
rl.question("EnderHelper [Build] ~ Enter your icon path: ", function(icon){
execute("cd \"" + processPath + "\"\nnpm outdated", function(code){
if(code === 0){
console.log("[EnderHelper] MESSAGE: all the modules are updated");
execute("cd \"" + processPath + "\"\nelectron-packager . " + name + " --all --icon=" + icon + " no-junk no-prune", function(code){
console.log("[Electron-Packager] exit code: " + code);
if(code === 0){
console.log("[EnderHelper] MESSAGE: this project is ready!");
console.log("[EnderHelper] MESSAGE: moving the files...");
//done();
//
//move example new
fs.mkdir(outputPath + "builds\\", function(err){
if(err){
console.log(err);
console.log("[EnderHelper] ERROR: An error has occurred!");
startFunction();
}else{
execute("cd \"" + processPath + "\"\nmove \"" + name + "-linux-ia32\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-win32-ia32\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-darwin-x64\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-linux-x64\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-mas-x64\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-win32-x64\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-linux-armv7l\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-linux-arm64\" \"" + outputPath + "builds\\\"\nmove \"" + name + "-win32-arm64\" \"" + outputPath + "builds\\\"", function(code){
console.log("[EnderHelper-Child-Process] exit code: " + code);
if(code === 0){
console.log("[EnderHelper] MESSAGE: Done!");
if(callback == null){
startFunction();
}else{
callback(outputPath);
}
}else{
console.log("[EnderHelper] ERROR: An error has occurred!");
startFunction();
}
}, function(data){
console.log(data.toString('utf8'));
}, function(data){
console.log(data.toString('utf8'));
});
}
});
}else{
console.log("[EnderHelper] ERROR: An error has occurred!");
startFunction();
}
}, function(data){
console.log(data.toString('utf8'));
}, function(data){
console.log(data.toString('utf8'));
});
}else{
console.log("[EnderHelper] ERROR: You need to update all the outdated modules!");
startFunction();
}
}, function(data){
console.log(data.toString('utf8'));
}, function(data){
console.log(data.toString('utf8'));
});
});
});
});
};
/*
rl.question("What's the app's path? ", function(name){
console.log(`Checking ${name}...`);
execute("cd name", function(code){
if(code == 0){
rl.question("Set the app name: ", function(name_){
rl.question("Set the app description: ", function(description){
rl.question("Set the app icon: ", function(icon_){
rl.question("Set the installer icon: ", function(iIcon_){
rl.question("Set the installer's loading screen image: ", function(loading_){
rl.question("The app's author: ", function(author_){
var electronInstaller = require('electron-winstaller');
electronInstaller.createWindowsInstaller({
appDirectory: './packed-versions/win32-x64',
outputDirectory: './output',
authors: author_,
description: description,
exe: name_ + '.exe',
loadingGif: loading_,
iconUrl: icon_,
setupIcon: iIcon_,
setupExe: name_ + ' installer.exe',
noMsi: true
}).then(() => {
console.log("The installers of your application were succesfully created!");
}, (e) => {
console.log(`An error has occurred: ${e.message}`)
});
});
});
});
});
});
});
}else{
console.log(`%cAn error has occured while tring to access this dircectory\nERROR_CODE: ${code}`, 'color: red');
}
});
});
rl.on("close", function(){
console.log("\nClosing EnderBuilder");
process.exit(0);
});
/*
var electronInstaller = require('electron-winstaller');
electronInstaller.createWindowsInstaller({
appDirectory: './packed-versions/win32-x64',
outputDirectory: './Installers',
authors: 'EnderAdel Inc.',
description: 'A framework for running EnderApps',
exe: 'EnderServices.exe',
//loadingGif: 'C:\\Users\\win10\\Desktop\\EnderServices\\EnderBuild\\resources\\install-spinner.gif',
loadingGif: 'https://static.dribbble.com/users/1186261/screenshots/3718681/_______.gif',
iconUrl: 'C:\\Users\\win10\\Desktop\\EnderServices\\EnderBuilder\\resources\\resources\\icon.ico',
setupIcon: 'C:\\Users\\win10\\Desktop\\EnderServices\\EnderBuilder\\resources\\sIcon.ico',
setupExe: 'EnderFramework installer.exe',
noMsi: true
}).then(() => {
console.log("The installers of your application were succesfully created !");
}, (e) => {
console.log(`Well, sometimes you are not so lucky: ${e.message}`)
});
*\/*/