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

24 lines
628 B
JavaScript

'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.');
};