Ohm-Management - Projektarbeit B-ME
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.

build.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env node
  2. 'use strict';
  3. const fs = require('fs');
  4. const path = require('path');
  5. const mimeScore = require('mime-score');
  6. let db = require('mime-db');
  7. let chalk = require('chalk');
  8. const STANDARD_FACET_SCORE = 900;
  9. const byExtension = {};
  10. // Clear out any conflict extensions in mime-db
  11. for (let type in db) {
  12. let entry = db[type];
  13. entry.type = type;
  14. if (!entry.extensions) continue;
  15. entry.extensions.forEach(ext => {
  16. if (ext in byExtension) {
  17. const e0 = entry;
  18. const e1 = byExtension[ext];
  19. e0.pri = mimeScore(e0.type, e0.source);
  20. e1.pri = mimeScore(e1.type, e1.source);
  21. let drop = e0.pri < e1.pri ? e0 : e1;
  22. let keep = e0.pri >= e1.pri ? e0 : e1;
  23. drop.extensions = drop.extensions.filter(e => e !== ext);
  24. console.log(`${ext}: Keeping ${chalk.green(keep.type)} (${keep.pri}), dropping ${chalk.red(drop.type)} (${drop.pri})`);
  25. }
  26. byExtension[ext] = entry;
  27. });
  28. }
  29. function writeTypesFile(types, path) {
  30. fs.writeFileSync(path, JSON.stringify(types));
  31. }
  32. // Segregate into standard and non-standard types based on facet per
  33. // https://tools.ietf.org/html/rfc6838#section-3.1
  34. const types = {};
  35. Object.keys(db).sort().forEach(k => {
  36. const entry = db[k];
  37. types[entry.type] = entry.extensions;
  38. });
  39. writeTypesFile(types, path.join(__dirname, '..', 'types.json'));