Add Hash util and split out file helper.

This commit is contained in:
John-David Dalton
2016-04-06 23:22:22 -07:00
parent 58afd8c364
commit 0588dcb3e9
9 changed files with 94 additions and 50 deletions

36
lib/common/file.js Normal file
View File

@@ -0,0 +1,36 @@
'use strict';
var _ = require('lodash'),
fs = require('fs-extra'),
glob = require('glob'),
path = require('path');
var minify = require('../common/minify.js');
/*----------------------------------------------------------------------------*/
function copy(srcPath, destPath) {
return _.partial(fs.copy, srcPath, destPath);
}
function globTemplate(pattern) {
return _.transform(glob.sync(pattern), function(result, filePath) {
var key = path.basename(filePath, path.extname(filePath));
result[key] = _.template(fs.readFileSync(filePath, 'utf8'));
}, {});
}
function min(srcPath, destPath) {
return _.partial(minify, srcPath, destPath);
}
function write(filePath, data) {
return _.partial(fs.writeFile, filePath, data);
}
module.exports = {
'copy': copy,
'globTemplate': globTemplate,
'min': min,
'write': write
};