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

24 lines
628 B
JavaScript
Raw Normal View History

'use strict';
var fs = require('fs');
var path = require('path');
var destDir = 'dist/js';
var destFilename = 'npm.js';
var destFilepath = path.join(destDir, destFilename);
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath);
return "require('"+requirePath+"')";
}
module.exports = function generateCommonJSModule(grunt, files) {
var moduleOutputJs = files.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
}
catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};