2 * Bootstrap Grunt task for the CommonJS module generation
3 * http://getbootstrap.com
4 * Copyright 2014-2015 Twitter, Inc.
5 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
10 var fs = require('fs');
11 var path = require('path');
13 var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
15 module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
16 var destDir = path.dirname(destFilepath);
18 function srcPathToDestRequire(srcFilepath) {
19 var requirePath = path.relative(destDir, srcFilepath).replace(/\\/g, '/');
20 return 'require(\'' + requirePath + '\')';
23 var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
25 fs.writeFileSync(destFilepath, moduleOutputJs);
29 grunt.log.writeln('File ' + destFilepath.cyan + ' created.');