Skip to content

Instantly share code, notes, and snippets.

@mndvns
Created January 11, 2014 03:15
Show Gist options
  • Save mndvns/8366527 to your computer and use it in GitHub Desktop.
Save mndvns/8366527 to your computer and use it in GitHub Desktop.
Shoelace build
/*
* Module dependencies.
*/
var rework = require('rework');
var mixins = require('rework-mixins');
var calc = require('rework-calc');
var breakpoints = require('rework-breakpoints');
var modules = require('rework-modules');
var myth = require('myth');
var fs = require('fs');
var path = require('path');
var read = fs.readFileSync;
module.exports = function(builder) {
var sl = new Shoelace(builder);
var buildType = builder.buildType;
builder.buildType = function(type, fn, process) {
if (type !== 'styles') return buildType.apply(builder, arguments);
buildType.call(builder, type, function() {
sl.build(fn);
}, process);
};
builder.hook('before styles', function(pkg) {
sl.load(pkg);
});
};
function Shoelace(builder) {
this.builder = builder;
this.modules = {};
}
Shoelace.prototype.load = function(pkg) {
var styles = pkg.config.styles;
if (!styles) return;
if (pkg.root) this.root = pkg.config.repo || pkg.config.name;
var mod = this.modules[pkg.config.repo || pkg.config.name] = {};
styles.forEach(function(file) {
if (!mod._main) mod._main = get;
var cache;
mod[file] = get;
function get() {
if (cache) return cache;
cache = read(pkg.path(file), 'utf8');
return cache;
};
});
pkg.config.styles = [];
};
Shoelace.prototype.build = function(fn) {
if (!this.root) {
console.error('No root style file found');
return fn(null, '');
}
var out = modules(this.modules, this.root)
.use(rework.extend())
.use(rework.colors())
.use(rework.references())
.use(rework.mixins(mixins))
.use(breakpoints)
.use(myth)
.use(calc);
fn(null, out.toString());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment