Skip to content

Commit

Permalink
references #378, references #316, yay tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
dbashford committed Jan 26, 2015
1 parent 95b5b33 commit 3a0aaeb
Show file tree
Hide file tree
Showing 37 changed files with 412 additions and 42 deletions.
94 changes: 52 additions & 42 deletions lib/modules/file/write.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,56 @@
"use strict";
var _write,
__slice = [].slice;

_write = function(config, options, next) {
var done, fileUtils, hasFiles, i, _ref;
fileUtils = require('../../util/file');
hasFiles = ((_ref = options.files) != null ? _ref.length : void 0) > 0;
if (!hasFiles) {
return next();
}
i = 0;
done = function() {
if (++i === options.files.length) {
return next();
}
};
return options.files.forEach(function(file) {
if ((file.outputFileText !== "" && !file.outputFileText) || !file.outputFileName) {
return done();
}
if (file.outputFileText === "") {
config.log.warn("Compile of file [[ " + file.inputFileName + " ]] resulted in empty output.");
}
if (config.log.isDebug()) {
config.log.debug("Writing file [[ " + file.outputFileName + " ]]");
}
return fileUtils.writeFile(file.outputFileName, file.outputFileText, function(err) {
if (err != null) {
config.log.error("Failed to write new file [[ " + file.outputFileName + " ]], Error: " + err, {
exitIfBuild: true
});
} else {
config.log.success("Wrote file [[ " + file.outputFileName + " ]]", options);

var _write = function( config, options, next ) {
if ( options.files && options.files.length ) {

var processed = 0;
var done = function() {
if ( ++processed === options.files.length ) {
next();
}
return done();
});
});
};
};

var fileUtils = require( "../../util/file" );
for ( var i = 0; i < options.files.length; i++ ) {
var file = options.files[i];

exports.registration = function(config, register) {
var e;
e = config.extensions;
register(['add', 'update', 'remove', 'buildExtension'], 'write', _write, __slice.call(e.template).concat(__slice.call(e.css)));
return register(['add', 'update', 'buildFile'], 'write', _write, __slice.call(e.javascript).concat(__slice.call(e.copy), __slice.call(e.misc)));
// If the outputText is null/undef or there is no name set then all done
if ( ( file.outputFileText !== "" && !file.outputFileText ) || !file.outputFileName ) {
return done();
}

// if the output text is empty, let user know
if ( file.outputFileText === "" ) {
config.log.warn( "File [[ " + file.inputFileName + " ]] is empty." );
}

fileUtils.writeFile( file.outputFileName, file.outputFileText, function( err ) {
if ( err ) {
config.log.error( "Failed to write new file [[ " + file.outputFileName + " ]], Error: " + err, {exitIfBuild:true});
} else {
config.log.success( "Wrote file [[ " + file.outputFileName + " ]]", options );
}
done();
});
}
} else {
next();
}
};

exports.registration = function( config, register ) {
var e = config.extensions;
register(
["add", "update", "remove", "buildExtension"],
"write",
_write,
[].concat.apply( e.template, e.css )
);

register(
["add", "update", "buildFile"],
"write",
_write,
[].concat.apply( e.javascript, e.copy, e.misc )
);
};
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"mimosa-jshint": "2.0.0",
"mimosa-live-reload": "1.3.0",
"mimosa-minify-css": "1.4.0",
"mimosa-minify-html": "^0.3.0",
"mimosa-minify-js": "2.0.0",
"mimosa-require": "2.3.3",
"mimosa-server": "1.6.1",
Expand All @@ -83,7 +84,13 @@
"engines": {
"node": ">=0.10"
},
"devDependencies": {
"mocha": "1.9.0",
"chai": "1.5.0",
"sinon": "1.12.2"
},
"scripts": {
"test": "node_modules/.bin/mocha",
"prepublish": "node build.js"
}
}
56 changes: 56 additions & 0 deletions src/modules/file/write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";

var _write = function( config, options, next ) {
if ( options.files && options.files.length ) {

var processed = 0;
var done = function() {
if ( ++processed === options.files.length ) {
next();
}
};

var fileUtils = require( "../../util/file" );
for ( var i = 0; i < options.files.length; i++ ) {
var file = options.files[i];

// If the outputText is null/undef or there is no name set then all done
if ( ( file.outputFileText !== "" && !file.outputFileText ) || !file.outputFileName ) {
return done();
}

// if the output text is empty, let user know
if ( file.outputFileText === "" ) {
config.log.warn( "File [[ " + file.inputFileName + " ]] is empty." );
}

fileUtils.writeFile( file.outputFileName, file.outputFileText, function( err ) {
if ( err ) {
config.log.error( "Failed to write new file [[ " + file.outputFileName + " ]], Error: " + err, {exitIfBuild:true});
} else {
config.log.success( "Wrote file [[ " + file.outputFileName + " ]]", options );
}
done();
});
}
} else {
next();
}
};

exports.registration = function( config, register ) {
var e = config.extensions;
register(
["add", "update", "remove", "buildExtension"],
"write",
_write,
[].concat.apply( e.template, e.css )
);

register(
["add", "update", "buildFile"],
"write",
_write,
[].concat.apply( e.javascript, e.copy, e.misc )
);
};
1 change: 1 addition & 0 deletions test/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global.expect = require('chai').expect;
1 change: 1 addition & 0 deletions test/tmp/03f9d3fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
1 change: 1 addition & 0 deletions test/tmp/18fdf0fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/tmp/21e9a8fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
1 change: 1 addition & 0 deletions test/tmp/23516dfixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/tmp/276715fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/tmp/4a6722fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/tmp/5d477bfixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/tmp/736c10fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/tmp/b97f25fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
1 change: 1 addition & 0 deletions test/tmp/cdfba9fixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
1 change: 1 addition & 0 deletions test/tmp/def22ffixture_outtest1.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/unit-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./units/modules/file/write-test")
Loading

0 comments on commit 3a0aaeb

Please sign in to comment.