qtools-library-dot-d 1.0.3 → 1.0.4
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/README.md +4 -0
- package/package.json +1 -1
- package/qtools-library-dot-d.js +18 -3
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qtools-library-dot-d",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Scan a directory for JS modules that can execute and addMe() that attaches it to some form of name/value list, eg, a Map() with functions as values or an xPressJS route/endpoint list.",
|
|
5
5
|
"main": "qtools-library-dot-d.js",
|
|
6
6
|
"scripts": {
|
package/qtools-library-dot-d.js
CHANGED
|
@@ -40,9 +40,17 @@ const moduleFunction =
|
|
|
40
40
|
// SET CUSTOM MODULE ADDING FUNCTION
|
|
41
41
|
|
|
42
42
|
const defaultAdd = (item, callback) => {
|
|
43
|
-
|
|
43
|
+
let error;
|
|
44
|
+
try {
|
|
45
|
+
require(item.endpointPath)(item.moduleArgs); //calls module with dotD object, including library.add()
|
|
46
|
+
} catch (err) {
|
|
47
|
+
item.exceptionList.push(
|
|
48
|
+
`${path.basename(item.endpointPath)}: ${err.toString().split('\n').qtFirst('n/a')}`,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
44
52
|
if (typeof callback == 'function') {
|
|
45
|
-
callback();
|
|
53
|
+
callback(error);
|
|
46
54
|
} else {
|
|
47
55
|
return;
|
|
48
56
|
}
|
|
@@ -73,6 +81,7 @@ const moduleFunction =
|
|
|
73
81
|
// LIBRARY OBJECT
|
|
74
82
|
|
|
75
83
|
const libraryObject = {}; //used only for producing display listings
|
|
84
|
+
const exceptionList = [];
|
|
76
85
|
const library = (() => {
|
|
77
86
|
const add = (name, item) => {
|
|
78
87
|
libraryObject[name] = item; //used only for producing display listings
|
|
@@ -94,7 +103,7 @@ const moduleFunction =
|
|
|
94
103
|
return outString;
|
|
95
104
|
};
|
|
96
105
|
|
|
97
|
-
|
|
106
|
+
const libString = Object.keys(libraryObject)
|
|
98
107
|
.reduce(
|
|
99
108
|
(result, name) =>
|
|
100
109
|
`${result}${name}: ${
|
|
@@ -105,6 +114,10 @@ const moduleFunction =
|
|
|
105
114
|
`\n${libraryName} Library\n\t`,
|
|
106
115
|
)
|
|
107
116
|
.replace(/\n\t$/, '');
|
|
117
|
+
|
|
118
|
+
const exceptionString = '\n\t' + exceptionList.join('\n\t');
|
|
119
|
+
|
|
120
|
+
return `${libString}${exceptionString}`;
|
|
108
121
|
};
|
|
109
122
|
|
|
110
123
|
// ======================================================================================
|
|
@@ -179,9 +192,11 @@ const moduleFunction =
|
|
|
179
192
|
//.filter(file => path.extname(file) === '.js')
|
|
180
193
|
.forEach((file) => {
|
|
181
194
|
const endpointPath = path.join(libraryPath, file);
|
|
195
|
+
|
|
182
196
|
add({
|
|
183
197
|
endpointPath,
|
|
184
198
|
moduleArgs,
|
|
199
|
+
exceptionList,
|
|
185
200
|
});
|
|
186
201
|
});
|
|
187
202
|
|