mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-05-12 04:31:04 +00:00
Update main.js
This commit is contained in:
parent
cef8421c7c
commit
62626df60e
6
app.hta
6
app.hta
|
@ -26,7 +26,7 @@
|
|||
-->
|
||||
<hta:application
|
||||
ID="WELSONJS_WINDOW"
|
||||
Version="0.1.2"
|
||||
Version="0.1.5"
|
||||
ApplicationName="WelsonJS"
|
||||
Border="None"
|
||||
BorderStyle="Static"
|
||||
|
@ -51,7 +51,7 @@
|
|||
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
|
||||
<meta name="description" content="Welsonjs - Build a Windows desktop apps with JavaScript, HTML, and CSS based on WSH/HTA" />
|
||||
<meta name="keywords" content="webapp" />
|
||||
<meta name="author" content="gnh1201" />
|
||||
<meta name="author" content="gnh1201/welsonjs" />
|
||||
<meta name="generator" content="welsonjs" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link type="image/x-icon" rel="icon" href="app/favicon.ico" />
|
||||
|
@ -63,7 +63,7 @@
|
|||
<div id="app"></div>
|
||||
<script src="app.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script type="text/javascript">//<!--<![CDATA[
|
||||
init_window("webloader", [WELSONJS_WINDOW.commandLine], 800, 600);
|
||||
initializeWindow("webloader", [WELSONJS_WINDOW.commandLine], 800, 600);
|
||||
//]]>--></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
144
app.js
144
app.js
|
@ -124,7 +124,7 @@ var console = {
|
|||
|
||||
if (typeof(CreateObject) !== "function") {
|
||||
var CreateObject = function(progId, serverName, callback) {
|
||||
var progIds = [];
|
||||
var progIds = (progId instanceof Array ? progId : [progId]);
|
||||
var _CreateObject = function(p, s) {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
return WScript.CreateObject(p, s);
|
||||
|
@ -133,12 +133,6 @@ if (typeof(CreateObject) !== "function") {
|
|||
}
|
||||
};
|
||||
|
||||
if (typeof(progId) == "object") {
|
||||
progIds = progId;
|
||||
} else {
|
||||
progIds.push(progId);
|
||||
}
|
||||
|
||||
for (var i = 0; i < progIds.length; i++) {
|
||||
try {
|
||||
var obj = _CreateObject(progIds[i], serverName);
|
||||
|
@ -156,82 +150,91 @@ if (typeof(CreateObject) !== "function") {
|
|||
/**
|
||||
* @FN {string} The name of the file.
|
||||
*/
|
||||
function require(FN, flag) {
|
||||
var cache = require.__cache = require.__cache || {};
|
||||
var flag = (typeof(flag) !== "number" ? 0 : flag);
|
||||
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 directory name
|
||||
var getDirName = function(path) {
|
||||
var delimiter = "\\";
|
||||
var pos = path.lastIndexOf(delimiter);
|
||||
return (pos > -1 ? path.substring(0, pos) : "");
|
||||
};
|
||||
|
||||
// get current script directory
|
||||
var getCurrentScriptDirectory = function() {
|
||||
if (typeof(WScript) !== "undefined") {
|
||||
return getDirName(WScript.ScriptFullName);
|
||||
} else if (typeof(document) !== "undefined") {
|
||||
return getDirName(document.location.pathname);
|
||||
} else {
|
||||
return ".";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// get file and directory name
|
||||
var __filename = getCurrentScriptDirectory() + "\\" + FN;
|
||||
var __dirname = getDirName(__filename);
|
||||
|
||||
// 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;
|
||||
}
|
||||
var __filename__ = require.__getCurrentScriptDirectory__() + "\\" + FN;
|
||||
var __dirname__ = require.__getDirName__(__filename__);
|
||||
var T = require.__load__(FN);
|
||||
|
||||
// make function
|
||||
T = "(function(global){var module=new ModuleObject();return(function(exports,require,module,__filename,__dirname){"
|
||||
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;
|
||||
+ "\n\nreturn module.exports})(module.exports,global.require,module,__filename__,__dirname__)})(require.__global__);\n\n////@ sourceURL="
|
||||
+ FN
|
||||
;
|
||||
|
||||
// execute function
|
||||
try {
|
||||
if (flag < 1) {
|
||||
cache[FN] = eval(T);
|
||||
} else {
|
||||
eval(T);
|
||||
}
|
||||
cache[FN] = eval(T);
|
||||
} catch (e) {
|
||||
console.error("PARSE ERROR! ", e.number, ", ", e.description, ", FN=", FN);
|
||||
console.error("PARSE ERROR!", e.number, ",", e.description, ", FN=", FN);
|
||||
}
|
||||
|
||||
// check type of callback return
|
||||
// check is it exists VERSIONINFO
|
||||
if (typeof(cache[FN]) === "object") {
|
||||
if ("VERSIONINFO" in cache[FN]) console.log(cache[FN].VERSIONINFO);
|
||||
}
|
||||
|
||||
return cache[FN];
|
||||
}
|
||||
require.__global = this;
|
||||
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 init_console() {
|
||||
function initializeConsole() {
|
||||
if (typeof(WScript) === "undefined") {
|
||||
console.error("Error, WScript is not defined");
|
||||
exit(1);
|
||||
|
@ -252,15 +255,15 @@ function init_console() {
|
|||
exit(exitstatus);
|
||||
}
|
||||
} else {
|
||||
console.error("Error, missing main entry point in ", name, ".js");
|
||||
console.error("Error, missing main entry point in", name + ".js");
|
||||
}
|
||||
} else {
|
||||
console.error("Error, cannot find ", name, ".js");
|
||||
console.error("Error, cannot find", name + ".js");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init_window(name, args, w, h) {
|
||||
function initializeWindow(name, args, w, h) {
|
||||
if (typeof(window) === "undefined") {
|
||||
console.error("Error, window is not defined");
|
||||
exit(1);
|
||||
|
@ -290,13 +293,8 @@ function init_window(name, args, w, h) {
|
|||
}
|
||||
}
|
||||
|
||||
// define module object
|
||||
var ModuleObject = function() {
|
||||
this.exports = {};
|
||||
};
|
||||
|
||||
// JSON 2
|
||||
require("app/assets/js/json2", 1);
|
||||
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");
|
||||
|
@ -309,19 +307,15 @@ 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.edited");
|
||||
|
||||
// (Optional) ECMAScript 6 compatibility shims for legacy JS engines
|
||||
//require("app/assets/js/es6-shim-0.35.6.ljharb-62dbad5.edited");
|
||||
//require("app/assets/js/es6-sham.0.35.6.ljharb-62dbad5");
|
||||
var squel = require("app/assets/js/squel-basic-5.13.0.hiddentao-afa1cb5.wsh");
|
||||
|
||||
// Dive into entrypoint
|
||||
function main() {
|
||||
function __main__() {
|
||||
if (typeof(window) === "undefined") {
|
||||
init_console();
|
||||
initializeConsole();
|
||||
} else {
|
||||
console.log("welcome");
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
__main__();
|
||||
|
|
Loading…
Reference in New Issue
Block a user