Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Commit

Permalink
You can now fuse a file via the module.
Browse files Browse the repository at this point in the history
  • Loading branch information
smebberson committed Dec 9, 2013
1 parent 2f6191c commit 64ab7dc
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
24 changes: 23 additions & 1 deletion lib/index.js
Expand Up @@ -31,4 +31,26 @@ exports.fuseContent = function (content, relativePath, mode, callback) {

fuser.fuseContent(content, relativePath, mode);

}
};

exports.fuseFile = function (input, output, callback) {

// arguments: input, output, compress, mangle, lint
var fuser = fuse.fuse(input, output);

fuser.on('fuse', function (results) {
callback(null, results);
});

fuser.on('nofuse', function () {
callback(null, results);
});

fuser.on('error', function (err) {
callback(err);
});

// fuse the file, and the thrown events will take care of process exit
fuser.fuseFile();

};
51 changes: 51 additions & 0 deletions test/test.js
Expand Up @@ -227,6 +227,16 @@ describe('Using fuse', function () {

describe('with html', function () {

before(function (done){
// make the directory first to hold the result content
fs.mkdir(process.cwd() + '/test/html/result/', done);
});

after(function (done) {
// remove the result directory
fs.rmdir(process.cwd() + '/test/html/result/', done);
});

it('should fuse content', function (done) {

var fuse = require('../lib');
Expand All @@ -243,6 +253,47 @@ describe('Using fuse', function () {

});

describe('it should fuse two files', function () {

it('by <!-- @depends -->', function (done) {

// make the directory first to hold the result content
fs.mkdirSync(process.cwd() + '/test/html/result/depends/');

var fuse = require('../lib');

fuse.fuseFile(process.cwd() + '/test/html/src/depends/basic-depends.html', process.cwd() + '/test/html/result/depends/basic-depends-output.html', function (err, result) {

// check the output against the expected output
assert.equal(fs.readFileSync(process.cwd() + '/test/html/result/depends/basic-depends-output.html', 'utf-8'), fs.readFileSync(process.cwd() + '/test/html/expected/depends/basic-depends-result.html', 'utf-8'));

// delete the file
fs.unlinkSync(process.cwd() + '/test/html/result/depends/basic-depends-output.html');
fs.rmdirSync(process.cwd() + '/test/html/result/depends/');

// we're done
done();

});

// exec('node ' + fuse + ' -i ' + process.cwd() + '/test/html/src/depends/basic-depends.html -o ' + process.cwd() + '/test/html/result/depends/basic-depends-output.html', function (error, stdout, stderr) {

// // check the output against the expected output
// assert.equal(fs.readFileSync(process.cwd() + '/test/html/result/depends/basic-depends-output.html', 'utf-8'), fs.readFileSync(process.cwd() + '/test/html/expected/depends/basic-depends-result.html', 'utf-8'));

// // delete the file
// fs.unlinkSync(process.cwd() + '/test/html/result/depends/basic-depends-output.html');
// fs.rmdirSync(process.cwd() + '/test/html/result/depends/');

// // we're done
// done();

// });

});

});

});

});
Expand Down

0 comments on commit 64ab7dc

Please sign in to comment.