From 2d92c59afc0a4d353ce9ac66b375e003f56ca211 Mon Sep 17 00:00:00 2001 From: Cevs Brazuka Date: Sun, 14 Oct 2012 10:38:16 -0500 Subject: [PATCH 1/4] Added compileStyl() & compileCoffee() to compile Stylus or CoffeeScript files. --- README.md | 7 +++++++ index.js | 28 ++++++++++++++++++++++++++++ package.json | 4 +++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b525b7..9c2d373 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,13 @@ 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. + ###save(file) Save the contents to a file. diff --git a/index.js b/index.js index f55e4dd..eb092e2 100644 --- a/index.js +++ b/index.js @@ -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'); @@ -196,6 +198,32 @@ 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; +}; + /** * Save the contents to disk * diff --git a/package.json b/package.json index 0f03cc9..6eaad8b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Charles Davison ", "name": "buildify", "description": "Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.", - "version": "0.3.0", + "version": "0.4.0", "repository": { "type": "git", "url": "git://github.com/powmedia/buildify.git" @@ -12,6 +12,8 @@ "mkdirp": "0.3.2", "uglify-js": "1.3.0", "underscore": "1.3.3", + "stylus": ">= 0.0.1", + "coffee-script": "1.3.3", "clean-css": "0.6.0" }, "devDependencies": { From d1b22064b05d82bb7f0148055bd06f327c7874d4 Mon Sep 17 00:00:00 2001 From: Cevs Brazuka Date: Sun, 14 Oct 2012 14:29:21 -0500 Subject: [PATCH 2/4] Added tests compileStyl, compileCoffee --- test/index.test.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/index.test.js b/test/index.test.js index 804942d..2b380e3 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -236,6 +236,29 @@ 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['save'] = { setUp: function(done) { this.sinon = sinon.sandbox.create(); From 8fed44ad3490971ef769d233fded48052e1cd1e4 Mon Sep 17 00:00:00 2001 From: Cevs Brazuka Date: Tue, 20 Nov 2012 03:54:04 -0500 Subject: [PATCH 3/4] loadRegex() --- README.md | 10 ++++++++++ index.js | 18 ++++++++++++++++++ package.json | 3 ++- test/index.test.js | 12 ++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9c2d373..06c780a 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,12 @@ Compile a Stylus file. ###compileCoffee() Compile a CoffeeScript file. + +###loadRegex() +Concatenate the content of multiple files that match the "regex" criteria. +Recursive (Looks up inside directories) + + ###save(file) Save the contents to a file. @@ -131,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) diff --git a/index.js b/index.js index eb092e2..aeb1f9f 100644 --- a/index.js +++ b/index.js @@ -224,6 +224,24 @@ Builder.prototype.compileCoffee = function() { 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", "name": "buildify", "description": "Builder for creating distributable JavaScript files from source. Concatenate, wrap, uglify.", - "version": "0.4.0", + "version": "0.4.2", "repository": { "type": "git", "url": "git://github.com/powmedia/buildify.git" @@ -14,6 +14,7 @@ "underscore": "1.3.3", "stylus": ">= 0.0.1", "coffee-script": "1.3.3", + "wrench": "~1.4.3", "clean-css": "0.6.0" }, "devDependencies": { diff --git a/test/index.test.js b/test/index.test.js index 2b380e3..3a5a36f 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -259,6 +259,18 @@ exports['compileCoffee'] = function(test) { 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(); From b8b93dc150af449a6187ea4dfb1694374a73989c Mon Sep 17 00:00:00 2001 From: Cevs Brazuka Date: Tue, 20 Nov 2012 03:57:45 -0500 Subject: [PATCH 4/4] README: loadRegex() --- README.md | 2 +- index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 06c780a..4e28634 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Compile a Stylus file. Compile a CoffeeScript file. -###loadRegex() +###loadRegex(regex) Concatenate the content of multiple files that match the "regex" criteria. Recursive (Looks up inside directories) diff --git a/index.js b/index.js index aeb1f9f..432a60e 100644 --- a/index.js +++ b/index.js @@ -226,8 +226,8 @@ Builder.prototype.compileCoffee = function() { /** * Load files regex + * * @param regex - * */ Builder.prototype.loadRegex = function(regex) { var walker = require('wrench');