2015-04-28 10:11:49 +02:00
|
|
|
/*!
|
|
|
|
* Bootstrap Grunt task for the CommonJS module generation
|
2018-09-18 21:27:46 +02:00
|
|
|
* https://getbootstrap.com/
|
2019-02-10 13:01:42 +01:00
|
|
|
* Copyright 2014-2019 Twitter, Inc.
|
2019-02-15 22:36:44 +01:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/v3-dev/LICENSE)
|
2015-04-28 10:11:49 +02:00
|
|
|
*/
|
|
|
|
|
2014-08-28 03:24:23 +02:00
|
|
|
'use strict';
|
2015-04-26 12:53:45 +02:00
|
|
|
|
2014-08-28 03:24:23 +02:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
|
|
|
|
2014-10-27 23:20:55 +01: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-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:24:23 +02:00
|
|
|
|
2014-08-28 03:39:41 +02:00
|
|
|
function srcPathToDestRequire(srcFilepath) {
|
2018-09-18 17:39:35 +02:00
|
|
|
var requirePath = path.posix.relative(destDir, srcFilepath);
|
2014-08-28 03:54:51 +02:00
|
|
|
return 'require(\'' + requirePath + '\')';
|
2014-08-28 03:39:41 +02:00
|
|
|
}
|
2014-08-28 03:24:23 +02:00
|
|
|
|
2014-09-09 02:50:35 +02:00
|
|
|
var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
|
2014-08-28 03:24:23 +02:00
|
|
|
try {
|
|
|
|
fs.writeFileSync(destFilepath, moduleOutputJs);
|
2015-04-26 12:53:45 +02:00
|
|
|
} catch (err) {
|
2014-08-28 03:24:23 +02:00
|
|
|
grunt.fail.warn(err);
|
|
|
|
}
|
|
|
|
grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
|
|
|
|
};
|