Skip to content

Commit

Permalink
add tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 1, 2016
1 parent 0c2b392 commit d11964f
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion updatefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,31 @@ module.exports = function(app) {
return updateExample(app, 'bar');
});

// register a "sub-updater"
app.task('baz', function() {
return updateExample(app, 'baz');
});

app.task('undo', function() {
var cwd = app.options.dest || app.cwd;
return app.src('example.txt', {cwd: cwd})
.pipe(erase(app.options.n))
.pipe(app.dest(cwd));
});

/**
* "Sub-updater"
*/

app.register('abc', function(abc) {
this.task('default', function() {
return updateExample(app, 'abc:default');
});

this.task('xyz', function() {
return updateExample(app, 'abc:xyz');
});
});

app.task('default', ['foo']);
};

Expand Down Expand Up @@ -57,3 +76,20 @@ function append(str) {
next(null, file);
});
}

/**
* Erase the given number of lines from the end of a string
*
* @param {String} `str`
* @return {Stream} vinyl stream
* @api public
*/

function erase(num) {
var n = typeof num === 'number' ? num : 1;
return through.obj(function(file, enc, next) {
var lines = file.contents.toString().trim().split('\n');
file.contents = new Buffer(lines.slice(0, -n).join('\n') + '\n');
next(null, file);
});
}

0 comments on commit d11964f

Please sign in to comment.