1
0
mirror of https://github.com/twbs/bootstrap.git synced 2025-02-23 18:40:03 +00:00
bootstrap/grunt/bs-commonjs-generator.js

23 lines
682 B
JavaScript
Raw Normal View History

'use strict';
var fs = require('fs');
var path = require('path');
2014-08-28 09:39:41 +08:00
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
var destDir = path.dirname(destFilepath);
2014-08-28 09:39:41 +08:00
function srcPathToDestRequire(srcFilepath) {
var requirePath = path.relative(destDir, srcFilepath);
2014-08-28 09:54:51 +08:00
return 'require(\'' + requirePath + '\')';
2014-08-28 09:39:41 +08:00
}
2014-09-09 08:47:23 +08:00
var moduleOutputJs = '// This file is generated. You can require() it in a CommonJS environment.\n' +
srcFiles.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
}
catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};