Skip to content

Commit

Permalink
2.7 File object
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Dec 4, 2013
1 parent 47bc52e commit dcaa92b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# gulp changelog

## 2.7

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

## 2.4 - 2.6

- Moved stuff to gulp-util
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ This project is in its early stages. If something is not working or you would li
## Links

[Slideshow](http://slid.es/contra/gulp)
[Twitter for updates](http://twitter.com/eschoffs)
[Our company twitter](http://twitter.com/wearefractal)

[Twitter for updates](http://twitter.com/eschoff)

[Company twitter](http://twitter.com/wearefractal)

## Plugin List

Expand Down Expand Up @@ -94,7 +96,7 @@ gulp.task('default', function(){

### gulp.src(glob[, opt])

Takes a glob and represents a file structure. Can be piped to plugins.
Takes a glob and represents a file structure. Can be piped to plugins. You can specify a single glob or an array of globs (see docs)56. All options are passed directly through to [glob-stream](https://github.com/wearefractal/glob-stream). See the [glob-stream documentation](https://github.com/wearefractal/glob-stream) for more information.

```javascript
gulp.src("./client/templates/*.jade")
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Gulp.prototype.src = require('./lib/createInputStream');
Gulp.prototype.dest = require('./lib/createOutputStream');
Gulp.prototype.watch = require('./lib/watchFile');

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

Expand Down
16 changes: 16 additions & 0 deletions lib/File.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var realBase = require('gulp-util').realBase;

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

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

this.__defineGetter__("shortened", function(){
return realBase(this.base, this.path);
});
}

module.exports = File;
10 changes: 7 additions & 3 deletions lib/createInputStream.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
var es = require('event-stream');
var gs = require('glob-stream');
var formatFile = require('./formatFile');

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

module.exports = function(glob, opt) {
if (!opt) opt = {};
if (typeof opt.read !== 'boolean') opt.read = true;
if (typeof opt.buffer !== 'boolean') opt.buffer = true;

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

var stream = globStream.pipe(formatStream);

return stream.pipe(getContents(opt));
};
10 changes: 0 additions & 10 deletions lib/formatFile.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
return !!o.pipe;
return !!o && !!o.pipe;
};
2 changes: 1 addition & 1 deletion 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.6.1",
"version": "2.7.0",
"homepage": "http://github.com/wearefractal/gulp",
"repository": "git://github.com/wearefractal/gulp.git",
"author": "Fractal <[email protected]> (http://wearefractal.com/)",
Expand Down
24 changes: 11 additions & 13 deletions test/file-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,20 @@ describe('gulp streamFile', function() {
});
});

describe('gulp formatFile', function() {
describe('formatFile()', function() {
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);
gulp.formatFile({path:fname,base:base}, function(err, file) {
should.not.exist(err);
should.exist(file);
should.exist(file.shortened);
should.exist(file.path);
should.exist(file.base);
file.path.should.equal(fname);
file.base.should.equal(base);
file.shortened.should.equal("test.coffee");
done();
});
var file = new gulp.File(base, fname);
should.exist(file);
should.exist(file.shortened);
should.exist(file.path);
should.exist(file.base);
file.path.should.equal(fname);
file.base.should.equal(base);
file.shortened.should.equal("test.coffee");
done();
});
});
});

0 comments on commit dcaa92b

Please sign in to comment.