Skip to content

Commit

Permalink
Symlink files without transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeche committed Jun 29, 2015
1 parent b0cbe27 commit 2a16ebf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ module.exports.rewriteUrl = function(config) {
};

/**
* Creates a transformation stream marking all files in current project to be
* symlinked instead of copied
* Creates a transformation stream marking all files in current project that
* has no transformations to be symlinked instead of copied
* @return {SymlinkStream}
*/
module.exports.symlink = function() {
Expand Down
20 changes: 15 additions & 5 deletions lib/stream/symlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@
var stream = require('stream');
var util = require('util');

var objMode = {objectMode: true};

var SymlinkStream = module.exports = function() {
stream.Transform.call(this, {objectMode: true});
stream.Transform.call(this, objMode);
};

util.inherits(SymlinkStream, stream.Transform);

SymlinkStream.prototype._transform = function(project, enc, next) {
project.addTransform('**/*.*', new FileSymlinkStream());
project.addTransform('**/*.*', streamFactory, project);
next(null, project);
};

function FileSymlinkStream() {
stream.Transform.call(this, {objectMode: true});
function streamFactory(project) {
return new FileSymlinkStream(project);
}

function FileSymlinkStream(project) {
stream.Transform.call(this, objMode);
this.project = project;
}
util.inherits(FileSymlinkStream, stream.Transform);

FileSymlinkStream.prototype._transform = function(file, enc, next) {
file.symlink = true;
var transforms = this.project.matchedTransforms(file.path);
// if the only matched transform for current file is current one —
// mark file as symlink
file.symlink = transforms.length === 1 && transforms[0].factory === streamFactory;
next(null, file);
};
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ imp.src('./test/in/')
});
next(null, project);
}))
// .pipe(imp.symlink())
.pipe(imp.symlink())
.pipe(imp.dest('./out'))
.on('end', function() {
console.log('Finished project import');
Expand Down

0 comments on commit 2a16ebf

Please sign in to comment.