mirror of
https://github.com/esiur/esiur-js.git
synced 2025-05-06 04:22:58 +00:00
global
This commit is contained in:
parent
eb0f3382dd
commit
c46dfaf58b
@ -12,6 +12,8 @@ if (process.argv.length == 2) {
|
|||||||
console.log("\t-u, --username\tAuthentication username.");
|
console.log("\t-u, --username\tAuthentication username.");
|
||||||
console.log("\t-p, --password\tAuthentication password.");
|
console.log("\t-p, --password\tAuthentication password.");
|
||||||
console.log("\t-d, --dir\tName of the directory to generate model inside.");
|
console.log("\t-d, --dir\tName of the directory to generate model inside.");
|
||||||
|
console.log("\t-g, --global\tDeclare a global variable for the module with the specified name.");
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +40,8 @@ else if (cmd == "get-template")
|
|||||||
// get username
|
// get username
|
||||||
let username = getOption(args, "--username", "-u");
|
let username = getOption(args, "--username", "-u");
|
||||||
let password = getOption(args, "--password", "-p");
|
let password = getOption(args, "--password", "-p");
|
||||||
|
let globalName = getOption(args, "--global", "-g");
|
||||||
|
|
||||||
let dir = getOption(args, "--dir", "-d");
|
let dir = getOption(args, "--dir", "-d");
|
||||||
|
|
||||||
if (args.length == 0){
|
if (args.length == 0){
|
||||||
@ -51,7 +55,7 @@ else if (cmd == "get-template")
|
|||||||
|
|
||||||
let getTemplate = async () => {
|
let getTemplate = async () => {
|
||||||
let Esiur = (await import('../src/esiur.js')).default;
|
let Esiur = (await import('../src/esiur.js')).default;
|
||||||
await Esiur.Proxy.TemplateGenerator.getTemplate(url, dir, username, password, true);
|
await Esiur.Proxy.TemplateGenerator.getTemplate(url, dir, username, password, true, globalName);
|
||||||
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
@ -10938,6 +10938,7 @@ var TemplateGenerator = /*#__PURE__*/function () {
|
|||||||
var _this3 = this;
|
var _this3 = this;
|
||||||
|
|
||||||
var asyncSetters,
|
var asyncSetters,
|
||||||
|
globalName,
|
||||||
fs,
|
fs,
|
||||||
_urlRegex,
|
_urlRegex,
|
||||||
path,
|
path,
|
||||||
@ -10954,47 +10955,48 @@ var TemplateGenerator = /*#__PURE__*/function () {
|
|||||||
switch (_context2.prev = _context2.next) {
|
switch (_context2.prev = _context2.next) {
|
||||||
case 0:
|
case 0:
|
||||||
asyncSetters = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : true;
|
asyncSetters = _args2.length > 4 && _args2[4] !== undefined ? _args2[4] : true;
|
||||||
_context2.next = 3;
|
globalName = _args2.length > 5 && _args2[5] !== undefined ? _args2[5] : null;
|
||||||
|
_context2.next = 4;
|
||||||
return Promise.resolve().then(function () {
|
return Promise.resolve().then(function () {
|
||||||
return _interopRequireWildcard(require("fs"));
|
return _interopRequireWildcard(require("fs"));
|
||||||
});
|
});
|
||||||
|
|
||||||
case 3:
|
case 4:
|
||||||
fs = _context2.sent;
|
fs = _context2.sent;
|
||||||
// var fs = require('fs');
|
// var fs = require('fs');
|
||||||
_urlRegex = /^(?:([^\s|:]*):\/\/([^/]*)\/?(.*))/; // /^(?:([^\s|:]*):\/\/([^/]*)\/?)/;
|
_urlRegex = /^(?:([^\s|:]*):\/\/([^/]*)\/?(.*))/; // /^(?:([^\s|:]*):\/\/([^/]*)\/?)/;
|
||||||
|
|
||||||
if (_urlRegex.test(url)) {
|
if (_urlRegex.test(url)) {
|
||||||
_context2.next = 7;
|
_context2.next = 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Error("Invalid IIP URL '".concat(url, "'"));
|
throw Error("Invalid IIP URL '".concat(url, "'"));
|
||||||
|
|
||||||
case 7:
|
case 8:
|
||||||
path = url.split(_urlRegex);
|
path = url.split(_urlRegex);
|
||||||
_context2.next = 10;
|
_context2.next = 11;
|
||||||
return _Warehouse["default"].get(path[1] + "://" + path[2], username != null ? {
|
return _Warehouse["default"].get(path[1] + "://" + path[2], username != null ? {
|
||||||
"username": username,
|
"username": username,
|
||||||
"password": password !== null && password !== void 0 ? password : ""
|
"password": password !== null && password !== void 0 ? password : ""
|
||||||
} : null);
|
} : null);
|
||||||
|
|
||||||
case 10:
|
case 11:
|
||||||
con = _context2.sent;
|
con = _context2.sent;
|
||||||
|
|
||||||
if (!(con == null)) {
|
if (!(con == null)) {
|
||||||
_context2.next = 13;
|
_context2.next = 14;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw Error("Can't connect to server");
|
throw Error("Can't connect to server");
|
||||||
|
|
||||||
case 13:
|
case 14:
|
||||||
if (dir == null || dir == "") dir = path[2].replaceAll(":", "_");
|
if (dir == null || dir == "") dir = path[2].replaceAll(":", "_");
|
||||||
_context2.next = 16;
|
_context2.next = 17;
|
||||||
return con.getLinkTemplates(path[3]);
|
return con.getLinkTemplates(path[3]);
|
||||||
|
|
||||||
case 16:
|
case 17:
|
||||||
templates = _context2.sent;
|
templates = _context2.sent;
|
||||||
|
|
||||||
// no longer needed
|
// no longer needed
|
||||||
@ -11063,11 +11065,17 @@ var TemplateGenerator = /*#__PURE__*/function () {
|
|||||||
module += "Esiur.define(module, ".concat(typeName, ", '").concat(tmp.className, "');\r\n");
|
module += "Esiur.define(module, ".concat(typeName, ", '").concat(tmp.className, "');\r\n");
|
||||||
module += "new Esiur.Resource.Template.TypeTemplate(".concat(typeName, ", true);\r\n");
|
module += "new Esiur.Resource.Template.TypeTemplate(".concat(typeName, ", true);\r\n");
|
||||||
});
|
});
|
||||||
module += "\r\nexport default module;";
|
module += "\r\nexport default module;\r\n";
|
||||||
|
|
||||||
|
if (globalName != null) {
|
||||||
|
module += "\r\nif (typeof window !== 'undefined') window[\"".concat(globalName, "\"] = module;\r\n");
|
||||||
|
module += "\r\nelse if (typeof global !== 'undefined') global[\"".concat(globalName, "\"] = module;\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
fs.writeFileSync(modulePath, module);
|
fs.writeFileSync(modulePath, module);
|
||||||
return _context2.abrupt("return", dstDir);
|
return _context2.abrupt("return", dstDir);
|
||||||
|
|
||||||
case 28:
|
case 30:
|
||||||
case "end":
|
case "end":
|
||||||
return _context2.stop();
|
return _context2.stop();
|
||||||
}
|
}
|
||||||
|
31
package-lock.json
generated
31
package-lock.json
generated
@ -1,20 +1,19 @@
|
|||||||
{
|
{
|
||||||
"name": "esiur",
|
"name": "esiur",
|
||||||
"version": "2.1.3",
|
"version": "2.2.8",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "esiur",
|
"name": "esiur",
|
||||||
"version": "2.1.3",
|
"version": "2.2.8",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mongodb": "^3.6.9",
|
"mongodb": "^3.6.9",
|
||||||
"ws": "^7.5.0"
|
"ws": "^7.5.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"esiur": "bin/esiur.cjs",
|
"esiur": "bin/esiur.cjs"
|
||||||
"esiur2": "node -i -e \"import('./src/esiur.js');\""
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.14.6",
|
"@babel/core": "^7.14.6",
|
||||||
@ -2206,14 +2205,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001315",
|
"version": "1.0.30001504",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001315.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001504.tgz",
|
||||||
"integrity": "sha512-5v7LFQU4Sb/qvkz7JcZkvtSH1Ko+1x2kgo3ocdBeMGZSOFpuE1kkm0kpTwLtWeFrw5qw08ulLxJjVIXIS8MkiQ==",
|
"integrity": "sha512-5uo7eoOp2mKbWyfMXnGO9rJWOGU8duvzEiYITW+wivukL7yHH4gX9yuRaobu6El4jPxo6jKZfG+N6fB621GD/Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": {
|
"funding": [
|
||||||
|
{
|
||||||
"type": "opencollective",
|
"type": "opencollective",
|
||||||
"url": "https://opencollective.com/browserslist"
|
"url": "https://opencollective.com/browserslist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tidelift",
|
||||||
|
"url": "https://tidelift.com/funding/github/npm/caniuse-lite"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/ai"
|
||||||
}
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"node_modules/chalk": {
|
"node_modules/chalk": {
|
||||||
"version": "2.4.2",
|
"version": "2.4.2",
|
||||||
@ -6696,9 +6705,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"caniuse-lite": {
|
"caniuse-lite": {
|
||||||
"version": "1.0.30001315",
|
"version": "1.0.30001504",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001315.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001504.tgz",
|
||||||
"integrity": "sha512-5v7LFQU4Sb/qvkz7JcZkvtSH1Ko+1x2kgo3ocdBeMGZSOFpuE1kkm0kpTwLtWeFrw5qw08ulLxJjVIXIS8MkiQ==",
|
"integrity": "sha512-5uo7eoOp2mKbWyfMXnGO9rJWOGU8duvzEiYITW+wivukL7yHH4gX9yuRaobu6El4jPxo6jKZfG+N6fB621GD/Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"chalk": {
|
"chalk": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "esiur",
|
"name": "esiur",
|
||||||
"version": "2.2.7",
|
"version": "2.2.8",
|
||||||
"description": "Distributed Object Framework",
|
"description": "Distributed Object Framework",
|
||||||
"main": "esiur.js",
|
"main": "esiur.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
@ -238,7 +238,7 @@ export default class TemplateGenerator {
|
|||||||
return v == null || v == "";
|
return v == null || v == "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static async getTemplate(url, dir, username, password, asyncSetters = true) {
|
static async getTemplate(url, dir, username, password, asyncSetters = true, globalName = null) {
|
||||||
|
|
||||||
|
|
||||||
const fs = await import("fs");
|
const fs = await import("fs");
|
||||||
@ -318,7 +318,13 @@ export default class TemplateGenerator {
|
|||||||
module += `new Esiur.Resource.Template.TypeTemplate(${typeName}, true);\r\n`
|
module += `new Esiur.Resource.Template.TypeTemplate(${typeName}, true);\r\n`
|
||||||
});
|
});
|
||||||
|
|
||||||
module += "\r\nexport default module;";
|
module += "\r\nexport default module;\r\n";
|
||||||
|
|
||||||
|
if (globalName != null) {
|
||||||
|
module += `\r\nif (typeof window !== 'undefined') window["${globalName}"] = module;\r\n`;
|
||||||
|
module += `\r\nelse if (typeof global !== 'undefined') global["${globalName}"] = module;\r\n`;
|
||||||
|
}
|
||||||
|
|
||||||
fs.writeFileSync(modulePath, module);
|
fs.writeFileSync(modulePath, module);
|
||||||
|
|
||||||
return dstDir;
|
return dstDir;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user