Skip to content

Commit ce7e79e

Browse files
author
Sylvain Bellone
committed
Updated README to address issue #15
1 parent d18c2e8 commit ce7e79e

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

README.md

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,30 @@ How To Use
8484
----------
8585

8686
OK, enough blabbing. Here's how you create and configure a DynamicModuleLoader:
87-
87+
```javascript
8888
// Require all of the needful.
8989
var LockManager = require('hurt-locker').LockManager;
9090
var DynamicModuleLoader = require('dynamic-module-loader').DynamicModuleLoader;
9191

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+
}
92105
// 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);
102107

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+
```
111111

112112
Now that it's been configured we can download and run some packages. But not so fast big boy! Hold your horses! We need
113113
a package first.
@@ -163,8 +163,7 @@ Changing Defaults
163163
By default the _DynamicModuleLoader_ assumes you will be downloading packages in _tar.gz_ form. You can change the
164164
default like this:
165165

166-
var dynamicModuleLoader = new DynamicModuleLoader();
167-
dynamicModuleLoader.setDefaultRemoteServerPackageFileExtension('.zip');
166+
var dynamicModuleLoader = new DynamicModuleLoader({ defaultRemoteServerPackageFileExtension: '.zip' });
168167

169168
// Will assume a .zip extension when requesting the package from the web server.
170169
var moduleResult = dynamicModuleLoader.load('test-dynamic-module');
@@ -195,11 +194,11 @@ External Dependencies
195194

196195
_DynamicModuleLoader_ depends on the existence of _npm_ and _unzip_ on the machine on which it is deployed. You can
197196
specify the paths to these executables like this:
198-
197+
```javascript
199198
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+
```
203202
By default, _DynamicModuleLoader_ assumes that _npm_ and _unzip_ paths are _/usr/local/bin/npm_ and _usr/bin/unzip_
204203
respectively.
205204

@@ -212,23 +211,22 @@ You can customize the NPM options. For example, you can set NPM to perform a ve
212211
var dynamicModuleLoader = new DynamicModuleLoader({
213212
npmOptions: ['--production', '--verbose']
214213
});
215-
dynamicModuleLoader.setNpmInstallVerbose(true);
216214

217215

218216
Skipping Installation
219217
---------------------
220218

221219
You can configure the dynamic downloader such that it doesn't execute the 'npm install' phase. In this configuration,
222220
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
224222
installation process:
225-
226-
dynamicModuleLoader.setNpmSkipInstall(true);
227-
223+
```javascript
224+
dynamicModuleLoader.settings.npmSkipInstall = true;
225+
```
228226
You can get the configuration settings like this:
229-
230-
dynamicModuleLoader.getNpmSkipInstall();
231-
227+
```javascript
228+
dynamicModuleLoader.settings.npmSkipInstall;
229+
```
232230
By default, NPM install is turned <b>on</b>, meaning that the "NPMSkipInstall" property is false.
233231

234232
Using pre-installed dependencies
@@ -383,6 +381,13 @@ This will permit you to use for example the same winston instance than your app
383381
an other logger than winston. The only constrain is that the object you pass in paramater has the
384382
`info()`, `debug()` and `error()` functions defined.
385383

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+
386391

387392
All Properties and Defaults
388393
---------------------------

0 commit comments

Comments
 (0)