config.js 875 B

12345678910111213141516171819202122232425
  1. /**
  2. * Wrapper around amd-config-builder.
  3. * Can be used in cli and in grunt task.
  4. */
  5. var configBuilder = require('amd-config-builder'),
  6. path = require('path'),
  7. fs = require('fs');
  8. exports.writeConfig = function (searchDir, fileForConfig) {
  9. searchDir = searchDir || path.join(__dirname, '../../..');
  10. fileForConfig = fileForConfig || 'config.js';
  11. configBuilder.produceConfigObject(searchDir, function (err, result) {
  12. if (err) throw err;
  13. var text = "/* DO NOT EDIT! This file is generated. */\n" +
  14. "\n" +
  15. "var require;\n" +
  16. "if (!require) require = {config: function (x) {require = x;}};\n" +
  17. "require.config(" + JSON.stringify(result, null, 2) + ");";
  18. fs.writeFile(path.join(searchDir, fileForConfig), text, function (err) {
  19. if (err) throw err;
  20. });
  21. });
  22. };