UNPKG

mason

Version:

simple, fun, static-file builder for jade, stylus, and javascript

39 lines (34 loc) 1.09 kB
var _ = require('underscore')._; var path = require('path'); var fs = require('node-fs'); exports.log = function(event, msg, sub) { if (sub) { console.log('\033[90m -> ' + msg + '\033[0m'); } else { console.log('\033[32mMason:\033[0m \033[36m%s\033[0m\033[90m - %s\033[0m', event, msg); } }; exports.concatFiles = function(files) { var total = '', contents; for (var i = 0; i < files.length; i++) { contents = fs.readFileSync(files[i]); // protect against missing semis... TODO: delegate this responsibility to the uglifier total += contents + ';'; } return total; }; exports.writeFile = function(file_path, contents) { var dir = path.dirname(file_path); fs.mkdirSync(dir, 0777, true); fs.writeFileSync(file_path, contents); exports.log('write', file_path, true); }; exports.buildPaths = function(root, sourceRoot, sourcePaths) { if (sourcePaths instanceof Array) { return _.map(sourcePaths, function(sourcePath) { return path.join(root, sourceRoot, sourcePath); }); } return [path.join(root, sourceRoot, sourcePaths)]; };