Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add support for file globs

  • Loading branch information...
commit 59092d9869702bc8b28635a165327ddd1528b628 1 parent 4a97008
@jgallen23 authored
View
2  Makefile
@@ -1,4 +1,4 @@
test:
- ./node_modules/.bin/mocha --ui tdd
+ ./node_modules/.bin/mocha -G
.PHONY: test
View
9 lib/mash.js
@@ -9,6 +9,7 @@ var minify = require('./plugins/minify');
var hash = require('./plugins/hash');
var map = require('./map');
var defaults = require('./defaults');
+var files = require('./plugins/files');
module.exports = function(obj, callback) {
//override defaults
@@ -20,9 +21,13 @@ module.exports = function(obj, callback) {
});
res.series([
- //read files
+ //get files
function(next) {
- read(obj.files, next);
+ files(obj.files, next);
+ },
+ //read files
+ function(next, files) {
+ read(files, next);
},
//preprocess
function(next, files, type) {
View
29 lib/plugins/files.js
@@ -0,0 +1,29 @@
+var fs = require('fs');
+var path = require('path');
+var res = require('resistance');
+var glob = require('glob');
+
+var exists = fs.exists || path.exists;
+
+var files = function(arr, callback) {
+
+ var list = [];
+ var queue = res.queue(function(file, next) {
+
+ glob(file, function(err, f) {
+ list = list.concat(f)
+ next();
+ });
+
+
+ }, true);
+
+ queue.push(arr);
+ queue.run(function() {
+ callback(null, list);
+
+ });
+
+}
+
+module.exports = files;
View
14 package.json
@@ -8,14 +8,19 @@
"type": "git",
"url": "https://jgallen23@github.com/jgallen23/masher.git"
},
- "keywords": ["asset", "js", "css"],
+ "keywords": [
+ "asset",
+ "js",
+ "css"
+ ],
"dependencies": {
"aug": "0.0.5",
"js-yaml": "1.0.1",
"uglify-js": "1.3.2",
"uglifycss": "0.0.5",
"optimist": "0.3.4",
- "resistance": "2.0.0alpha1"
+ "resistance": "2.0.0alpha1",
+ "glob": "~3.1.13"
},
"devDependencies": {
"mocha": "*",
@@ -23,7 +28,8 @@
"nib": "*",
"less": "*"
},
- "bin": { "masher": "./bin/masher.js" },
+ "bin": {
+ "masher": "./bin/masher.js"
+ },
"main": "./lib/masher"
}
-
View
45 test/files.test.js
@@ -0,0 +1,45 @@
+var assert = require('assert');
+
+var files = require('../lib/plugins/files');
+
+var fixturePath = __dirname + '/fixtures/';
+
+suite('files', function() {
+
+ test('returns files', function(done) {
+
+ var file1 = fixturePath + 'a.js';
+ var file2 = fixturePath + 'b.js';
+ files([file1, file2], function(err, list) {
+
+ assert.equal(err, null);
+ assert.equal(list.length, 2);
+ assert.equal(list[0], file1);
+ assert.equal(list[1], file2);
+ done();
+ });
+
+ });
+
+ test('checks that file exists', function(done) {
+
+ var file1 = fixturePath + 'poop.js';
+ var file2 = fixturePath + 'b.js';
+ files([file1, file2], function(err, list) {
+
+ assert.notEqual(err, null);
+ console.log(err);
+ done();
+ });
+ });
+
+ test('expands glob', function(done) {
+
+ files([fixturePath + 'dir/*.js'], function(err, list) {
+
+ assert.equal(err, null);
+ assert.equal(list.length, 2);
+ done();
+ });
+ });
+});
View
1  test/fixtures/dir/a.js
@@ -0,0 +1 @@
+var testA = true;
View
1  test/fixtures/dir/b.js
@@ -0,0 +1 @@
+var testB = true;
View
1  test/mocha.opts
@@ -0,0 +1 @@
+--ui tdd -R list
View
45 test/read.test.js
@@ -0,0 +1,45 @@
+var assert = require('assert');
+var fs = require('fs');
+
+var read = require('../lib/plugins/read');
+var fixturePath = __dirname + '/fixtures/';
+
+var readFixture = function(name, ext) {
+ ext = ext || '.js';
+ return fs.readFileSync(fixturePath + name+ext, 'utf8');
+}
+
+suite('read', function() {
+
+ test('should read files passed in', function(done) {
+
+ var file1 = fixturePath + 'a.js';
+ var file2 = fixturePath + 'b.js';
+ read([file1, file2], function(err, out, assetType) {
+ assert.equal(err, null);
+ assert.equal(out.length, 2);
+
+ assert.equal(out[0].filename, file1);
+ assert.equal(out[0].source, readFixture('a'));
+ assert.equal(out[1].filename, file2);
+ assert.equal(out[1].source, readFixture('b'));
+
+ assert.equal(assetType, 'script');
+
+ done();
+ });
+
+ });
+
+ //test('should throw error if mixing asset types', function(done) {
+
+ //assert.throws(function() {
+ //var file1 = fixturePath + 'a.js';
+ //var file2 = fixturePath + 'stylea.css';
+ //read([file1, file2], function(err, out, assetType) {
+ //done();
+ //});
+ //});
+ //});
+
+});
Please sign in to comment.
Something went wrong with that request. Please try again.