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
XhmikosR 37facee922 bs-commonjs-generator.js: always use forward slashes in the require path.
Since `path.resolve` is using backslashes on Windows, we ended up with different files. Just replace those with forward slashes.
2014-10-26 09:35:14 +02:00

24 lines
740 B
JavaScript

'use strict';
var fs = require('fs');
var path = require('path');
var COMMONJS_BANNER = '// This file is generated. You can require() it in a CommonJS environment.\n';
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
var destDir = path.dirname(destFilepath);
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath).replace(/\\/g, '/');
return 'require(\'' + requirePath + '\')';
}
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.');
};