Skip to content

Commit

Permalink
3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Dec 7, 2013
1 parent dcaa92b commit 633c88a
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 66 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# gulp changelog

## 3.0

- Ability to pass multiple globs and glob negations to glob-stream
- Breaking change to the way glob-stream works
- File object is now a class
- file.shortened changed to file.relative
- file.cwd added
- Break out getStats to avoid nesting
- Major code reorganization

## 2.7

- Breaking change to the way options are passed to glob-stream
- Introduce new File object to ease pain of computing shortened names
- Introduce new File object to ease pain of computing shortened names (now a getter)

## 2.4 - 2.6

Expand Down
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ Gulp.prototype.run = function(){

Gulp.prototype.src = require('./lib/createInputStream');
Gulp.prototype.dest = require('./lib/createOutputStream');
Gulp.prototype.watch = require('./lib/watchFile');
Gulp.prototype.watch = require('./lib/watch');

Gulp.prototype.File = require("./lib/File");
Gulp.prototype.bufferFile = require('./lib/bufferFile');
Gulp.prototype.streamFile = require('./lib/streamFile');

var gulp = new Gulp();
gulp.Gulp = Gulp;
Expand Down
11 changes: 6 additions & 5 deletions lib/File.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
var realBase = require('gulp-util').realBase;

function File(base, path) {
this.base = base;
this.path = path;
function File(file) {
this.cwd = file.cwd;
this.base = file.base;
this.path = file.path;

// other fields are
// stats = fs stats object
// stat = fs stats object
// contents = stream, buffer, or null if not read

this.__defineGetter__("shortened", function(){
this.__defineGetter__("relative", function(){
return realBase(this.base, this.path);
});
}
Expand Down
File renamed without changes.
28 changes: 28 additions & 0 deletions lib/createInputStream/getContents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var es = require('event-stream');
var fs = require('fs');

var readDir = require('./readDir');
var bufferFile = require('./bufferFile');
var streamFile = require('./streamFile');

module.exports = function(opt) {
return es.map(function (file, cb) {
// don't read anything - just pass names
if (!opt.read) {
return cb(null, file);
}

// don't fail to read a directory
if (file.stat.isDirectory()) {
return readDir(file, cb);
}

// read and pass full contents
if (opt.buffer) {
return bufferFile(file, cb);
}

// dont buffer anything - just pass streams
return streamFile(file, cb);
});
};
12 changes: 12 additions & 0 deletions lib/createInputStream/getStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var es = require('event-stream');
var fs = require('fs');

module.exports = function(opt) {
return es.map(function (file, cb) {
fs.stat(file.path, function (err, stat) {
if (err) return cb(err);
file.stat = stat;
cb(null, file);
});
});
};
9 changes: 6 additions & 3 deletions lib/createInputStream.js → lib/createInputStream/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
var es = require('event-stream');
var gs = require('glob-stream');

var File = require('./File');
var File = require('../File');
var getContents = require('./getContents');
var getStats = require('./getStats');

module.exports = function(glob, opt) {
if (!opt) opt = {};
Expand All @@ -11,10 +12,12 @@ module.exports = function(glob, opt) {

var globStream = gs.create(glob, opt);
var formatStream = es.map(function(file, cb){
cb(null, new File(file.base, file.path));
cb(null, new File(file));
});

var stream = globStream.pipe(formatStream);

return stream.pipe(getContents(opt));
return stream
.pipe(getStats(opt))
.pipe(getContents(opt));
};
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(folder, opt) {
folder = path.resolve(folder);

function saveFile (file, cb) {
var writePath = path.join(folder, file.shortened);
var writePath = path.join(folder, file.relative);
var writeFolder = path.dirname(writePath);

mkdirp(writeFolder, function(err){
Expand Down
1 change: 0 additions & 1 deletion lib/writeDir.js → lib/createOutputStream/writeDir.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var mkdirp = require('mkdirp');
var isStream = require('./isStream');

module.exports = function (writePath, file, cb) {
// create directory
Expand Down
2 changes: 1 addition & 1 deletion lib/writeFile.js → lib/createOutputStream/writeFile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var fs = require('fs');
var isStream = require('./isStream');
var semver = require('semver');
var isStream = require('../isStream');

module.exports = function (writePath, file, cb) {
// if no contents then do nothing
Expand Down
33 changes: 0 additions & 33 deletions lib/getContents.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/isStream.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(o) {
// really shitty for now
// really shitty
return !!o && !!o.pipe;
};
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gulp",
"description": "The streaming build system",
"version": "2.7.0",
"version": "3.0.0",
"homepage": "http://github.com/wearefractal/gulp",
"repository": "git://github.com/wearefractal/gulp.git",
"author": "Fractal <[email protected]> (http://wearefractal.com/)",
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {
"event-stream": "~3.0.16",
"glob-stream": "~0.1.0",
"glob-stream": "~3.0.0",
"mkdirp": "~0.3.5",
"optimist": "~0.6.0",
"gulp-util": "~1.1.1",
Expand Down
75 changes: 60 additions & 15 deletions test/file-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,28 @@ var dirname = path.dirname;
var semver = require('semver');
require('mocha');

var bufferFile = require('../lib/createInputStream/bufferFile');
var streamFile = require('../lib/createInputStream/streamFile');

describe('gulp bufferFile', function() {
describe('bufferFile()', function() {
it('should return a valid file', function(done) {
var fname = join(__dirname, "./fixtures/test.coffee");
var base = dirname(fname);
gulp.bufferFile({path:fname,base:base}, function(err, file) {
var base = join(__dirname, "./fixtures/");
var file = new gulp.File({
base: base,
cwd: __dirname,
path: fname
});
bufferFile(file, function(err, file) {
should.not.exist(err);
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
should.exist(file.base);
should.exist(file.cwd);
should.exist(file.contents, 'contents');
file.cwd.should.equal(__dirname);
file.path.should.equal(fname);
file.base.should.equal(base);
String(file.contents).should.equal("this is a test");
Expand All @@ -30,13 +41,21 @@ describe('gulp streamFile', function() {
describe('streamFile()', function() {
it('should return a valid file', function(done) {
var fname = join(__dirname, "./fixtures/test.coffee");
var base = dirname(fname);
gulp.streamFile({path:fname,base:base}, function(err, file) {
var base = join(__dirname, "./fixtures/");
var file = new gulp.File({
base: base,
cwd: __dirname,
path: fname
});
streamFile(file, function(err, file) {
should.not.exist(err);
should.exist(file);
should.exist(file.path);
should.exist(file.contents);
should.exist(file.base);
should.exist(file, 'root');
should.exist(file.relative, 'relative');
should.exist(file.path, 'path');
should.exist(file.cwd, 'cwd');
should.exist(file.base, 'base');
should.exist(file.contents, 'contents');
file.cwd.should.equal(__dirname);
file.path.should.equal(fname);
file.base.should.equal(base);

Expand All @@ -61,15 +80,41 @@ describe('gulp File class', function() {
describe('File()', function() {
it('should return a valid file', function(done) {
var fname = join(__dirname, "./fixtures/test.coffee");
var base = dirname(fname);
var file = new gulp.File(base, fname);
should.exist(file);
should.exist(file.shortened);
should.exist(file.path);
should.exist(file.base);
var base = join(__dirname, "./fixtures/");
var file = new gulp.File({
base: base,
cwd: __dirname,
path: fname
});
should.exist(file, 'root');
should.exist(file.relative, 'relative');
should.exist(file.path, 'path');
should.exist(file.cwd, 'cwd');
should.exist(file.base, 'base');
file.path.should.equal(fname);
file.cwd.should.equal(__dirname);
file.base.should.equal(base);
file.relative.should.equal("test.coffee");
done();
});

it('should return a valid file 2', function(done) {
var fname = join(__dirname, "./fixtures/test.coffee");
var base = __dirname;
var file = new gulp.File({
base: base,
cwd: __dirname,
path: fname
});
should.exist(file, 'root');
should.exist(file.relative, 'relative');
should.exist(file.path, 'path');
should.exist(file.cwd, 'cwd');
should.exist(file.base, 'base');
file.path.should.equal(fname);
file.cwd.should.equal(__dirname);
file.base.should.equal(base);
file.shortened.should.equal("test.coffee");
file.relative.should.equal("fixtures/test.coffee");
done();
});
});
Expand Down

0 comments on commit 633c88a

Please sign in to comment.