1
0
Fork 0
mirror of https://github.com/twbs/bootstrap.git synced 2022-11-09 12:25:43 -05:00
twbs--bootstrap/grunt/bs-commonjs-generator.js

24 lines
781 B
JavaScript
Raw Normal View History

'use strict';
var fs = require('fs');
var path = require('path');
var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
2014-09-08 20:50:35 -04:00
2014-08-27 21:39:41 -04:00
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
var destDir = path.dirname(destFilepath);
2014-08-27 21:39:41 -04:00
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath).replace(/\\/g, '/');
2014-08-27 21:54:51 -04:00
return 'require(\'' + requirePath + '\')';
2014-08-27 21:39:41 -04:00
}
2014-09-08 20:50:35 -04:00
var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
}
catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};