Skip to content

Commit

Permalink
folder is correct now
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Jul 6, 2013
1 parent 3f9847d commit a265e35
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var minify = require('gulp-minify');

// compile, minify, and copy templates
gulp.task('templates', function(){
gulp.folder("./client/templates")
gulp.files("./client/templates/*.jade")
.pipe(jade())
.pipe(minify())
.pipe(gulp.folder("./public/templates"));
Expand All @@ -35,24 +35,24 @@ gulp.task('templates', function(){
gulp.task('scripts', function(){

// compile, minify, and copy coffeescript
gulp.folder("./client/js", {ignore: ["vendor"]})
gulp.files("./client/js/*.js", {ignore: ["vendor"]})
.pipe(coffee())
.pipe(minify())
.pipe(gulp.folder("./public/js"));

// copy vendor files
gulp.folder("./client/js/vendor")
gulp.files("./client/js/vendor/**")
.pipe(minify())
.pipe(gulp.folder("./public/js/vendor"));

});

// copy all static assets
gulp.task('copy', function(){
gulp.folder("./client/img")
gulp.files("./client/img/**")
.pipe(gulp.folder("./public/img"));

gulp.folder("./client/css")
gulp.files("./client/css/**")
.pipe(gulp.folder("./public/css"));

gulp.files("./client/*.html")
Expand All @@ -75,7 +75,7 @@ Takes a glob and represents an array of files with no structure. Can be piped to

### gulp.folder(path[, opt])

Takes a folder path and represents it's structure. Can be piped to and from.
Takes a folder path and represents it's structure. Can be piped to and it will write files. Re-emits all data passed to it so you can pipe to multiple folders.

### gulp.task(name, fn)

Expand Down
12 changes: 6 additions & 6 deletions lib/createFolderStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ module.exports = function(folder, opt) {

folder = path.resolve(folder);

function saveFile (file) {
function saveFile (file, cb) {
var writePath = path.join(folder, file.shortened);
var that = this;

mkdirp(folder, function(err){
if (err) return that.emit('error', err);
if (err) return cb(err);
fs.writeFile(writePath, file.contents, function(err){
if (err) return that.emit('error', err);
if (err) return cb(err);

// re-emit the same data we got in.
that.emit('data', file);
cb(null, file);
});
});
}
var stream = es.through(saveFile);
var stream = es.map(saveFile);
return stream;
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
"optimist":"0.6.0"
},
"devDependencies":{
"mocha":"1.12",
"should":"~1.2"
"mocha":"1.12.0",
"should":"1.2.2",
"rimraf":"2.2.0"
},
"scripts":{
"test":"mocha"
Expand Down
42 changes: 27 additions & 15 deletions test/folder.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
var gulp = require('../');
var should = require('should');
var join = require('path').join;
var rimraf = require('rimraf');
var fs = require('fs');

require('mocha');

describe('gulp file collection', function() {
describe('files()', function() {
describe('folder()', function() {
it('should return a stream', function(done) {
var stream = gulp.folder(join(__dirname, "./fixtures/"));
should.exist(stream);
should.exist(stream.on);
done();
});
it('should return a folder stream that writes files', function(done) {
var instream = gulp.files(join(__dirname, "./fixtures/*.coffee"));
var outstream = gulp.folder(join(__dirname, "./out-fixtures"));
instream.pipe(outstream);
var outpath = join(__dirname, "./out-fixtures");
rimraf(outpath, function(err){
should.not.exist(err);
var instream = gulp.files(join(__dirname, "./fixtures/*.coffee"));
var outstream = gulp.folder(outpath);
instream.pipe(outstream);

outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
file.path.should.equal(join(__dirname, "./fixtures/test.coffee"));
String(file.contents).should.equal("this is a test");
});
outstream.on('end', function() {
done();
outstream.on('error', done);
outstream.on('data', function(file) {
// data should be re-emitted right
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
file.path.should.equal(join(__dirname, "./fixtures/test.coffee"));
String(file.contents).should.equal("this is a test");
});
outstream.on('end', function() {
fs.readFile(join(outpath, "test.coffee"), function(err, contents){
should.not.exist(err);
should.exist(contents);
String(contents).should.equal("this is a test");
done();
});
});
});
});
});
Expand Down

0 comments on commit a265e35

Please sign in to comment.