@@ -84,30 +84,30 @@ How To Use
84
84
----------
85
85
86
86
OK, enough blabbing. Here's how you create and configure a DynamicModuleLoader:
87
-
87
+ ``` javascript
88
88
// Require all of the needful.
89
89
var LockManager = require (' hurt-locker' ).LockManager ;
90
90
var DynamicModuleLoader = require (' dynamic-module-loader' ).DynamicModuleLoader ;
91
91
92
+ // Create our config by overriding some default parameters
93
+ // All configurable parameters and their default values can be seen in [dml_config.js](lib/dml_config.js)
94
+ var dmlConfig = {
95
+ // Set the download directory. Default is ./downloads
96
+ downloadDir: path .normalize (" /some/accessible/location/downloads" ),
97
+ // Set the installed modules directory. Default is ./installed-modules
98
+ moduleInstallationDir: path .normalize (" /somewhere/else/accessible/installed-modules" ),
99
+ // Configure the package web sever URL. URL can be anything. Default is http://localhost.
100
+ modulePackageServerUrl: " http://gattacus" ,
101
+ // Provide the loader with a lock manager. If you don't do this it will create its own lock manager and use
102
+ // ./locks as the lock directory.
103
+ lockManager: new LockManager ({ lockDir: path .normalize (" /another/accessible/location/for/lock/files" ) })
104
+ }
92
105
// Create our loader.
93
- var dynamicModuleLoader = new DynamicModuleLoader();
94
-
95
- // Configure the directories needed by the module loader. These methods also have accessors (getXXDir()).
96
-
97
- // Set the download directory. Default is ./downloads
98
- dynamicModuleLoader.setDownloadDir(path.normalize("/some/accessible/location/downloads"));
99
-
100
- // Set the installed modules directory. Default is ./installed-modules
101
- dynamicModuleLoader.setModuleInstallationDir(path.normalize("/somewhere/else/accessible/installed-modules"));
106
+ var dynamicModuleLoader = new DynamicModuleLoader (dmlConfig);
102
107
103
- // Configure the package web sever URL. URL can be anything. Default is http://localhost.
104
- dynamicModuleLoader.setModulePackageServerUrl("http://gattacus");
105
-
106
- // Provide the loader with a lock manager. If you don't do this it will create its own lock manager and use
107
- // ./locks as the lock directory.
108
- var lockManager = new LockManager();
109
- lockManager.setLockDir(path.normalize("/another/accessible/location/for/lock/files");
110
- dynamicModuleLoader.setLockManager(lockManager);
108
+ // All configurations can also be changed aftewards by accessing the `settings` property
109
+ dynamicModuleLoader .settings .downloadDir = path .normalize (" /some/other/location" )
110
+ ```
111
111
112
112
Now that it's been configured we can download and run some packages. But not so fast big boy! Hold your horses! We need
113
113
a package first.
@@ -163,8 +163,7 @@ Changing Defaults
163
163
By default the _ DynamicModuleLoader_ assumes you will be downloading packages in _ tar.gz_ form. You can change the
164
164
default like this:
165
165
166
- var dynamicModuleLoader = new DynamicModuleLoader();
167
- dynamicModuleLoader.setDefaultRemoteServerPackageFileExtension('.zip');
166
+ var dynamicModuleLoader = new DynamicModuleLoader({ defaultRemoteServerPackageFileExtension: '.zip' });
168
167
169
168
// Will assume a .zip extension when requesting the package from the web server.
170
169
var moduleResult = dynamicModuleLoader.load('test-dynamic-module');
@@ -195,11 +194,11 @@ External Dependencies
195
194
196
195
_ DynamicModuleLoader_ depends on the existence of _ npm_ and _ unzip_ on the machine on which it is deployed. You can
197
196
specify the paths to these executables like this:
198
-
197
+ ``` javascript
199
198
var dynamicModuleLoader = new DynamicModuleLoader ();
200
- dynamicModuleLoader.setNpmExecutablePath( '/wherever/npm/is/installed') ;
201
- dynamicModuleLoader.setUnzipExecutablePath( '/wherever/unzip/ins/installed') ;
202
-
199
+ dynamicModuleLoader .settings . npmExecutablePath = ' /wherever/npm/is/installed' ;
200
+ dynamicModuleLoader .settings . unzipExecutablePath = ' /wherever/unzip/ins/installed' ;
201
+ ```
203
202
By default, _ DynamicModuleLoader_ assumes that _ npm_ and _ unzip_ paths are _ /usr/local/bin/npm_ and _ usr/bin/unzip_
204
203
respectively.
205
204
@@ -212,23 +211,22 @@ You can customize the NPM options. For example, you can set NPM to perform a ve
212
211
var dynamicModuleLoader = new DynamicModuleLoader({
213
212
npmOptions: ['--production', '--verbose']
214
213
});
215
- dynamicModuleLoader.setNpmInstallVerbose(true);
216
214
217
215
218
216
Skipping Installation
219
217
---------------------
220
218
221
219
You can configure the dynamic downloader such that it doesn't execute the 'npm install' phase. In this configuration,
222
220
the downloader assumes that modules have been pre-installed and that executing npm is not necessary. The loader still
223
- fires the same events in this configuration but you need not specify the location of NPM. Here's how to skip the
221
+ fires the same events in this configuration but you don't need to specify the location of NPM. Here's how to skip the
224
222
installation process:
225
-
226
- dynamicModuleLoader.setNpmSkipInstall( true) ;
227
-
223
+ ``` javascript
224
+ dynamicModuleLoader .settings . npmSkipInstall = true ;
225
+ ```
228
226
You can get the configuration settings like this:
229
-
230
- dynamicModuleLoader.getNpmSkipInstall() ;
231
-
227
+ ``` javascript
228
+ dynamicModuleLoader .settings . npmSkipInstall ;
229
+ ```
232
230
By default, NPM install is turned <b >on</b >, meaning that the "NPMSkipInstall" property is false.
233
231
234
232
Using pre-installed dependencies
@@ -383,6 +381,13 @@ This will permit you to use for example the same winston instance than your app
383
381
an other logger than winston. The only constrain is that the object you pass in paramater has the
384
382
` info() ` , ` debug() ` and ` error() ` functions defined.
385
383
384
+ The same logger can also be shared with the LockManager:
385
+ ``` javascript
386
+ var logger = require (' winston' );
387
+ var dmlConfig = { lockManager: new LockManager (undefined , winston) }
388
+ var dynamicModuleLoader = new DynamicModuleLoader (dmlConfig, winston);
389
+ ```
390
+
386
391
387
392
All Properties and Defaults
388
393
---------------------------
0 commit comments