2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 04:22:58 +00:00
This commit is contained in:
Esiur Project 2023-06-19 22:30:44 +03:00
parent eb0f3382dd
commit c46dfaf58b
5 changed files with 57 additions and 30 deletions

View File

@ -12,6 +12,8 @@ if (process.argv.length == 2) {
console.log("\t-u, --username\tAuthentication username.");
console.log("\t-p, --password\tAuthentication password.");
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();
}
@ -38,6 +40,8 @@ else if (cmd == "get-template")
// get username
let username = getOption(args, "--username", "-u");
let password = getOption(args, "--password", "-p");
let globalName = getOption(args, "--global", "-g");
let dir = getOption(args, "--dir", "-d");
if (args.length == 0){
@ -51,7 +55,7 @@ else if (cmd == "get-template")
let getTemplate = async () => {
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();
}

View File

@ -10938,6 +10938,7 @@ var TemplateGenerator = /*#__PURE__*/function () {
var _this3 = this;
var asyncSetters,
globalName,
fs,
_urlRegex,
path,
@ -10954,47 +10955,48 @@ var TemplateGenerator = /*#__PURE__*/function () {
switch (_context2.prev = _context2.next) {
case 0:
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 _interopRequireWildcard(require("fs"));
});
case 3:
case 4:
fs = _context2.sent;
// var fs = require('fs');
_urlRegex = /^(?:([^\s|:]*):\/\/([^/]*)\/?(.*))/; // /^(?:([^\s|:]*):\/\/([^/]*)\/?)/;
if (_urlRegex.test(url)) {
_context2.next = 7;
_context2.next = 8;
break;
}
throw Error("Invalid IIP URL '".concat(url, "'"));
case 7:
case 8:
path = url.split(_urlRegex);
_context2.next = 10;
_context2.next = 11;
return _Warehouse["default"].get(path[1] + "://" + path[2], username != null ? {
"username": username,
"password": password !== null && password !== void 0 ? password : ""
} : null);
case 10:
case 11:
con = _context2.sent;
if (!(con == null)) {
_context2.next = 13;
_context2.next = 14;
break;
}
throw Error("Can't connect to server");
case 13:
case 14:
if (dir == null || dir == "") dir = path[2].replaceAll(":", "_");
_context2.next = 16;
_context2.next = 17;
return con.getLinkTemplates(path[3]);
case 16:
case 17:
templates = _context2.sent;
// no longer needed
@ -11063,11 +11065,17 @@ var TemplateGenerator = /*#__PURE__*/function () {
module += "Esiur.define(module, ".concat(typeName, ", '").concat(tmp.className, "');\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);
return _context2.abrupt("return", dstDir);
case 28:
case 30:
case "end":
return _context2.stop();
}

31
package-lock.json generated
View File

@ -1,20 +1,19 @@
{
"name": "esiur",
"version": "2.1.3",
"version": "2.2.8",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "esiur",
"version": "2.1.3",
"version": "2.2.8",
"license": "MIT",
"dependencies": {
"mongodb": "^3.6.9",
"ws": "^7.5.0"
},
"bin": {
"esiur": "bin/esiur.cjs",
"esiur2": "node -i -e \"import('./src/esiur.js');\""
"esiur": "bin/esiur.cjs"
},
"devDependencies": {
"@babel/core": "^7.14.6",
@ -2206,14 +2205,24 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001315",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001315.tgz",
"integrity": "sha512-5v7LFQU4Sb/qvkz7JcZkvtSH1Ko+1x2kgo3ocdBeMGZSOFpuE1kkm0kpTwLtWeFrw5qw08ulLxJjVIXIS8MkiQ==",
"version": "1.0.30001504",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001504.tgz",
"integrity": "sha512-5uo7eoOp2mKbWyfMXnGO9rJWOGU8duvzEiYITW+wivukL7yHH4gX9yuRaobu6El4jPxo6jKZfG+N6fB621GD/Q==",
"dev": true,
"funding": {
"funding": [
{
"type": "opencollective",
"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": {
"version": "2.4.2",
@ -6696,9 +6705,9 @@
"dev": true
},
"caniuse-lite": {
"version": "1.0.30001315",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001315.tgz",
"integrity": "sha512-5v7LFQU4Sb/qvkz7JcZkvtSH1Ko+1x2kgo3ocdBeMGZSOFpuE1kkm0kpTwLtWeFrw5qw08ulLxJjVIXIS8MkiQ==",
"version": "1.0.30001504",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001504.tgz",
"integrity": "sha512-5uo7eoOp2mKbWyfMXnGO9rJWOGU8duvzEiYITW+wivukL7yHH4gX9yuRaobu6El4jPxo6jKZfG+N6fB621GD/Q==",
"dev": true
},
"chalk": {

View File

@ -1,6 +1,6 @@
{
"name": "esiur",
"version": "2.2.7",
"version": "2.2.8",
"description": "Distributed Object Framework",
"main": "esiur.js",
"type": "module",

View File

@ -238,7 +238,7 @@ export default class TemplateGenerator {
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");
@ -318,7 +318,13 @@ export default class TemplateGenerator {
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);
return dstDir;