qtools-library-dot-d 1.0.0 → 1.0.2
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/package.json +5 -2
- package/qtools-library-dot-d.js +80 -24
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qtools-library-dot-d",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
9
|
"author": "TQ White II",
|
|
10
|
-
"license": "ISC"
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"qtools-asynchronous-pipe-plus": "^1.0.2"
|
|
13
|
+
}
|
|
11
14
|
}
|
package/qtools-library-dot-d.js
CHANGED
|
@@ -9,15 +9,14 @@ const os = require('os');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
|
|
12
|
-
console.log(`HELLO FROM ${__dirname}/${moduleName}`);
|
|
13
12
|
//START OF moduleFunction() ============================================================
|
|
14
13
|
const moduleFunction = ({ moduleName } = {}) => ({ libraryName }) => {
|
|
15
14
|
// ======================================================================================
|
|
16
15
|
// SETTERS
|
|
17
|
-
|
|
16
|
+
|
|
18
17
|
// --------------------------------------------------------------------------------
|
|
19
18
|
// SET LIBRARY PATH
|
|
20
|
-
|
|
19
|
+
|
|
21
20
|
let libraryPath;
|
|
22
21
|
|
|
23
22
|
const setLibraryPath = (dirPath, callback) => {
|
|
@@ -38,19 +37,18 @@ const moduleFunction = ({ moduleName } = {}) => ({ libraryName }) => {
|
|
|
38
37
|
require(item.endpointPath)(item.moduleArgs);
|
|
39
38
|
callback();
|
|
40
39
|
};
|
|
41
|
-
|
|
40
|
+
|
|
42
41
|
let add = defaultAdd;
|
|
43
|
-
|
|
42
|
+
|
|
44
43
|
const setCustomAddFunction = newFunction => (add = newFunction);
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
|
|
47
45
|
// ======================================================================================
|
|
48
46
|
// LOG LIST OBJECT
|
|
49
|
-
|
|
47
|
+
|
|
50
48
|
const logList = (() => {
|
|
51
49
|
const list = [];
|
|
52
50
|
const push = item => list.push(item);
|
|
53
|
-
const
|
|
51
|
+
const formatList = () => {
|
|
54
52
|
return list
|
|
55
53
|
.reduce(
|
|
56
54
|
(result, item) => `${result}${item}\n\t`,
|
|
@@ -58,27 +56,81 @@ const moduleFunction = ({ moduleName } = {}) => ({ libraryName }) => {
|
|
|
58
56
|
)
|
|
59
57
|
.replace(/\n\t$/, '');
|
|
60
58
|
};
|
|
61
|
-
return { push,
|
|
59
|
+
return { push, formatList };
|
|
62
60
|
})();
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
|
|
65
62
|
// ======================================================================================
|
|
66
63
|
// LIBRARY OBJECT
|
|
67
64
|
|
|
65
|
+
const libraryObject = {}; //used only for producing display listings
|
|
68
66
|
const library = (() => {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return Object.keys(list)
|
|
73
|
-
.reduce(
|
|
74
|
-
(result, name) => `${result}${name}: ${(typeof(list[name])).match(/(string|number)/i)?list[name]:typeof(list[name])}\n\t`,
|
|
75
|
-
`\n${libraryName} Library\n\t`
|
|
76
|
-
)
|
|
77
|
-
.replace(/\n\t$/, '');
|
|
67
|
+
const add = (name, item) => {
|
|
68
|
+
libraryObject[name] = item; //used only for producing display listings
|
|
69
|
+
externalElements[name] = item;
|
|
78
70
|
};
|
|
79
|
-
return { add
|
|
71
|
+
return { add };
|
|
80
72
|
})();
|
|
73
|
+
|
|
74
|
+
// ======================================================================================
|
|
75
|
+
// LIBRARY OBJECT
|
|
76
|
+
|
|
77
|
+
const toString = () => {
|
|
78
|
+
|
|
79
|
+
const formatProperty=item=>{
|
|
80
|
+
let outString=typeof(item);
|
|
81
|
+
if (typeof(item)=='function'){
|
|
82
|
+
const result=item.toString().match(/\((?<args>.*?\))/);
|
|
83
|
+
outString=`(${result.qtGetSurePath('groups.args', 'function')})`
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
return outString;
|
|
87
|
+
}
|
|
81
88
|
|
|
89
|
+
return Object.keys(libraryObject)
|
|
90
|
+
.reduce(
|
|
91
|
+
(result, name) =>
|
|
92
|
+
`${result}${name}: ${
|
|
93
|
+
(typeof libraryObject[name]).match(/(string|number)/i)
|
|
94
|
+
? libraryObject[name]
|
|
95
|
+
: formatProperty(libraryObject[name])
|
|
96
|
+
}\n\t`,
|
|
97
|
+
`\n${libraryName} Library\n\t`
|
|
98
|
+
)
|
|
99
|
+
.replace(/\n\t$/, '');
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
// ======================================================================================
|
|
103
|
+
// SEAL OBJECT (make immutable)
|
|
104
|
+
|
|
105
|
+
const sealActual = externalElements => () => {
|
|
106
|
+
Object.assign(
|
|
107
|
+
externalElements.library.qtSelectProperties(['add'], {
|
|
108
|
+
excludeMode: true
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
Object.assign(
|
|
112
|
+
externalElements.logList.qtSelectProperties(['push'], {
|
|
113
|
+
excludeMode: true
|
|
114
|
+
})
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
Object.assign(
|
|
118
|
+
externalElements.qtSelectProperties(
|
|
119
|
+
[
|
|
120
|
+
'setLibraryPath',
|
|
121
|
+
'loadModules',
|
|
122
|
+
'seal',
|
|
123
|
+
'setCustomAddFunction',
|
|
124
|
+
'library',
|
|
125
|
+
'logList'
|
|
126
|
+
],
|
|
127
|
+
{ excludeMode: true }
|
|
128
|
+
)
|
|
129
|
+
);
|
|
130
|
+
Object.freeze(externalElements);
|
|
131
|
+
Object.seal(externalElements);
|
|
132
|
+
};
|
|
133
|
+
|
|
82
134
|
// ======================================================================================
|
|
83
135
|
// LOAD MODULES (actual execution)
|
|
84
136
|
|
|
@@ -153,13 +205,17 @@ const moduleFunction = ({ moduleName } = {}) => ({ libraryName }) => {
|
|
|
153
205
|
});
|
|
154
206
|
};
|
|
155
207
|
|
|
156
|
-
|
|
208
|
+
const externalElements = {
|
|
157
209
|
setLibraryPath,
|
|
158
210
|
setCustomAddFunction,
|
|
159
211
|
logList,
|
|
160
212
|
library,
|
|
161
|
-
loadModules
|
|
213
|
+
loadModules,
|
|
214
|
+
toString,
|
|
215
|
+
qtdProcessLog: logList.formatList
|
|
162
216
|
};
|
|
217
|
+
externalElements.seal = sealActual(externalElements);
|
|
218
|
+
return externalElements;
|
|
163
219
|
};
|
|
164
220
|
|
|
165
221
|
//END OF moduleFunction() ============================================================
|