-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathtool.js
116 lines (109 loc) · 4.7 KB
/
tool.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
/*
* Copyright (c) 2016-2023 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Tools.
*
* The Moddable SDK Tools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Moddable SDK Tools is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the Moddable SDK Tools. If not, see <http://www.gnu.org/licenses/>.
*
*/
const inline = "args.txt";
export class FILE @ "FILE_prototype_destructor" {
constructor(path, flags) @ "FILE_prototype_constructor";
close() @ "FILE_prototype_close";
dump(path) @ "FILE_prototype_dump";
line(...strings) {
let c = arguments.length;
for (let i = 0; i < c; i++)
this.writeString(arguments[i]);
this.writeString("\n");
}
write() @ "FILE_prototype_write";
writeBuffer(buffer) @ "FILE_prototype_writeBuffer";
writeByte(byte) @ "FILE_prototype_writeByte";
writeString(string) @ "FILE_prototype_writeString";
}
export class TOOL {
constructor(argv) {
let command = argv.slice();
this.errorCount = 0;
this.warningCount = 0;
if ((argv.length == 2) && (argv[1] == inline)) {
let path = this.resolveFilePath(inline);
let args = this.readFileString(path);
args = args.trim().split(/\s+/);
argv.length = 1;
args.forEach(arg => argv.push(arg));
}
let path = this.getenv("MODDABLE");
if (!path)
throw new Error("missing MODDABLE environment variable")
path = this.resolveDirectoryPath(path);
if (!path)
throw new Error("invalid MODDABLE environment variable")
path += "/tools/VERSION";
if ("win" === this.currentPlatform)
path = path.replaceAll("/", "\\");
const fileVersion = (this.isDirectoryOrFile(path) == 1) ? this.readFileString(path) : undefined;
const toolsVersion = this.getToolsVersion();
if (fileVersion.trim() === toolsVersion)
return;
trace(`Moddable SDK tools mismatch between binary (${toolsVersion}) and source (${fileVersion})! Rebuilding tools.\n`);
command = command.map(item => {
item = item.replaceAll('"', '\\"');
item = (item.indexOf(" ") < 0) ? item : `"${item}"`;
return item;
});
command = command.join(" ");
if ("win" === this.currentPlatform) {
command = `wmic process where "name='tools.exe'" delete >nul 2>&1 & pushd %MODDABLE%\\build\\makefiles\\win && build clean && build && popd && ${command}`;
this.then("cmd", "/C", command);
}
else {
command = `pushd $MODDABLE/build/makefiles/${this.currentPlatform} && make clean && make && popd && ${command}`;
this.then("bash", "-c", command);
}
this.run = function() {};
}
get build() @ "Tool_prototype_get_build";
get ipAddress() @ "Tool_prototype_get_ipAddress";
get currentDirectory() @ "Tool_prototype_get_currentDirectory";
set currentDirectory(it) @ "Tool_prototype_set_currentDirectory";
get currentPlatform() @ "Tool_prototype_get_currentPlatform";
deleteDirectory(path) @ "Tool_prototype_deleteDirectory";
deleteFile(path) @ "Tool_prototype_deleteFile";
createDirectory(path) @ "Tool_prototype_createDirectory";
enumerateDirectory(path) @ "Tool_prototype_enumerateDirectory";
execute(command) @ "Tool_prototype_execute";
getenv(name) @ "Tool_prototype_getenv";
getFileSize(path) @ "Tool_prototype_getFileSize";
getToolsVersion(path) @ "Tool_prototype_getToolsVersion";
hash(d, string) @ "Tool_prototype_fsvhash";
isDirectoryOrFile(path) @ "Tool_prototype_isDirectoryOrFile"; // -1: directory, 0: none, 1: file
joinPath(parts) @ "Tool_prototype_joinPath";
readFileString(path) @ "Tool_prototype_readFileString";
readFileBuffer(path) @ "Tool_prototype_readFileBuffer";
report(message) @ "Tool_prototype_report";
reportError(message) @ "Tool_prototype_reportError";
reportWarning(message) @ "Tool_prototype_reportWarning";
resolveDirectoryPath(message) @ "Tool_prototype_resolveDirectoryPath";
resolveFilePath(message) @ "Tool_prototype_resolveFilePath";
resolvePath(message) @ "Tool_prototype_resolvePath";
setenv(name, value) @ "Tool_prototype_setenv";
spawn(path) @ "Tool_prototype_spawn";
splitPath(path) @ "Tool_prototype_splitPath";
strlen(string) @ "Tool_prototype_strlen";
then() @ "Tool_prototype_then";
writeFileString(path, string) @ "Tool_prototype_writeFileString";
writeFileBuffer(path, buffer) @ "Tool_prototype_writeFileBuffer";
}