bootstrap/grunt/bs-commonjs-generator.js
2014-09-09 08:47:23 +08:00

23 lines
682 B
JavaScript

'use strict';
var fs = require('fs');
var path = require('path');
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
var destDir = path.dirname(destFilepath);
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath);
return 'require(\'' + requirePath + '\')';
}
var moduleOutputJs = '// This file is generated. You can require() it in a CommonJS environment.\n' +
srcFiles.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
}
catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};