Comparing version 0.1.1 to 0.2.0
@@ -7,7 +7,8 @@ 'use strict'; | ||
var path = require('path'); | ||
var when = require('when'); | ||
var fs = require('fs'); | ||
var mm = require('micromatch'); | ||
var nodefn = require('when/node'); | ||
var when = require('when'); | ||
var rimraf = nodefn.lift(require('rimraf')); | ||
var mkdirp = nodefn.lift(require('mkdirp')); | ||
var fs = require('fs'); | ||
var fsp = nodefn.liftAll(require('fs')); | ||
@@ -17,6 +18,8 @@ var filesCopied = 0; | ||
module.exports = function(inputDir, outputDir, options) { | ||
options = options || {}; | ||
var compileAndCopy = function() { | ||
return when.promise(function(resolve, reject) { | ||
var stream = readdirp({ root: inputDir, options: options }); | ||
options.root = inputDir; | ||
var stream = readdirp(options); | ||
@@ -68,3 +71,5 @@ stream.pipe(through.obj(function (file, _, next) { | ||
if (!!compileExt) { | ||
var doCompile = !mm(file.path, options.compileBlacklist).length; | ||
if (!!compileExt && doCompile) { | ||
compile(); | ||
@@ -75,2 +80,3 @@ } else { | ||
}; | ||
var dir = path.join(outputDir, file.path.replace(file.name, '')); | ||
@@ -77,0 +83,0 @@ mkdirp(dir).then(processFile, reject); |
{ | ||
"name": "baconize", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Compile static site for production (with sourcemaps), auto-compiles files like `app.coffee -> app.js`", | ||
@@ -32,2 +32,3 @@ "main": "lib/index.js", | ||
"baby-tolk": "^1.1.0", | ||
"micromatch": "^2.2.0", | ||
"mkdirp": "^0.5.1", | ||
@@ -34,0 +35,0 @@ "readdirp": "^2.0.0", |
@@ -19,3 +19,3 @@ Baconize | ||
var target = '/path/to/output/dir'; | ||
baconize(source, target).then([successFn],[errorFn]); | ||
baconize(source, target, [options]).then([successFn],[errorFn]); | ||
``` | ||
@@ -30,5 +30,32 @@ | ||
This library is designed for use alongside [pingy-in-the-middle](https://github.com/davej/piggy-in-the-middle). | ||
Options | ||
------- | ||
- **compileBlacklist**: filter to blacklist files from being compiled. They will still be copied (without compilation) unless they are negated using the `fileFilter` or `directoryFilter Options below`. This option is useful for vendor directories (like 'bower_components') which already include the compiled versions of files. See [Filters](#filters) for more. | ||
- **fileFilter**: filter to include/exclude files to be copied to target. See [Filters](#filters) for more. | ||
- **directoryFilter**: filter to include/exclude directories to be copied to target, rules are applied to sub-directories also. See [Filters](#filters) for more. | ||
- **depth**: depth at which to stop recursing even if more subdirectories are found. | ||
Filters | ||
------- | ||
Filters take an array of glob strings: | ||
* `compileBlacklist: [ 'bower_components/**' ]` includes bower_components directory but copies the raw directory instead of compiling files within the directory. | ||
* `fileFilter: [ '*.json', '*.js' ]` includes all JavaScript and Json files. | ||
* `directoryFilter: [ '!.git', '!node_modules' ]` includes all directories except the '.git' and 'node_modules'. | ||
See [minimatch](https://github.com/isaacs/minimatch) for some examples of glob strings. | ||
Try it out | ||
@@ -35,0 +62,0 @@ ---------- |
@@ -27,3 +27,7 @@ 'use strict'; | ||
it('should compile compilable files and copy all others', function () { | ||
return expect(baconize(getPathIn(), getPathOut()), 'to be fulfilled with', 4); | ||
var options = { | ||
compileBlacklist: ['dont-compile/**'], | ||
directoryFilter: ['!dont-copy'] | ||
}; | ||
return expect(baconize(getPathIn(), getPathOut(), options), 'to be fulfilled with', 5); | ||
}); | ||
@@ -38,3 +42,4 @@ | ||
fs.readFile(getPathOut('scripts/main.js')), | ||
fs.readFile(getPathOut('about.html')) | ||
fs.readFile(getPathOut('about.html')), | ||
fs.readFile(getPathOut('dont-compile/foo.coffee')) | ||
]).then(function(results) { | ||
@@ -45,3 +50,4 @@ return expect.promise.all([ | ||
expect(results[2].toString(), 'to contain', 'console.log("H'), | ||
expect(results[3].toString(), 'to contain', '<title>Some') | ||
expect(results[3].toString(), 'to contain', '<title>Some'), | ||
expect(results[4].toString(), 'to contain', 'console.log "T') | ||
]); | ||
@@ -80,3 +86,3 @@ }); | ||
.then(function() { | ||
return expect.fail('index.jade should not have been copied'); | ||
return expect.fail('`index.jade` should not be copied'); | ||
}, function(err) { | ||
@@ -87,4 +93,22 @@ return expect(err.code, 'to be', 'ENOENT'); | ||
it('should not compile blacklist matches', function() { | ||
return fs.readFile(getPathOut('dont-compile/foo.js')) | ||
.then(function() { | ||
return expect.fail('`dont-compile/foo.js` should not be copied'); | ||
}, function(err) { | ||
return expect(err.code, 'to be', 'ENOENT'); | ||
}); | ||
}); | ||
it('should not copy ignore paths', function() { | ||
return fs.stat(getPathOut('dont-copy')) | ||
.then(function() { | ||
return expect.fail('`dont-copy` directory should not be copied'); | ||
}, function(err) { | ||
return expect(err.code, 'to be', 'ENOENT'); | ||
}); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
17861
15
185
69
7
+ Addedmicromatch@^2.2.0
+ Addedarr-diff@2.0.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)