node-module-concat
Advanced tools
Comparing version 1.0.2 to 1.1.0
43
index.js
@@ -66,4 +66,33 @@ /* node-module-concat | ||
`__getDirname(...)` and `__getFilename(...)` references. | ||
`modConcat(entryModule, outputFile, [options,] cb)` | ||
- `entryModule` - the path to the entry point of the project to be | ||
concatenated. This might be an `index.js` file, for example. | ||
- `outputFile` - the path where the concatenated project file will be | ||
written. | ||
- `options` - Optional. An Object containing any of the following: | ||
- `outputStreamOptions` - Options passed to `fs.createWriteStream` call | ||
when the `outputFile` is opened for writing. Defaults to `null`. | ||
- `excludeFiles` - An Array of files that should be excluded from the | ||
project even if they were referenced by a `require(...)`. | ||
Note: These `require` statements should probably be wrapped in a | ||
try, catch block to prevent uncaught exceptions. | ||
- `cb` - Callback of the form `cb(err, files)` where `files` is an Array | ||
of files that have been included in the project. | ||
*/ | ||
module.exports = function concat(entryModule, outputFile, cb) { | ||
module.exports = function concat(entryModule, outputFile, opts, cb) { | ||
// Reorganize arguments | ||
if(typeof opts === "function") { | ||
cb = opts; | ||
opts = {}; | ||
} | ||
opts = opts || {}; | ||
// Ensure that all paths have been resolved | ||
if(opts.excludeFiles) { | ||
for(var i = 0; i < opts.excludeFiles.length; i++) { | ||
opts.excludeFiles[i] = path.resolve(opts.excludeFiles[i]); | ||
} | ||
} | ||
// A list of all of the files read and included in the output thus far | ||
@@ -77,3 +106,3 @@ var files = []; | ||
// Open WriteStream | ||
var out = fs.createWriteStream(outputFile); | ||
var out = fs.createWriteStream(outputFile, opts.outputStreamOptions); | ||
out.on("open", function(_fd) { | ||
@@ -138,3 +167,11 @@ // Save the file descriptor | ||
// Not found; add this module to the project | ||
index = files.push(modulePath) - 1; | ||
if(!opts.excludeFiles || | ||
opts.excludeFiles.indexOf(modulePath) < 0) | ||
{ | ||
index = files.push(modulePath) - 1; | ||
} | ||
else { | ||
// Ignore; do not replace | ||
return match; | ||
} | ||
} | ||
@@ -141,0 +178,0 @@ // Replace the `require` statement with `__require` |
{ | ||
"name": "node-module-concat", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Node.js module concatenation library", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -11,4 +11,5 @@ # node-module-concat | ||
## Install | ||
npm install node-module-concat | ||
`npm install node-module-concat` | ||
## Usage | ||
@@ -25,2 +26,23 @@ | ||
## API | ||
`var modConcat = require("node-module-concat");` | ||
**`modConcat(entryModule, outputFile, [options,] cb)`** | ||
- `entryModule` - the path to the entry point of the project to be | ||
concatenated. This might be an `index.js` file, for example. | ||
- `outputFile` - the path where the concatenated project file will be | ||
written. | ||
- `options` - Optional. An Object containing any of the following: | ||
- `outputStreamOptions` - Options passed to `fs.createWriteStream` call | ||
when the `outputFile` is opened for writing. | ||
- `excludeFiles` - An Array of files that should be excluded from the | ||
project even if they were referenced by a `require(...)`. | ||
Note: These `require` statements should probably be wrapped in a | ||
try, catch block to prevent uncaught exceptions. | ||
- `cb` - Callback of the form `cb(err, files)` where `files` is an Array | ||
of files that have been included in the project. | ||
## Known limitations | ||
@@ -27,0 +49,0 @@ - Dynamic `require()` statements don't work |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17293
361
51