build-query.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*global define*/
  2. define(['lodash', 'metadata'], function(_, metadata) {
  3. function getDetectObjByAmdPath(amdPath) {
  4. return _.find(metadata, function(detect) {
  5. return detect.amdPath === amdPath || detect.amdPath === 'test/' + amdPath;
  6. });
  7. }
  8. return function generateBuildQuery(config) {
  9. // Format:
  10. // ?-<prop1>-<prop2>-…-<propN>-<option1>-<option2>-…<optionN>[-dontmin][-cssclassprefix:<prefix>]
  11. // where prop1…N and option1…N are sorted alphabetically (for consistency)
  12. var dontmin = !config.minify;
  13. // Config uses amdPaths, but build query uses property names
  14. var props = _.chain(config['feature-detects'])
  15. .map(function(amdPath) {
  16. var detect = getDetectObjByAmdPath(amdPath);
  17. var property = detect && detect.property;
  18. if (property) {
  19. property = _.isArray(property) ?
  20. property.join('_').replace('-', '_') :
  21. property.replace('-', '_');
  22. return property;
  23. }
  24. })
  25. .filter()
  26. .value();
  27. // Config uses amdPaths, but the option's just use their names.
  28. // A few of the values have to be massaged in order to match
  29. // the `value`
  30. var opts = _.map(config.options, function(opt) {
  31. if (opt.indexOf('html5') === 0) {
  32. opt = opt.replace('html5', '');
  33. }
  34. return opt.toLowerCase();
  35. });
  36. var sortedProps = props.sort();
  37. var sortedOpts = opts.sort();
  38. // Options are AMD paths in the config, but need to be converted to
  39. var buildQuery = '?-' + sortedProps.concat(sortedOpts).join('-') +
  40. (dontmin ? '-dontmin' : '') +
  41. ((config.classPrefix) ?
  42. '-cssclassprefix:' + config.classPrefix : '');
  43. return buildQuery;
  44. };
  45. });