qtools-library-dot-d 1.0.7 → 1.0.8
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 +18 -25
- package/package.json +1 -1
- package/qtools-library-dot-d.js +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ The "dotD" naming convention (short for "dot-D") refers to directories that cont
|
|
|
15
15
|
- `accessPoints.d/` - Directory containing data access modules
|
|
16
16
|
- `mappers.d/` - Directory containing data mapping modules
|
|
17
17
|
|
|
18
|
-
Each `.js` file in a dotD directory becomes a method on the library object, with the filename determining the method name.
|
|
18
|
+
Each module, `.js` file or directory with package.json, in a dotD directory becomes a method on the library object, with the filename determining the method name.
|
|
19
19
|
|
|
20
20
|
## Why Use Dynamic dotD Libraries?
|
|
21
21
|
|
|
@@ -30,10 +30,10 @@ const module2 = require('./modules/module2');
|
|
|
30
30
|
const module3 = require('./modules/module3');
|
|
31
31
|
|
|
32
32
|
// dotD approach - automatic discovery
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// All modules in modules.d/ are now available as
|
|
33
|
+
const myLibrary = qtLibDotD({ libraryName: 'myLibrary' }); //libraryName is used as a label in reports
|
|
34
|
+
myLibrary.setLibraryPath('./modules.d');
|
|
35
|
+
myLibrary.loadModules();
|
|
36
|
+
// All modules in modules.d/ are now available as myLibrary.moduleName()
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
### 2. **Plugin Architecture**
|
|
@@ -42,12 +42,12 @@ Create extensible applications where new functionality can be added by simply dr
|
|
|
42
42
|
|
|
43
43
|
```javascript
|
|
44
44
|
// Add new functionality by creating a new file
|
|
45
|
-
// modules.d/newFeature.js ->
|
|
45
|
+
// modules.d/newFeature.js -> myLibrary.newFeature()
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
### 3. **Shared Resources**
|
|
49
49
|
|
|
50
|
-
Pass common resources (configuration, database connections, utilities) to all modules through `passThroughParameters`.
|
|
50
|
+
Pass common resources (configuration, database connections, utilities) to all modules through `passThroughParameters`. These are given, by that name, to the module (along with the 'dotD', the library object) when it is instantiated during the loadModules() process.
|
|
51
51
|
|
|
52
52
|
```javascript
|
|
53
53
|
const passThroughParameters = {
|
|
@@ -56,7 +56,7 @@ const passThroughParameters = {
|
|
|
56
56
|
logger: xLog,
|
|
57
57
|
utilities: commonUtils
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
myLibrary.loadModules({ passThroughParameters });
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
### 4. **Clean Separation of Concerns**
|
|
@@ -111,13 +111,13 @@ Modules can be loaded synchronously or asynchronously, and the library can be se
|
|
|
111
111
|
|
|
112
112
|
```javascript
|
|
113
113
|
const qtLibDotD = require('qtools-library-dot-d');
|
|
114
|
-
const
|
|
114
|
+
const myLibrary = qtLibDotD({ libraryName: 'myLibrary' });
|
|
115
115
|
```
|
|
116
116
|
|
|
117
117
|
### 2. **Module Directory Setup**
|
|
118
118
|
|
|
119
119
|
```javascript
|
|
120
|
-
|
|
120
|
+
myLibrary.setLibraryPath('./modules.d');
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
### 3. **Shared Resource Definition**
|
|
@@ -127,33 +127,33 @@ const passThroughParameters = {
|
|
|
127
127
|
config: appConfig,
|
|
128
128
|
database: dbConnection,
|
|
129
129
|
logger: logger
|
|
130
|
-
};
|
|
130
|
+
}; //provided by loadModules() in the initialization object
|
|
131
131
|
```
|
|
132
132
|
|
|
133
133
|
### 4. **Module Loading**
|
|
134
134
|
|
|
135
135
|
```javascript
|
|
136
136
|
// Synchronous
|
|
137
|
-
|
|
137
|
+
myLibrary.loadModules({ passThroughParameters });
|
|
138
138
|
|
|
139
139
|
// Asynchronous
|
|
140
|
-
|
|
140
|
+
myLibrary.loadModules({ passThroughParameters }, callback);
|
|
141
141
|
```
|
|
142
142
|
|
|
143
143
|
### 5. **Library Sealing**
|
|
144
144
|
|
|
145
145
|
```javascript
|
|
146
|
-
|
|
146
|
+
myLibrary.seal(); // Prevents further modifications
|
|
147
147
|
```
|
|
148
148
|
|
|
149
149
|
### 6. **Module Usage**
|
|
150
150
|
|
|
151
151
|
```javascript
|
|
152
152
|
// If you have modules.d/processOrder.js
|
|
153
|
-
|
|
153
|
+
myLibrary.processOrder(orderData);
|
|
154
154
|
|
|
155
155
|
// If you have modules.d/sendEmail.js
|
|
156
|
-
|
|
156
|
+
myLibrary.sendEmail(recipient, message);
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
## Module Structure
|
|
@@ -201,13 +201,7 @@ module.exports = moduleFunction({ moduleName });
|
|
|
201
201
|
npm install qtools-library-dot-d
|
|
202
202
|
```
|
|
203
203
|
|
|
204
|
-
2. **
|
|
205
|
-
|
|
206
|
-
```bash
|
|
207
|
-
npm start
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
3. **Create your own modules:**
|
|
204
|
+
2. **Create your own modules:**
|
|
211
205
|
|
|
212
206
|
- Add `.js` files to `demoModules_DotD/`
|
|
213
207
|
- Follow the module pattern shown in the examples
|
|
@@ -235,7 +229,6 @@ This pattern is used extensively in the qtools ecosystem for building scalable,
|
|
|
235
229
|
|
|
236
230
|
## HISTORY
|
|
237
231
|
|
|
238
|
-
v1.
|
|
232
|
+
v1.08 - updated README (several times)
|
|
239
233
|
v1.05 - cleaned up toString() report, returns exception list (or err if callback) if needed, added qtools-functional-library
|
|
240
234
|
v1.04 - Now tolerates (and reports) directories and files that are not modules.
|
|
241
|
-
|
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.8",
|
|
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
|
@@ -14,7 +14,7 @@ const qt = require('qtools-functional-library');
|
|
|
14
14
|
//START OF moduleFunction() ============================================================
|
|
15
15
|
const moduleFunction =
|
|
16
16
|
({ moduleName } = {}) =>
|
|
17
|
-
({ libraryName }) => {
|
|
17
|
+
({ libraryName='libraryDotD' }) => {
|
|
18
18
|
// ======================================================================================
|
|
19
19
|
// SETTERS
|
|
20
20
|
|