0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-01 13:24:25 +01:00
Bootstrap/grunt/bs-commonjs-generator.js

23 lines
596 B
JavaScript
Raw Normal View History

'use strict';
var fs = require('fs');
var path = require('path');
2014-08-28 03:39:41 +02:00
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
var destDir = path.dirname(destFilepath);
2014-08-28 03:39:41 +02:00
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath);
return "require('"+requirePath+"')";
}
2014-08-28 03:39:41 +02:00
var moduleOutputJs = srcFiles.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
}
catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};