Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ Minimise your CSS using clean-css.
Optionally a line break is inserted after 'maxLineLength' characters in the minimized css file.


###compileStyl()
Compile a Stylus file.


###compileCoffee()
Compile a CoffeeScript file.


###loadRegex(regex)
Concatenate the content of multiple files that match the "regex" criteria.
Recursive (Looks up inside directories)


###save(file)
Save the contents to a file.

Expand All @@ -124,6 +137,10 @@ Reset/clear contents.


##Changelog
0.4.2
Add compileStyl() and compileCoffee() for Stylus and CoffeeScript
Add loadRegex() pseudo regex for concatenate files matching criteria

0.3.0
Add cssmin() for minifying CSS (RustyMarvin)
Fix tests under Windows (RustyMarvin)
Expand Down
46 changes: 46 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var fs = require('fs'),
mkdirp = require('mkdirp'),
_ = require('underscore'),
uglifyJS = require('uglify-js'),
stylus = require('stylus'),
coffeeScript = require('coffee-script'),
cleanCSS = require('clean-css');


Expand Down Expand Up @@ -196,6 +198,50 @@ Builder.prototype.cssmin = function(maxLineLength) {
return this;
};

/**
* Compile styl files
*/
Builder.prototype.compileStyl = function() {
var content = this.content;
stylus(content).set('compress', true).render(function(err, css){
content = css;
});

this.content = content;

return this;
};

/**
* Compile Coffee files
*/
Builder.prototype.compileCoffee = function() {
var content = this.content;
content = coffeeScript.compile(content, {bare:true});

this.content = content;

return this;
};

/**
* Load files regex
*
* @param regex
*/
Builder.prototype.loadRegex = function(regex) {
var walker = require('wrench');
var files = [];
var contents = [];

files = walker.readdirSyncRecursive(this.dir);
for (var i=0,len=files.length;i<len;i++) {
if (files[i].match(regex))
contents.push(files[i]);
}
this.concat(contents);
};

/**
* Save the contents to disk
*
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "Charles Davison <charlie@powmedia.co.uk>",
"name": "buildify",
"description": "Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.",
"version": "0.3.0",
"version": "0.4.2",
"repository": {
"type": "git",
"url": "git://github.com/powmedia/buildify.git"
Expand All @@ -12,6 +12,9 @@
"mkdirp": "0.3.2",
"uglify-js": "1.3.0",
"underscore": "1.3.3",
"stylus": ">= 0.0.1",
"coffee-script": "1.3.3",
"wrench": "~1.4.3",
"clean-css": "0.6.0"
},
"devDependencies": {
Expand Down
35 changes: 35 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,41 @@ exports['cssmin'] = {
};


exports['compileStyl'] = function(test) {
var b = builder();

b.setContent('body\n \t font 12px Helvetica, Arial, sans-serif\n \na.button\n \t border-radius 5px');
b.compileStyl();

test.same(b.content, 'body{font:12px Helvetica,Arial,sans-serif}\na.button{border-radius:5px}\n');

test.done();
}


exports['compileCoffee'] = function(test) {
var b = builder();

b.setContent('play() while life is on');
b.compileCoffee();

test.same(b.content, '\nwhile (life === true) {\n play();\n}\n');

test.done();
}


exports['loadRegex'] = function(test) {
var b = builder(__dirname + '/support');

b.loadRegex("^[a-z]{3}.txt");

test.same(b.content, 'BAR\nFOO');

test.done();
}


exports['save'] = {
setUp: function(done) {
this.sinon = sinon.sandbox.create();
Expand Down