You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 line
990B

  1. /*!
  2. * Bootstrap Grunt task for the CommonJS module generation
  3. * http://getbootstrap.com
  4. * Copyright 2014-2015 Twitter, Inc.
  5. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  6. */
  7. 'use strict';
  8. var fs = require('fs');
  9. var path = require('path');
  10. var COMMONJS_BANNER = '// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.\n';
  11. module.exports = function generateCommonJSModule(grunt, srcFiles, destFilepath) {
  12. var destDir = path.dirname(destFilepath);
  13. function srcPathToDestRequire(srcFilepath) {
  14. var requirePath = path.relative(destDir, srcFilepath).replace(/\\/g, '/');
  15. return 'require(\'' + requirePath + '\')';
  16. }
  17. var moduleOutputJs = COMMONJS_BANNER + srcFiles.map(srcPathToDestRequire).join('\n');
  18. try {
  19. fs.writeFileSync(destFilepath, moduleOutputJs);
  20. } catch (err) {
  21. grunt.fail.warn(err);
  22. }
  23. grunt.log.writeln('File ' + destFilepath.cyan + ' created.');
  24. };