Skip to content

Instantly share code, notes, and snippets.

@ianstormtaylor
Last active January 3, 2016 04:38
Show Gist options
  • Save ianstormtaylor/8409952 to your computer and use it in GitHub Desktop.
Save ianstormtaylor/8409952 to your computer and use it in GitHub Desktop.
var shorthands = require('./shorthands');
/**
* Mixin shorthands.
*/
for (var key in shorthands) Builder.prototype[key] = shorthands[key];
/**
* Expose `exprts`.
*/
module.exports = exprts;
/**
* Exports plugin example.
*
* @param {String} type
*/
function exprts (type) {
return function (build, fn) {
setImmediate(fn);
build.each(type, function (file) {
if (!file.contents) return;
file.contents = 'module.exports = ' + file.contents;
});
});
};
var str2js = require('string-to-js');
/**
* Expose `string`.
*/
module.exports = string;
/**
* String plugin example.
*
* @param {String} type
*/
function string (type) {
return function (build, fn) {
setImmediate(fn);
build.each(type, function (file) {
if (!file.contents) return;
file.contents = str2js(file.contents);
});
});
}
var concat = require('./plugins/concat');
var copy = require('./plugins/copy');
var string = require('./plugins/string');
var exps = require('./plugins/exports');
/**
* Build scripts shorthand.
*
* @param {Function} fn
*/
exports.scripts = function (fn) {
this
.use(concat('scripts'))
.build(fn);
};
/**
* Build styles shorthand.
*
* @param {Function} fn
*/
exports.styles = function (fn) {
this
.use(concat('styles'))
.build(fn);
};
/**
* Build templates shorthand.
*
* @param {Function} fn
*/
exports.templates = function (fn) {
this
.use(string('templates'))
.use(concat('templates'))
.build(fn);
};
/**
* Build json shorthand.
*
* @param {Function} fn
*/
exports.json = function (fn) {
this
.use(exps('json'))
.use(concat('json'))
.build(fn);
};
/**
* Build images shorthand.
*
* @param {Function} fn
*/
exports.images = function (fn) {
this
.use(copy('images'))
.build(fn);
};
/**
* Build fonts shorthand.
*
* @param {Function} fn
*/
exports.fonts = function (fn) {
this
.use(copy('fonts'))
.build(fn);
};
@jonathanong
Copy link

i'm not totally sure about what's going on here, but why not something like:

builder.use('fonts', copy)
builder.use('scripts', concat)
builder.use('templates', string, concat)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment