2015-04-28 04:11:49 -04:00
|
|
|
/*!
|
|
|
|
* Bootstrap Grunt task for the CommonJS module generation
|
|
|
|
* http://getbootstrap.com
|
2016-05-20 12:04:31 -04:00
|
|
|
* Copyright 2014-2015 The Bootstrap Authors
|
2015-04-28 04:11:49 -04:00
|
|
|
* Copyright 2014-2015 Twitter, Inc.
|
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
|
|
|
*/
|
|
|
|
|
2014-08-27 21:24:23 -04:00
|
|
|
'use strict';
|
2015-05-06 16:34:14 -04:00
|
|
|
|
2014-08-27 21:24:23 -04:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
2014-10-27 18:20:55 -04:00
|
|
|
var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
|
2014-09-08 20:50:35 -04:00
|
|
|
|
2014-08-27 21:39:41 -04:00
|
|
|
module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
|
|
|
|
var destDir = path.dirname(destFilepath);
|
2014-08-27 21:24:23 -04:00
|
|
|
|
2014-08-27 21:39:41 -04:00
|
|
|
function srcPathToDestRequire(srcFilepath) {
|
2015-08-25 01:27:01 -04:00
|
|
|
return 'require(\'' + srcFilepath.replace(/\\/g, '/') + '\')';
|
2014-08-27 21:39:41 -04:00
|
|
|
}
|
2014-08-27 21:24:23 -04:00
|
|
|
|
2014-09-08 20:50:35 -04:00
|
|
|
var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
|
2014-08-27 21:24:23 -04:00
|
|
|
try {
|
|
|
|
fs.writeFileSync(destFilepath, moduleOutputJs);
|
2015-04-26 06:53:45 -04:00
|
|
|
} catch (err) {
|
2014-08-27 21:24:23 -04:00
|
|
|
grunt.fail.warn(err);
|
|
|
|
}
|
|
|
|
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
|
|
|
|
};
|