build.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. 'use strict';
  2. var fs = require('fs');
  3. var path = require('path');
  4. var glob = require('glob');
  5. var async = require('async');
  6. main();
  7. function main() {
  8. var componentsPath = 'node_modules/prismjs/components/';
  9. glob(componentsPath + '*.js', {}, function(err, files) {
  10. if(err) {
  11. return console.error(err);
  12. }
  13. files = files.filter(function(file) {
  14. // skip minified and core
  15. return file.indexOf('.min.js') === -1 && file.indexOf('-core.') === -1;
  16. });
  17. // XXX: not in npm... -> consume github version instead?
  18. files.push(path.join(__dirname, './makefile.js'));
  19. // XXX: JSON support. once the pr gets merged, this can be removed
  20. files.push(path.join(__dirname, './json.js'));
  21. async.map(files, function(file, cb) {
  22. fs.readFile(file, {
  23. encoding: 'utf-8'
  24. }, cb);
  25. }, function(err, data) {
  26. if(err) {
  27. return console.error(err);
  28. }
  29. var code = ['var Prism = require(\'prismjs\');\n'].
  30. concat(data).
  31. concat('delete Prism.languages.extend;').
  32. concat('delete Prism.languages.insertBefore;').
  33. concat('module.exports = Prism.languages;').
  34. join('');
  35. fs.writeFile('./index.js', code, function(err) {
  36. if(err) {
  37. return console.error(err);
  38. }
  39. });
  40. });
  41. });
  42. }