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

30 lines
931 B
JavaScript
Raw Normal View History

2015-04-28 10:11:49 +02:00
/*!
* Bootstrap Grunt task for the CommonJS module generation
* http://getbootstrap.com
* Copyright 2014-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
'use strict';
2015-05-06 22:34:14 +02:00
var fs = require('fs');
var path = require('path');
var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
2014-09-09 02:50:35 +02:00
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) {
return 'require(\'' + srcFilepath.replace(/\\/g, '/') + '\')';
2014-08-28 03:39:41 +02:00
}
2014-09-09 02:50:35 +02:00
var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
try {
fs.writeFileSync(destFilepath, moduleOutputJs);
2015-04-26 12:53:45 +02:00
} catch (err) {
grunt.fail.warn(err);
}
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
};