config.js 913 B

123456789101112131415161718192021222324
  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, callback) {
  9. searchDir = searchDir || path.join(__dirname, '../../..');
  10. fileForConfig = fileForConfig || 'config.js';
  11. callback = callback || function (err) { if (err) throw err; };
  12. configBuilder.produceConfigObject(searchDir, function (err, result) {
  13. if (err) return callback(err);
  14. var text = "/* DO NOT EDIT! This file is generated. */\n" +
  15. "\n" +
  16. "var require;\n" +
  17. "if (!require) require = {config: function (x) {require = x;}};\n" +
  18. "require.config(" + JSON.stringify(result, null, 2) + ");";
  19. fs.writeFile(path.join(searchDir, fileForConfig), text, callback);
  20. });
  21. };