qtools-library-dot-d 1.0.4 → 1.0.5
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 +153 -1
- package/package.json +3 -2
- package/qtools-library-dot-d.js +15 -5
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ promptObjects.seal(); //make the library immutable
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
SYNCHROMOUS CODE SAMPLE:
|
|
43
43
|
|
|
44
44
|
const promptObjects = require('qtools-library-dot-d')({
|
|
45
45
|
libraryName: 'promptObjects',
|
|
@@ -51,6 +51,158 @@ promptObjects.loadModules({ passThroughParameters });
|
|
|
51
51
|
promptObjects.seal(); //make the library immutable
|
|
52
52
|
|
|
53
53
|
|
|
54
|
+
COMPLETE WORKING CODE SAMPLE
|
|
55
|
+
|
|
56
|
+
// ================================================================================
|
|
57
|
+
// index.js for demonstration
|
|
58
|
+
|
|
59
|
+
#!/usr/bin/env node
|
|
60
|
+
'use strict';
|
|
61
|
+
// Suppress punycode deprecation warning
|
|
62
|
+
process.noDeprecation = true;
|
|
63
|
+
|
|
64
|
+
const moduleName = __filename.replace(__dirname + '/', '').replace(/.js$/, ''); //this just seems to come in handy a lot
|
|
65
|
+
|
|
66
|
+
// const qt = require('qtools-functional-library'); //also exposes qtLog(); qt.help({printOutput:true, queryString:'.*', sendJson:false});
|
|
67
|
+
|
|
68
|
+
const os = require('os');
|
|
69
|
+
const path = require('path');
|
|
70
|
+
const fs = require('fs');
|
|
71
|
+
|
|
72
|
+
const qtLibDotD = require('qtools-library-dot-d');
|
|
73
|
+
|
|
74
|
+
//START OF moduleFunction() ============================================================
|
|
75
|
+
const moduleFunction =
|
|
76
|
+
({ moduleName } = {}) =>
|
|
77
|
+
({ unused } = {}) => {
|
|
78
|
+
|
|
79
|
+
// ========================================================================
|
|
80
|
+
// SYNCHRONOUS DEMO
|
|
81
|
+
|
|
82
|
+
const synchronousDemo = () => {
|
|
83
|
+
const demoDotD = qtLibDotD({
|
|
84
|
+
libraryName: 'demoDotD',
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const libraryModulesPath = path.join(__dirname, 'demoModules_DotD');
|
|
88
|
+
|
|
89
|
+
const passThroughParameters = {
|
|
90
|
+
message: 'Hello from a dotDlib module',
|
|
91
|
+
add: (a, b) => a + b,
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
demoDotD.setLibraryPath(libraryModulesPath);
|
|
95
|
+
demoDotD.loadModules({ passThroughParameters });
|
|
96
|
+
demoDotD.seal();
|
|
97
|
+
|
|
98
|
+
// console.log(demoDotD.qtdProcessLog());
|
|
99
|
+
console.log(demoDotD.toString());
|
|
100
|
+
|
|
101
|
+
demoDotD.demo1();
|
|
102
|
+
demoDotD.demo2(10, 7);
|
|
103
|
+
};
|
|
104
|
+
console.log(`SYNCHRONOUS DEMO =====================================`);
|
|
105
|
+
synchronousDemo();
|
|
106
|
+
|
|
107
|
+
// ========================================================================
|
|
108
|
+
// ASYNCHRONOUS DEMO
|
|
109
|
+
|
|
110
|
+
const asynchronousDemo = (callback) => {
|
|
111
|
+
const localCallback = (err) => {
|
|
112
|
+
demoDotD.seal();
|
|
113
|
+
callback(err, demoDotD);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const demoDotD = qtLibDotD({
|
|
117
|
+
libraryName: 'demoDotD',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const libraryModulesPath = path.join(__dirname, 'demoModules_DotD');
|
|
121
|
+
|
|
122
|
+
const passThroughParameters = {
|
|
123
|
+
message: 'Hello from a dotDlib module',
|
|
124
|
+
add: (a, b) => a + b,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
demoDotD.setLibraryPath(libraryModulesPath);
|
|
128
|
+
demoDotD.loadModules({ passThroughParameters }, localCallback);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
console.log(`\n\nASYNCHRONOUS DEMO =====================================`);
|
|
132
|
+
|
|
133
|
+
const callback = (err, demoDotD) => {
|
|
134
|
+
console.log(demoDotD.toString());
|
|
135
|
+
demoDotD.demo1();
|
|
136
|
+
demoDotD.demo2(10, 7);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
asynchronousDemo(callback);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
// ================================================================================
|
|
144
|
+
// demo1.js
|
|
145
|
+
|
|
146
|
+
#!/usr/bin/env node
|
|
147
|
+
'use strict';
|
|
148
|
+
// Suppress punycode deprecation warning
|
|
149
|
+
process.noDeprecation = true;
|
|
150
|
+
|
|
151
|
+
const moduleName = __filename.replace(__dirname + '/', '').replace(/.js$/, ''); //this just seems to come in handy a lot
|
|
152
|
+
|
|
153
|
+
//START OF moduleFunction() ============================================================
|
|
154
|
+
const moduleFunction = ({ moduleName } = {}) => ({ dotD, passThroughParameters } = {}) => {
|
|
155
|
+
|
|
156
|
+
const workingFunction = () => {
|
|
157
|
+
console.log(`${passThroughParameters.message} [${moduleName}]`);
|
|
158
|
+
return 'hello';
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
dotD.library.add(moduleName, workingFunction);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
//END OF moduleFunction() ============================================================
|
|
166
|
+
|
|
167
|
+
module.exports = moduleFunction({ moduleName }); //runs it right now
|
|
168
|
+
//END OF moduleFunction() ============================================================
|
|
169
|
+
|
|
170
|
+
module.exports = moduleFunction({ moduleName })({});
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
// ================================================================================
|
|
174
|
+
//demo2.js
|
|
175
|
+
|
|
176
|
+
#!/usr/bin/env node
|
|
177
|
+
'use strict';
|
|
178
|
+
// Suppress punycode deprecation warning
|
|
179
|
+
process.noDeprecation = true;
|
|
180
|
+
|
|
181
|
+
const moduleName = __filename.replace(__dirname + '/', '').replace(/.js$/, ''); //this just seems to come in handy a lot
|
|
182
|
+
|
|
183
|
+
//START OF moduleFunction() ============================================================
|
|
184
|
+
const moduleFunction = ({ moduleName } = {}) => ({ dotD, passThroughParameters } = {}) => {
|
|
185
|
+
|
|
186
|
+
const workingFunction = (arg1, arg2) => {
|
|
187
|
+
console.log(`Pass Through Function: ${arg1}+${arg2}=${passThroughParameters.add(arg1, arg2)} [${moduleName}]`);
|
|
188
|
+
return 'hello';
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
dotD.library.add(moduleName, workingFunction);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
//END OF moduleFunction() ============================================================
|
|
196
|
+
|
|
197
|
+
module.exports = moduleFunction({ moduleName }); //runs it right now
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
HISTORY
|
|
201
|
+
|
|
202
|
+
v1.05 - cleaned up toString() report, returns exception list (or err if callback) if needed, added qtools-functional-library
|
|
203
|
+
v1.04 - Now tolerates (and reports) directories and files that are not modules.
|
|
204
|
+
|
|
205
|
+
|
|
54
206
|
HISTORY
|
|
55
207
|
|
|
56
208
|
v1.04 - Now tolerates (and reports) directories and files that are not modules.
|
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.5",
|
|
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": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"author": "TQ White II",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"qtools-asynchronous-pipe-plus": "^1.0.2"
|
|
12
|
+
"qtools-asynchronous-pipe-plus": "^1.0.2",
|
|
13
|
+
"qtools-functional-library": "^2.0.4"
|
|
13
14
|
}
|
|
14
15
|
}
|
package/qtools-library-dot-d.js
CHANGED
|
@@ -9,6 +9,8 @@ const os = require('os');
|
|
|
9
9
|
const path = require('path');
|
|
10
10
|
const fs = require('fs');
|
|
11
11
|
|
|
12
|
+
const qt = require('qtools-functional-library');
|
|
13
|
+
|
|
12
14
|
//START OF moduleFunction() ============================================================
|
|
13
15
|
const moduleFunction =
|
|
14
16
|
({ moduleName } = {}) =>
|
|
@@ -98,7 +100,8 @@ const moduleFunction =
|
|
|
98
100
|
let outString = typeof item;
|
|
99
101
|
if (typeof item == 'function') {
|
|
100
102
|
const result = item.toString().match(/\((?<args>.*?\))/);
|
|
101
|
-
|
|
103
|
+
const args = result.qtGetSurePath('groups.args', 'function');
|
|
104
|
+
outString = `(${args == ')' ? args + ' # function takes no arguments' : args}`;
|
|
102
105
|
}
|
|
103
106
|
return outString;
|
|
104
107
|
};
|
|
@@ -111,7 +114,7 @@ const moduleFunction =
|
|
|
111
114
|
? libraryObject[name]
|
|
112
115
|
: formatProperty(libraryObject[name])
|
|
113
116
|
}\n\t`,
|
|
114
|
-
`\n${libraryName} Library\n\t`,
|
|
117
|
+
`\n${libraryName} Library Elements\n\t`,
|
|
115
118
|
)
|
|
116
119
|
.replace(/\n\t$/, '');
|
|
117
120
|
|
|
@@ -204,10 +207,17 @@ const moduleFunction =
|
|
|
204
207
|
// INIT AND EXECUTE THE PIPELINE
|
|
205
208
|
|
|
206
209
|
if (typeof callback == 'function') {
|
|
207
|
-
|
|
210
|
+
if (exceptionList.length) {
|
|
211
|
+
callback(exceptionList);
|
|
212
|
+
} else {
|
|
213
|
+
callback();
|
|
214
|
+
}
|
|
208
215
|
} else {
|
|
209
|
-
|
|
210
|
-
|
|
216
|
+
if (exceptionList.length) {
|
|
217
|
+
return exceptionList;
|
|
218
|
+
} else {
|
|
219
|
+
return;
|
|
220
|
+
}}
|
|
211
221
|
};
|
|
212
222
|
|
|
213
223
|
const externalElements = {
|