-
Notifications
You must be signed in to change notification settings - Fork 529
/
scripts-utils.js
73 lines (63 loc) · 2.56 KB
/
scripts-utils.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
import fs from 'node:fs';
import path from 'node:path';
/**
* txAdmin in ASCII
* @returns {String}
*/
export const txAdminASCII = () => {
//NOTE: precalculating the ascii art for efficiency
// const figlet = require('figlet');
// let ascii = figlet.textSync('txAdmin');
// let b64 = Buffer.from(ascii).toString('base64');
// console.log(b64);
const preCalculated = `ICBfICAgICAgICAgICAgXyAgICAgICBfICAgICAgICAgICBfICAgICAgIAogfCB8X19fICBfX
yAgIC8gXCAgIF9ffCB8XyBfXyBfX18gKF8pXyBfXyAgCiB8IF9fXCBcLyAvICAvIF8gXCAvIF9gIHwgJ18gYCBfIFx8IHwg
J18gXCAKIHwgfF8gPiAgPCAgLyBfX18gXCAoX3wgfCB8IHwgfCB8IHwgfCB8IHwgfAogIFxfXy9fL1xfXC9fLyAgIFxfXF9
fLF98X3wgfF98IHxffF98X3wgfF98CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA=`;
return Buffer.from(preCalculated, 'base64').toString('ascii');
};
/**
* txAdmin + license banner for bundled files
* @returns {String}
*/
export const licenseBanner = (baseDir = '.') => {
const licensePath = path.join(baseDir, 'LICENSE');
const lineSep = '%'.repeat(80);
const logoPad = ' '.repeat(18);
const contentLines = [
'',
lineSep,
...txAdminASCII().split('\n').map((x) => logoPad + x),
lineSep,
'Author: André Tabarra (https://github.com/tabarra)',
'Repository: https://github.com/tabarra/txAdmin',
'This bundled file includes third party libraries under their respective licenses.',
'txAdmin is a free open source software provided under the license below.',
lineSep,
...fs.readFileSync(licensePath, 'utf8').trim().split('\n'),
lineSep,
].join('\n * ');
return `/*!${contentLines}\n */`;
};
/**
* Processes a fxserver path to validate it as well as the monitor folder.
* NOTE: this function is windows only, but could be easily adapted.
* @param {String} fxserverPath
* @returns fxServerRootPath, fxsBinPath, monitorPath
*/
export const getFxsPaths = (fxserverPath) => {
const fxServerRootPath = path.normalize(fxserverPath);
//Process fxserver path
const fxsBinPath = path.join(fxServerRootPath, 'FXServer.exe');
const fxsBinPathStat = fs.statSync(fxsBinPath);
if (!fxsBinPathStat.isFile()) {
throw new Error(`${fxsBinPath} is not a file.`);
}
//Process monitor path
const monitorPath = path.join(fxServerRootPath, 'citizen', 'system_resources', 'monitor');
const monitorPathStat = fs.statSync(monitorPath);
if (!monitorPathStat.isDirectory()) {
throw new Error(`${monitorPath} is not a directory.`);
}
return { fxServerRootPath, fxsBinPath, monitorPath };
};