forked from gnh1201/welsonjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
371 lines (337 loc) · 10.9 KB
/
app.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
//////////////////////////////////////////////////////////////////////////////////
//
// app.js
//
// Bootstrap code for running a javascript app in windows. Run as:
//
// cscript.js app.js <appname> <app arguments> ...
//
/////////////////////////////////////////////////////////////////////////////////
//"use strict";
/////////////////////////////////////////////////////////////////////////////////
// Bootstrap code, basic module loading functionality
/////////////////////////////////////////////////////////////////////////////////
//
// The module loaded is run inside a function, with one argument, global which
// points to the global context. So global.FN is the same as FN (as long as a
// version of FN does not exist in local scope).
//
// The module should return its interface at the end of the script. The basic
// pattern for a module is:-
//
// var module = { ... };
// return module;
//
// Or:-
//
// return function() {
// }
//
// The appname argument causes <appname>.js to be loaded. The interface returned
// must define main = function(args) {}, which is called once the module is
// loaded.
var exit = function(status) {
console.error("Exit caused by status " + status);
if (typeof(WScript) !== "undefined") {
WScript.quit(status);
} else if (typeof(window) !== "undefined") {
window.close();
}
};
var console = {
_timers: {},
_counters: {},
_messages: [],
_join: function(args, sep) {
args = args || [];
sep = sep || ' ';
var res = '';
for (var i = args.length - 1; i > -1; i--) {
res = (i ? sep : '') + args[i] + res;
}
return res;
},
_echoCallback: null,
_echo: function(args, type) {
var message = "";
var params = {
type: type,
channel: 'default',
messsage: '',
datetime: new Date().toISOString()
};
if (args.length > 0) {
if (typeof args[0] === "string") {
// if not type is "log", then "{type}: {message}"
if (typeof type !== "undefined") {
message += (type + ": " + this._join(args));
} else {
message += this._join(args);
}
if (typeof WScript !== "undefined") {
WScript.echo(" * " + message)
}
this._messages.push(message);
params.message = message;
} else if (typeof args[0] === "object") {
if ('message' in args[0]) {
if (typeof type !== "undefined") {
message += (type + ": " + args[0].message);
} else {
message += args[0].message;
}
}
if (typeof WScript !== "undefined") {
WScript.echo(" * " + message);
}
this._messages.push(args[0].message);
for (var k in args[0]) {
params[k] = args[0][k];
}
}
}
if (params.channel != "default" && this._echoCallback != null) {
try {
this._echoCallback(params, type);
} catch (e) {
if (typeof WScript !== "undefined") {
WScript.echo(" * Exception of _echoCallback:", e.message);
}
}
}
},
assert: function(assertion) {
if (arguments.length > 1 && assertion === arguments[0]) {
if(!assertion) {
this.error("Assertion failed: " + this._join(arguments.slice(1)));
}
}
},
clear: function() {
this._messages = [];
},
log: function() {
this._echo(arguments);
},
error: function() {
this._echo(arguments, "error");
},
info: function() {
this._echo(arguments, "info");
},
warn: function() {
this._echo(arguments, "warn");
},
debug: function() {
this._echo(arguments, "debug");
},
time: function(label) {
label = label || "default";
if (!(label in this._timers)) {
this._timers[label] = new Date();
}
},
timeLog: function(label, end) {
label = label || "default";
if (label in this._timers) {
console.debug(label + ":", ((new Date()).getTime() - this._timers[label].getTime()) + "ms", (end ? " - timer ended" : ""));
}
},
timeEnd: function(label) {
label = label || "default";
if (label in this._timers) {
this.timeLog();
delete this._timers[label];
}
},
count: function(label) {
label = label || "default";
if (!(label in this._counters)) {
this._counters[label] = 1;
}
},
countReset: function(label) {
label = label || "default";
if (label in this._counters) {
this.timeLog();
delete this._counters[label];
}
}
};
if (typeof(CreateObject) === "undefined") {
var CreateObject = function(progId, serverName, callback) {
var progIds = (progId instanceof Array ? progId : [progId]);
var _CreateObject = function(p, s) {
if (typeof(WScript) !== "undefined") {
return WScript.CreateObject(p, s);
} else {
return new ActiveXObject(p);
}
};
for (var i = 0; i < progIds.length; i++) {
try {
var obj = _CreateObject(progIds[i], serverName);
if (typeof(callback) === "function") {
callback(obj, progIds[i]);
}
return obj;
} catch (e) {
console.error(e.message);
};
}
};
}
/**
* @FN {string} The name of the file.
*/
function include(FN) {
if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
return eval(require.__load__(FN));
}
/**
* @FN {string} The name of the file.
*/
function require(FN) {
var cache = require.__cache__ = require.__cache__ || {};
if (FN.substr(FN.length - 3) !== '.js') FN += ".js";
if (cache[FN]) return cache[FN];
// get file and directory name
var __filename__ = require.__getCurrentScriptDirectory__() + "\\" + FN;
var __dirname__ = require.__getDirName__(__filename__);
var T = require.__load__(FN);
// build
T = "(function(global){var module=new require.__ModuleObject__();return(function(exports,require,module,__filename,__dirname){"
+ '"use strict";'
+ T
+ "\n\nreturn module.exports})(module.exports,global.require,module,__filename__,__dirname__)})(require.__global__);\n\n////@ sourceURL="
+ FN
;
// execute
try {
cache[FN] = eval(T);
} catch (e) {
console.error("PARSE ERROR!", e.number + ",", e.description + ",", "FN=" + FN);
}
// print VERSIONINFO
if (typeof(cache[FN]) === "object") {
if ("VERSIONINFO" in cache[FN]) console.log(cache[FN].VERSIONINFO);
}
return cache[FN];
}
require.__global__ = this;
require.__ModuleObject__ = function() {
this.exports = {};
};
require.__getDirName__ = function(path) {
var delimiter = "\\";
var pos = path.lastIndexOf(delimiter);
return (pos > -1 ? path.substring(0, pos) : "");
};
require.__getCurrentScriptDirectory__ = function() {
if (typeof(WScript) !== "undefined") {
return require.__getDirName__(WScript.ScriptFullName);
} else if (typeof(document) !== "undefined") {
return require.__getDirName__(document.location.pathname);
} else {
return ".";
}
};
require.__load__ = function(FN) {
// get filename
var __filename__ = require.__getCurrentScriptDirectory__() + "\\" + FN;
// load script file
// use ADODB.Stream instead of Scripting.FileSystemObject, because of UTF-8 (unicode)
var objStream = CreateObject("ADODB.Stream");
var T = null;
try {
objStream.charSet = "utf-8";
objStream.open();
objStream.loadFromFile(__filename__);
T = objStream.readText();
objStream.close();
} catch (e) {
console.error("LOAD ERROR!", e.number + ",", e.description + ",", "FN=" + FN);
return;
}
return T;
};
/////////////////////////////////////////////////////////////////////////////////
// Load script, and call app.main()
/////////////////////////////////////////////////////////////////////////////////
function initializeConsole() {
if (typeof(WScript) === "undefined") {
console.error("Error, WScript is not defined");
exit(1);
}
var argl = WScript.arguments.length;
if (argl > 0) {
var args = [];
for (var i = 0; i < argl; i++) {
args.push(WScript.arguments(i));
}
var name = args.shift();
var app = require(name);
if (app) {
if (app.main) {
var exitStatus = app.main.call(this, args);
if (typeof(exitStatus) !== "undefined") {
exit(exitStatus);
}
} else {
console.error("Error, missing main entry point in", name + ".js");
}
} else {
console.error("Error, cannot find", name + ".js");
}
}
}
function initializeWindow(name, args, w, h) {
if (typeof(window) === "undefined") {
console.error("Error, window is not defined");
exit(1);
}
var app = require(name);
// "set default size of window";
if (typeof(w) !== "undefined" && typeof(h) !== "undefined") {
window.resizeTo(w, h);
}
// "load app";
if (app) {
if (app.main) {
var exitStatus = app.main.call(app, args);
if (exitStatus > 0) {
exit(exitStatus);
}
} else {
console.error("Error, missing main entry point in", name + ".js");
exit(1);
}
} else {
console.error("Error, cannot find", name + ".js");
exit(1);
}
}
// JSON 2
include("app/assets/js/json2");
// JSON 3 was a JSON polyfill for older JavaScript platforms
//var JSON = require("app/assets/js/json3-3.3.2.min");
// core-js (formerly babel-polyfill)
require("app/assets/js/corejs-build-20210810");
// es5-shims
//require("app/assets/js/es5-shim-4.5.15.min");
//require("app/assets/js/es5-sham-4.5.15.min");
// Squel.js SQL query string builder for Javascript
var squel = require("app/assets/js/squel-basic-5.13.0.hiddentao-afa1cb5.wsh");
// JavaScript YAML parser and dumper.
var yaml = require("app/assets/js/js-yaml-4.1.0.wsh");
// is.js Micro check library
var is = require("app/assets/js/is-0.9.0.min");
// Dive into entrypoint
function __main__() {
if (typeof(window) === "undefined") {
initializeConsole();
} else {
console.log("welcome");
}
}
__main__();