-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (50 loc) · 1.64 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
#!/usr/bin/env node
const { Object, Script } = require("./src/Types");
const { parse_file, write_file } = require("./src/File");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const argv = yargs(hideBin(process.argv)).argv;
let projectPath = "";
let projectName = "";
function init_project(path) {
const ind = path.lastIndexOf("/");
projectPath = path.slice(0, ind);
projectName = path.slice(ind+1);
projectName = projectName.slice(0, projectName.lastIndexOf("."));
}
function main() {
if (argv.yyp === undefined) {
console.error(`You must provide the yyp path.`);
return;
}
const yypPath = argv.yyp.replace(/\\/g, "/");
init_project(yypPath);
const yyp = parse_file(yypPath, "utf8");
if (yyp === null) return;
const getObjects = (argv.obj === true);
const getScripts = (argv.scr === true);
let objects = [];
let scripts = [];
yyp.resources.forEach((res) => {
let yyPath = `${projectPath}/${res.id.path}`;
let yyDir = yyPath.slice(0, yyPath.lastIndexOf("/"));
let yy = parse_file(yyPath, "utf8");
if (getObjects && Object.is(yy)) {
objects.push(new Object(yy.name, yyDir));
}
if (getScripts && Script.is(yy)) {
scripts.push(new Script(yy.name, yyDir));
}
});
let output = "";
if (getObjects) {
objects.sort((a, b) => { return a.name.localeCompare(b.name); });
objects.forEach((res) => { output += res.to_text(); });
}
if (getScripts) {
scripts.sort((a, b) => { return a.name.localeCompare(b.name); });
scripts.forEach((res) => { output += res.to_text(); });
}
write_file(`./out/${projectName}.txt`, output);
}
main();