qcobjects-cli 2.4.60 → 2.4.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/VERSION +1 -1
- package/package.json +1 -1
- package/src/org.quickcorp.qcobjects.defaultsettings.js +342 -322
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.4.
|
|
1
|
+
2.4.62
|
package/package.json
CHANGED
|
@@ -30,348 +30,368 @@
|
|
|
30
30
|
/*eslint no-undef: "off"*/
|
|
31
31
|
"use strict";
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
CONFIG.set("projectPath", `${process.cwd()}/`);
|
|
35
|
-
CONFIG.set("useConfigService", false); // this is only true useful for client web side
|
|
36
|
-
CONFIG.set("documentRoot", "./");
|
|
37
|
-
CONFIG.set("serverPortHTTP", 80);
|
|
38
|
-
CONFIG.set("serverPortHTTPS", 443);
|
|
39
|
-
CONFIG.set("private-key-pem", "localhost-privkey.pem");
|
|
40
|
-
CONFIG.set("private-cert-pem", "localhost-cert.pem");
|
|
41
|
-
CONFIG.set("allowHTTP1", true);
|
|
42
|
-
CONFIG.set("useTemplate", false);
|
|
43
|
-
CONFIG.set("domain", "localhost");
|
|
33
|
+
(function (){
|
|
44
34
|
|
|
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
|
-
|
|
35
|
+
const __load_default_settings__ = () => {
|
|
36
|
+
CONFIG.set("documentRootFileIndex", "index.html");
|
|
37
|
+
CONFIG.set("projectPath", `${process.cwd()}/`);
|
|
38
|
+
CONFIG.set("useConfigService", false); // this is only true useful for client web side
|
|
39
|
+
CONFIG.set("documentRoot", "./");
|
|
40
|
+
CONFIG.set("serverPortHTTP", 80);
|
|
41
|
+
CONFIG.set("serverPortHTTPS", 443);
|
|
42
|
+
CONFIG.set("private-key-pem", "localhost-privkey.pem");
|
|
43
|
+
CONFIG.set("private-cert-pem", "localhost-cert.pem");
|
|
44
|
+
CONFIG.set("allowHTTP1", true);
|
|
45
|
+
CONFIG.set("useTemplate", false);
|
|
46
|
+
CONFIG.set("domain", "localhost");
|
|
47
|
+
|
|
48
|
+
global.__get_version__ = function () {
|
|
49
|
+
const path = require("path");
|
|
50
|
+
|
|
51
|
+
const absolutePath = path.resolve(__dirname, "./");
|
|
52
|
+
const package_config = require(absolutePath + "/../package.json");
|
|
53
|
+
const qcobjects_pkg_config = require("qcobjects/package.json");
|
|
54
|
+
const qcobjects_sdk_pkg_config = require("qcobjects-sdk/package.json");
|
|
55
|
+
return {
|
|
56
|
+
"qcobjects": qcobjects_pkg_config.version,
|
|
57
|
+
"sdk": qcobjects_sdk_pkg_config.version,
|
|
58
|
+
"cli": package_config.version
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
global.__get_version_string__ = function () {
|
|
63
|
+
const version = global.__get_version__();
|
|
64
|
+
return "QCObjects: v" + version.qcobjects + ", SDK: v" + version.sdk + ", CLI: v" + version.cli;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
let setDevMode = function (devmode) {
|
|
69
|
+
if (typeof devmode !== "undefined") {
|
|
70
|
+
switch (true) {
|
|
71
|
+
case devmode == "debug":
|
|
72
|
+
logger.debugEnabled = true;
|
|
73
|
+
logger.warnEnabled = true;
|
|
74
|
+
logger.infoEnabled = true;
|
|
75
|
+
break;
|
|
76
|
+
case devmode == "warn":
|
|
77
|
+
logger.debugEnabled = false;
|
|
78
|
+
logger.warnEnabled = true;
|
|
79
|
+
logger.infoEnabled = true;
|
|
80
|
+
break;
|
|
81
|
+
case devmode == "info":
|
|
82
|
+
logger.debugEnabled = false;
|
|
83
|
+
logger.warnEnabled = false;
|
|
84
|
+
logger.infoEnabled = true;
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
default:
|
|
88
|
+
logger.debugEnabled = false;
|
|
89
|
+
logger.warnEnabled = false;
|
|
90
|
+
logger.infoEnabled = false;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
85
94
|
logger.debugEnabled = false;
|
|
86
95
|
logger.warnEnabled = false;
|
|
87
96
|
logger.infoEnabled = false;
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
logger.debugEnabled = false;
|
|
92
|
-
logger.warnEnabled = false;
|
|
93
|
-
logger.infoEnabled = false;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
var _config = require(CONFIG.get("projectPath") + "config.json");
|
|
100
|
-
logger.debug("Loading settings from your config.json");
|
|
101
|
-
|
|
102
|
-
let _secretKey = (_config.hasOwnProperty.call(_config, "domain")) ? (_config["domain"]) : ("_secret_");
|
|
103
|
-
|
|
104
|
-
if (_config.hasOwnProperty.call(_config, "__encoded__")) {
|
|
105
|
-
_config = JSON.parse(_Crypt.decrypt(_config.__encoded__, _secretKey));
|
|
106
|
-
}
|
|
107
|
-
for (var k in _config) {
|
|
108
|
-
CONFIG.set(k, _config[k]);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
setDevMode(CONFIG.get("devmode", ""));
|
|
112
|
-
|
|
113
|
-
if (typeof CONFIG.get("backend") !== "undefined") {
|
|
114
|
-
global.set("backendAvailable", true);
|
|
115
|
-
|
|
116
|
-
if (typeof CONFIG.get("basePath") !== "undefined") {
|
|
117
|
-
logger.debug(`Changing the current directory: ${process.cwd()}`);
|
|
118
|
-
try {
|
|
119
|
-
process.chdir(CONFIG.get("basePath"));
|
|
120
|
-
logger.debug(`New directory: ${process.cwd()}`);
|
|
121
|
-
} catch (err) {
|
|
122
|
-
logger.warn(`It was impossible to change the current chdir: ${err}`);
|
|
123
97
|
}
|
|
98
|
+
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
var _config = require(CONFIG.get("projectPath") + "config.json");
|
|
103
|
+
logger.debug("Loading settings from your config.json");
|
|
104
|
+
|
|
105
|
+
let _secretKey = (_config.hasOwnProperty.call(_config, "domain")) ? (_config["domain"]) : ("_secret_");
|
|
106
|
+
|
|
107
|
+
if (_config.hasOwnProperty.call(_config, "__encoded__")) {
|
|
108
|
+
_config = JSON.parse(_Crypt.decrypt(_config.__encoded__, _secretKey));
|
|
109
|
+
}
|
|
110
|
+
for (var k in _config) {
|
|
111
|
+
CONFIG.set(k, _config[k]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setDevMode(CONFIG.get("devmode", ""));
|
|
115
|
+
|
|
116
|
+
if (typeof CONFIG.get("backend") !== "undefined") {
|
|
117
|
+
global.set("backendAvailable", true);
|
|
118
|
+
|
|
119
|
+
if (typeof CONFIG.get("basePath") !== "undefined") {
|
|
120
|
+
logger.debug(`Changing the current directory: ${process.cwd()}`);
|
|
121
|
+
try {
|
|
122
|
+
process.chdir(CONFIG.get("basePath"));
|
|
123
|
+
logger.debug(`New directory: ${process.cwd()}`);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
logger.warn(`It was impossible to change the current chdir: ${err}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
} catch (e) {
|
|
130
|
+
logger.debug(e);
|
|
131
|
+
logger.debug("Something went wrong trying to load config.json file in your project");
|
|
124
132
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const sdkPath = path.resolve(findPackageNodePath("qcobjects-sdk"), "qcobjects-sdk");
|
|
136
|
-
const qcobjectsPath = path.resolve(findPackageNodePath("qcobjects"), "qcobjects");
|
|
137
|
-
let backend = CONFIG.get("backend");
|
|
138
|
-
if (typeof backend === "undefined") {
|
|
139
|
-
backend = {};
|
|
140
|
-
}
|
|
141
|
-
if (typeof backend.routes === "undefined") {
|
|
142
|
-
backend.routes = [];
|
|
143
|
-
}
|
|
144
|
-
backend.routes = backend.routes.concat([{
|
|
145
|
-
"name": "QCObjects.js",
|
|
146
|
-
"description": "Redirection of QCObjects.js",
|
|
147
|
-
"path": "^/QCObjects.js$",
|
|
148
|
-
"microservice": "com.qcobjects.backend.microservice.static",
|
|
149
|
-
"redirect_to": path.resolve(qcobjectsPath,"src","QCObjects.js"),
|
|
150
|
-
"responseHeaders": {},
|
|
151
|
-
"cors": {
|
|
152
|
-
"allow_origins": "*"
|
|
133
|
+
|
|
134
|
+
(async function () {
|
|
135
|
+
const path = require("path");
|
|
136
|
+
const projectPath = CONFIG.get("projectPath", `${process.cwd()}/`);
|
|
137
|
+
const loadDefaultRoutes = async () => {
|
|
138
|
+
const sdkPath = path.resolve(findPackageNodePath("qcobjects-sdk"), "qcobjects-sdk");
|
|
139
|
+
const qcobjectsPath = path.resolve(findPackageNodePath("qcobjects"), "qcobjects");
|
|
140
|
+
let backend = CONFIG.get("backend");
|
|
141
|
+
if (typeof backend === "undefined") {
|
|
142
|
+
backend = {};
|
|
153
143
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
"name": "QCObjects-SDK.js",
|
|
157
|
-
"description": "Redirection of QCObjects SDK",
|
|
158
|
-
"path": "^/js/packages/QCObjects-SDK.js$",
|
|
159
|
-
"microservice": "com.qcobjects.backend.microservice.static",
|
|
160
|
-
"redirect_to": path.resolve(sdkPath, "src/QCObjects-SDK.js"),
|
|
161
|
-
"responseHeaders": {},
|
|
162
|
-
"cors": {
|
|
163
|
-
"allow_origins": "*"
|
|
144
|
+
if (typeof backend.routes === "undefined") {
|
|
145
|
+
backend.routes = [];
|
|
164
146
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
147
|
+
backend.routes = backend.routes.concat([{
|
|
148
|
+
"name": "QCObjects.js",
|
|
149
|
+
"description": "Redirection of QCObjects.js",
|
|
150
|
+
"path": "^/QCObjects.js$",
|
|
151
|
+
"microservice": "com.qcobjects.backend.microservice.static",
|
|
152
|
+
"redirect_to": path.resolve(qcobjectsPath,"src","QCObjects.js"),
|
|
153
|
+
"responseHeaders": {},
|
|
154
|
+
"cors": {
|
|
155
|
+
"allow_origins": "*"
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"name": "QCObjects-SDK.js",
|
|
160
|
+
"description": "Redirection of QCObjects SDK",
|
|
161
|
+
"path": "^/js/packages/QCObjects-SDK.js$",
|
|
162
|
+
"microservice": "com.qcobjects.backend.microservice.static",
|
|
163
|
+
"redirect_to": path.resolve(sdkPath, "src/QCObjects-SDK.js"),
|
|
164
|
+
"responseHeaders": {},
|
|
165
|
+
"cors": {
|
|
166
|
+
"allow_origins": "*"
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"name": "QCObjects-SDK Components",
|
|
171
|
+
"description": "Redirection of QCObjects SDK",
|
|
172
|
+
"path": "^/qcobjects-sdk/(.*)$",
|
|
173
|
+
"microservice": "com.qcobjects.backend.microservice.static",
|
|
174
|
+
"redirect_to": path.resolve(sdkPath, "$1"),
|
|
175
|
+
"responseHeaders": {},
|
|
176
|
+
"cors": {
|
|
177
|
+
"allow_origins": "*"
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
]);
|
|
182
|
+
CONFIG.set("backend", backend);
|
|
183
|
+
|
|
184
|
+
};
|
|
185
|
+
await loadDefaultRoutes();
|
|
186
|
+
})().then(() => logger.info("Default routes loaded"));
|
|
187
|
+
|
|
188
|
+
(function () {
|
|
189
|
+
/* Auto Discover dependencies (lib, handlers, commands) */
|
|
190
|
+
const path = require("path");
|
|
191
|
+
const fs = require ("fs");
|
|
192
|
+
const projectPath = CONFIG.get("projectPath", `${process.cwd()}/`);
|
|
193
|
+
logger.debug(`CONFIG.projectPath is set to ${projectPath}`);
|
|
194
|
+
const findPath = (p) => {
|
|
195
|
+
const packagePath = path.resolve(findPackageNodePath(p), p);
|
|
196
|
+
return packagePath;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const getPackageJSON = (p) => {
|
|
200
|
+
let _json;
|
|
201
|
+
try {
|
|
202
|
+
let packagePath = findPath(p);
|
|
203
|
+
if (typeof packagePath !== "undefined"){
|
|
204
|
+
_json = JSON.parse(fs.readFileSync(path.resolve(`${packagePath}`,"./package.json")).toString());
|
|
205
|
+
} else {
|
|
206
|
+
_json = {};
|
|
207
|
+
}
|
|
208
|
+
} catch (e){
|
|
209
|
+
logger.debug(`It was impossible to get the package.json from ${p}: ${e}`);
|
|
210
|
+
_json = {}
|
|
175
211
|
}
|
|
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
|
-
|
|
212
|
+
return _json;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const hasKeyword = (p, keyword) => {
|
|
216
|
+
if (typeof hasKeyword.keywords === "undefined"){
|
|
217
|
+
hasKeyword.keywords = {};
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
if (typeof hasKeyword.keywords[p] === "undefined"){
|
|
221
|
+
hasKeyword.keywords[p] = getPackageJSON(p).keywords;
|
|
222
|
+
}
|
|
223
|
+
} catch (e){
|
|
224
|
+
throw Error (`Something went wrong when trying to get the keywords of ${p}`);
|
|
225
|
+
}
|
|
226
|
+
return typeof hasKeyword.keywords[p] !== "undefined" && hasKeyword.keywords[p].includes(keyword);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const setBackendValue = (name, value) => {
|
|
230
|
+
const backend = CONFIG.get("backend", {});
|
|
231
|
+
if (typeof value !== "undefined"){
|
|
232
|
+
backend[name] = value;
|
|
233
|
+
}
|
|
234
|
+
CONFIG.set("backend",backend);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const dependencies = () => {
|
|
238
|
+
if (typeof dependencies.deps === "undefined"){
|
|
239
|
+
dependencies.deps = Object.keys(JSON.parse(fs.readFileSync(path.resolve(`${projectPath}`,"./package.json")).toString()).dependencies);
|
|
240
|
+
setBackendValue("dependencies", dependencies.deps);
|
|
241
|
+
}
|
|
242
|
+
return dependencies.deps;
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const devDependencies = () => {
|
|
246
|
+
if (typeof devDependencies.deps === "undefined"){
|
|
247
|
+
devDependencies.deps = Object.keys(JSON.parse(fs.readFileSync(path.resolve(`${projectPath}`,"./package.json")).toString()).devDependencies);
|
|
248
|
+
setBackendValue("devDependencies", devDependencies.deps);
|
|
249
|
+
}
|
|
250
|
+
return devDependencies.deps;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const loadLibs = () => {
|
|
254
|
+
let _ret_;
|
|
255
|
+
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_libs", false)) {
|
|
256
|
+
const libs = dependencies().filter((p) => hasKeyword(p, "qcobjects-lib"));
|
|
257
|
+
setBackendValue("libs", libs);
|
|
258
|
+
if (libs.length>0){
|
|
259
|
+
logger.debug(`Plugin Libs found: ${libs}`);
|
|
260
|
+
_ret_ = Promise.all(libs.map((p) => {return require(findPath(p));})).then(() => logger.info("Libs loaded"));
|
|
261
|
+
} else {
|
|
262
|
+
logger.debug("No Plugin Libs found.");
|
|
263
|
+
_ret_ = Promise.resolve();
|
|
264
|
+
}
|
|
265
|
+
} else {
|
|
266
|
+
logger.debug("To load libs, set autodiscover_libs to true in your config.json");
|
|
267
|
+
_ret_ = Promise.resolve();
|
|
268
|
+
}
|
|
269
|
+
return _ret_;
|
|
270
|
+
};
|
|
271
|
+
const loadHandlers = () => {
|
|
272
|
+
let _ret_;
|
|
273
|
+
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_handlers", false)) {
|
|
274
|
+
const handlers = dependencies().filter((p) => hasKeyword(p, "qcobjects-handler"));
|
|
275
|
+
setBackendValue("handlers", handlers);
|
|
276
|
+
if (handlers.length>0){
|
|
277
|
+
logger.debug(`Plugin Handlers found: ${handlers}`);
|
|
278
|
+
_ret_ = Promise.all(handlers.map((p) => {return require(findPath(p));})).then(() => logger.info("Handlers loaded"));
|
|
279
|
+
} else {
|
|
280
|
+
logger.debug("No Plugin Handlers found.");
|
|
281
|
+
_ret_ = Promise.resolve();
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
logger.debug("To load handlers, set autodiscover_handlers to true in your config.json");
|
|
285
|
+
_ret_ = Promise.resolve();
|
|
286
|
+
}
|
|
287
|
+
return _ret_;
|
|
288
|
+
};
|
|
289
|
+
const loadCommands = () => {
|
|
290
|
+
let _ret_;
|
|
291
|
+
logger.debug(`Looking for custom commands as dependencies in: ${projectPath}/package.json`);
|
|
292
|
+
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_commands", false)) {
|
|
293
|
+
const commands = dependencies().filter((p) => hasKeyword(p, "qcobjects-command"));
|
|
294
|
+
setBackendValue("commands", commands);
|
|
295
|
+
if (commands.length>0){
|
|
296
|
+
logger.debug(`Plugin Commands found: ${commands}`);
|
|
297
|
+
_ret_ = Promise.all(commands.map((p) => {return require(findPath(p));})).then(() => logger.info("Commands loaded"));
|
|
298
|
+
} else {
|
|
299
|
+
logger.debug("No Plugin Commands found.");
|
|
300
|
+
_ret_ = Promise.resolve();
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
logger.debug("To load commands, set autodiscover_commands to true in your config.json");
|
|
304
|
+
_ret_ = Promise.resolve();
|
|
305
|
+
}
|
|
306
|
+
return _ret_;
|
|
307
|
+
};
|
|
308
|
+
const loadDevCommands = () => {
|
|
309
|
+
let _ret_;
|
|
310
|
+
logger.debug(`Looking for custom commands as dev dependencies in: ${projectPath}/package.json`);
|
|
311
|
+
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_commands", false)) {
|
|
312
|
+
const commands = devDependencies().filter((p) => hasKeyword(p, "qcobjects-command"));
|
|
313
|
+
setBackendValue("devCommands", commands);
|
|
314
|
+
if (commands.length>0){
|
|
315
|
+
logger.debug(`Dev Plugin Commands found: ${commands}`);
|
|
316
|
+
_ret_ = Promise.all(commands.map((p) => {return require(findPath(p));})).then(() => logger.info("Commands loaded"));
|
|
317
|
+
} else {
|
|
318
|
+
logger.debug("No Plugin Commands found in dev dependencies.");
|
|
319
|
+
_ret_ = Promise.resolve();
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
logger.debug("To load commands, set autodiscover_commands to true in your config.json");
|
|
323
|
+
_ret_ = Promise.resolve();
|
|
324
|
+
}
|
|
325
|
+
return _ret_;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
if (CONFIG.get("autodiscover", false) ||
|
|
329
|
+
CONFIG.get("autodiscover_libs", false) ||
|
|
330
|
+
CONFIG.get("autodiscover_handlers", false) ||
|
|
331
|
+
CONFIG.get("autodiscover_commands", false)
|
|
332
|
+
) {
|
|
333
|
+
logger.info("Auto discover is enabled");
|
|
334
|
+
} else if (!CONFIG.get("autodiscover", false)) {
|
|
335
|
+
logger.info("Auto discover is disabled");
|
|
336
|
+
logger.debug("To load all dependencies, set autodiscover to true in your config.json");
|
|
202
337
|
} else {
|
|
203
|
-
|
|
338
|
+
logger.info("Auto discover is disabled");
|
|
204
339
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const hasKeyword = (p, keyword) => {
|
|
213
|
-
if (typeof hasKeyword.keywords === "undefined"){
|
|
214
|
-
hasKeyword.keywords = {};
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
if (typeof hasKeyword.keywords[p] === "undefined"){
|
|
218
|
-
hasKeyword.keywords[p] = getPackageJSON(p).keywords;
|
|
219
|
-
}
|
|
220
|
-
} catch (e){
|
|
221
|
-
throw Error (`Something went wrong when trying to get the keywords of ${p}`);
|
|
222
|
-
}
|
|
223
|
-
return typeof hasKeyword.keywords[p] !== "undefined" && hasKeyword.keywords[p].includes(keyword);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
const setBackendValue = (name, value) => {
|
|
227
|
-
const backend = CONFIG.get("backend", {});
|
|
228
|
-
if (typeof value !== "undefined"){
|
|
229
|
-
backend[name] = value;
|
|
230
|
-
}
|
|
231
|
-
CONFIG.set("backend",backend);
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
const dependencies = () => {
|
|
235
|
-
if (typeof dependencies.deps === "undefined"){
|
|
236
|
-
dependencies.deps = Object.keys(JSON.parse(fs.readFileSync(path.resolve(`${projectPath}`,"./package.json")).toString()).dependencies);
|
|
237
|
-
setBackendValue("dependencies", dependencies.deps);
|
|
238
|
-
}
|
|
239
|
-
return dependencies.deps;
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
const devDependencies = () => {
|
|
243
|
-
if (typeof devDependencies.deps === "undefined"){
|
|
244
|
-
devDependencies.deps = Object.keys(JSON.parse(fs.readFileSync(path.resolve(`${projectPath}`,"./package.json")).toString()).devDependencies);
|
|
245
|
-
setBackendValue("devDependencies", devDependencies.deps);
|
|
246
|
-
}
|
|
247
|
-
return devDependencies.deps;
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const loadLibs = () => {
|
|
251
|
-
let _ret_;
|
|
252
|
-
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_libs", false)) {
|
|
253
|
-
const libs = dependencies().filter((p) => hasKeyword(p, "qcobjects-lib"));
|
|
254
|
-
setBackendValue("libs", libs);
|
|
255
|
-
if (libs.length>0){
|
|
256
|
-
logger.debug(`Plugin Libs found: ${libs}`);
|
|
257
|
-
_ret_ = Promise.all(libs.map((p) => {return require(findPath(p));})).then(() => logger.info("Libs loaded"));
|
|
258
|
-
} else {
|
|
259
|
-
logger.debug("No Plugin Libs found.");
|
|
260
|
-
_ret_ = Promise.resolve();
|
|
340
|
+
|
|
341
|
+
try {
|
|
342
|
+
logger.debug("Loading Libs...");
|
|
343
|
+
loadLibs();
|
|
344
|
+
} catch (e) {
|
|
345
|
+
throw Error(`Something went wrong trying to load libs: ${e.message}`);
|
|
261
346
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
};
|
|
268
|
-
const loadHandlers = () => {
|
|
269
|
-
let _ret_;
|
|
270
|
-
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_handlers", false)) {
|
|
271
|
-
const handlers = dependencies().filter((p) => hasKeyword(p, "qcobjects-handler"));
|
|
272
|
-
setBackendValue("handlers", handlers);
|
|
273
|
-
if (handlers.length>0){
|
|
274
|
-
logger.debug(`Plugin Handlers found: ${handlers}`);
|
|
275
|
-
_ret_ = Promise.all(handlers.map((p) => {return require(findPath(p));})).then(() => logger.info("Handlers loaded"));
|
|
276
|
-
} else {
|
|
277
|
-
logger.debug("No Plugin Handlers found.");
|
|
278
|
-
_ret_ = Promise.resolve();
|
|
347
|
+
try {
|
|
348
|
+
logger.debug("Loading Handlers...");
|
|
349
|
+
loadHandlers();
|
|
350
|
+
} catch (e) {
|
|
351
|
+
throw Error(`Something went wrong trying to load handler: ${e.message}`);
|
|
279
352
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
};
|
|
286
|
-
const loadCommands = () => {
|
|
287
|
-
let _ret_;
|
|
288
|
-
logger.debug(`Looking for custom commands as dependencies in: ${projectPath}/package.json`);
|
|
289
|
-
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_commands", false)) {
|
|
290
|
-
const commands = dependencies().filter((p) => hasKeyword(p, "qcobjects-command"));
|
|
291
|
-
setBackendValue("commands", commands);
|
|
292
|
-
if (commands.length>0){
|
|
293
|
-
logger.debug(`Plugin Commands found: ${commands}`);
|
|
294
|
-
_ret_ = Promise.all(commands.map((p) => {return require(findPath(p));})).then(() => logger.info("Commands loaded"));
|
|
295
|
-
} else {
|
|
296
|
-
logger.debug("No Plugin Commands found.");
|
|
297
|
-
_ret_ = Promise.resolve();
|
|
353
|
+
try {
|
|
354
|
+
logger.debug("Loading Commands...");
|
|
355
|
+
loadCommands();
|
|
356
|
+
} catch (e) {
|
|
357
|
+
throw Error(`Something went wrong trying to load commands: ${e.message}`);
|
|
298
358
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
};
|
|
305
|
-
const loadDevCommands = () => {
|
|
306
|
-
let _ret_;
|
|
307
|
-
logger.debug(`Looking for custom commands as dev dependencies in: ${projectPath}/package.json`);
|
|
308
|
-
if (CONFIG.get("autodiscover", false) || CONFIG.get("autodiscover_commands", false)) {
|
|
309
|
-
const commands = devDependencies().filter((p) => hasKeyword(p, "qcobjects-command"));
|
|
310
|
-
setBackendValue("devCommands", commands);
|
|
311
|
-
if (commands.length>0){
|
|
312
|
-
logger.debug(`Dev Plugin Commands found: ${commands}`);
|
|
313
|
-
_ret_ = Promise.all(commands.map((p) => {return require(findPath(p));})).then(() => logger.info("Commands loaded"));
|
|
314
|
-
} else {
|
|
315
|
-
logger.debug("No Plugin Commands found in dev dependencies.");
|
|
316
|
-
_ret_ = Promise.resolve();
|
|
359
|
+
try {
|
|
360
|
+
logger.debug("Loading Dev Commands...");
|
|
361
|
+
loadDevCommands();
|
|
362
|
+
} catch (e) {
|
|
363
|
+
throw Error(`Something went wrong trying to load Dev commands: ${e.message}`);
|
|
317
364
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
365
|
+
|
|
366
|
+
try {
|
|
367
|
+
const commands = CONFIG.get("backend", {commands:[]}).commands || [];
|
|
368
|
+
const devCommands = CONFIG.get("backend", {devCommands:[]}).devCommands || [];
|
|
369
|
+
setBackendValue("plugins", commands.concat(devCommands));
|
|
370
|
+
} catch (e) {
|
|
371
|
+
throw Error(`Something went wrong trying to load plugins list: ${e.message}`);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
logger.info("Dependencies loaded");
|
|
375
|
+
|
|
376
|
+
process.once("SIGTERM", ()=> {
|
|
377
|
+
console.log("\x1b[33m%s\x1b[0m", "Bye bye!");
|
|
378
|
+
process.exit();
|
|
379
|
+
});
|
|
380
|
+
})();
|
|
323
381
|
};
|
|
324
382
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
CONFIG.get("autodiscover_handlers", false) ||
|
|
328
|
-
CONFIG.get("autodiscover_commands", false)
|
|
329
|
-
) {
|
|
330
|
-
logger.info("Auto discover is enabled");
|
|
331
|
-
} else if (!CONFIG.get("autodiscover", false)) {
|
|
332
|
-
logger.info("Auto discover is disabled");
|
|
333
|
-
logger.debug("To load all dependencies, set autodiscover to true in your config.json");
|
|
334
|
-
} else {
|
|
335
|
-
logger.info("Auto discover is disabled");
|
|
336
|
-
}
|
|
383
|
+
global.__load_default_settings__ = __load_default_settings__;
|
|
384
|
+
global.__load_default_settings__();
|
|
337
385
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
loadLibs();
|
|
341
|
-
} catch (e) {
|
|
342
|
-
throw Error(`Something went wrong trying to load libs: ${e.message}`);
|
|
343
|
-
}
|
|
344
|
-
try {
|
|
345
|
-
logger.debug("Loading Handlers...");
|
|
346
|
-
loadHandlers();
|
|
347
|
-
} catch (e) {
|
|
348
|
-
throw Error(`Something went wrong trying to load handler: ${e.message}`);
|
|
349
|
-
}
|
|
350
|
-
try {
|
|
351
|
-
logger.debug("Loading Commands...");
|
|
352
|
-
loadCommands();
|
|
353
|
-
} catch (e) {
|
|
354
|
-
throw Error(`Something went wrong trying to load commands: ${e.message}`);
|
|
355
|
-
}
|
|
356
|
-
try {
|
|
357
|
-
logger.debug("Loading Dev Commands...");
|
|
358
|
-
loadDevCommands();
|
|
359
|
-
} catch (e) {
|
|
360
|
-
throw Error(`Something went wrong trying to load Dev commands: ${e.message}`);
|
|
386
|
+
const cleanCache = () => {
|
|
387
|
+
Object.keys(require.cache).forEach( (key) => { delete require.cache[key]; });
|
|
361
388
|
}
|
|
362
389
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
} catch (e) {
|
|
368
|
-
throw Error(`Something went wrong trying to load plugins list: ${e.message}`);
|
|
369
|
-
}
|
|
390
|
+
const __reset_settings__ = () => {
|
|
391
|
+
cleanCache();
|
|
392
|
+
global.__load_default_settings__();
|
|
393
|
+
};
|
|
370
394
|
|
|
371
|
-
|
|
395
|
+
global.__reset_settings__ = __reset_settings__;
|
|
372
396
|
|
|
373
|
-
process.once("SIGTERM", ()=> {
|
|
374
|
-
console.log("\x1b[33m%s\x1b[0m", "Bye bye!");
|
|
375
|
-
process.exit();
|
|
376
|
-
});
|
|
377
397
|
})();
|