forked from TasoOneAsia/JetbrainIDE-CFX.RE
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.ts
More file actions
134 lines (117 loc) · 3.38 KB
/
main.ts
File metadata and controls
134 lines (117 loc) · 3.38 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
import * as request from "request";
import { FilesBuilder } from "./src/files-builder";
import { ContentGenerate } from "./src/content-generate";
import * as figlet from "figlet";
import { GamesType } from "./src/enum/GamesType";
import { terminal as term } from "terminal-kit";
/**
* The [[Main]] class that groups together all the logical execution processes of the system.
*/
export class Main {
/**
* @param gametype
*/
private static getNativeLink = (gametype: GamesType): string => {
switch (gametype) {
default:
case GamesType.GTA:
return "https://static.cfx.re/natives/natives.json";
case GamesType.RDR3:
return "https://raw.githubusercontent.com/VORPCORE/RDR3natives/main/rdr3natives.json";
case GamesType.Cfx:
return "https://static.cfx.re/natives/natives_cfx.json";
}
};
/**
* @param gametype
*/
private static getNativeDocsUrl = (gametype: GamesType): string => {
switch (gametype) {
case GamesType.RDR3:
return "https://rdr3natives.com/?_";
default:
return "https://docs.fivem.net/natives/?_";
}
};
/**
* Startup logicNom de la native fivem
*
* @param dir Location of the file where the project will be built
*
* @param gametype
* @return void
*/
public static onEnable = (
dir: string,
gametype: GamesType
): Promise<void> => {
let json = Main.getNativeLink(gametype);
if (!json) return;
return new Promise((resolve) => {
request.get(json, async (error, response, content) => {
const files = new FilesBuilder(dir);
const json = JSON.parse(content);
await files.init();
files.category(json);
await new Promise((resolve) => setTimeout(resolve, 1000));
const builder = new ContentGenerate(files).setDocumentationUrl(
Main.getNativeDocsUrl(gametype)
);
try {
await builder.generateTemplate(json);
} catch (err) {
term.red(err);
} finally {
resolve();
}
});
});
};
/**
* Folder generate logic
*
* @param response
*
* @return void
*/
public static onFolderGenerate = (response: void) => {
term.cyan("Create build directory successfully : " + response);
};
/**
* File update logic
*
* @param stats
* @param filename Name of the updated file
* @param nativename Name of the native fivem
*
* @return void
*/
public static onFileUpdate = (
stats: { native: { total: number; current: number } },
filename: String,
nativename: String
): void => {
stats.native.current++;
term.green("[File : " + filename + " ] [Native : " + nativename + " ]\n");
if (stats.native.current == stats.native.total) process.exit();
};
}
figlet("JetBrainIDE-CitizenFX", (err, data) => {
term.blue(data);
term.red("\n Dylan Malandain - @iTexZoz \n");
});
term.cyan(
"Welcome to the native completion generator tool for Jetbrain IDEs for cfx.re projects.\n"
);
// term.cyan("Please select the game concerned.\n");
// let items = [
// "1. (FiveM) GTA V",
// "2. (RedM) Red Dead Redemption 2",
// "3. CFX (Is Available for RedM && FiveM)",
// ];
(async () => {
await Main.onEnable("build/cfx/GTAV", GamesType.GTA);
await Main.onEnable("build/cfx/RDR3", GamesType.RDR3);
await Main.onEnable("build/cfx/CFX-NATIVE", GamesType.Cfx);
process.exit();
})();