cdn.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. let path = require('path');
  3. let browserBuild = require('./browser');
  4. let registry = require('./tasks');
  5. let utility = require('./utility');
  6. let directory;
  7. function moveLanguages() {
  8. let input = path.join(directory.root, 'src', 'languages', '*.js'),
  9. output = path.join(directory.build, 'languages'),
  10. regex = utility.regex,
  11. replace = utility.replace,
  12. replaceArgs = replace(regex.header, ''),
  13. template = 'hljs.registerLanguage(\'<%= name %>\','+
  14. ' <%= content %>);\n';
  15. return {
  16. startLog: { task: ['log', 'Building language files.'] },
  17. read: {
  18. requires: 'startLog',
  19. task: ['glob', utility.glob(input)]
  20. },
  21. replace: { requires: 'read', task: ['replace', replaceArgs] },
  22. template: { requires: 'replace', task: ['template', template] },
  23. replace2: {
  24. requires: 'template',
  25. task: [ 'replaceSkippingStrings'
  26. , replace(regex.replaces, utility.replaceClassNames)
  27. ]
  28. },
  29. replace3: {
  30. requires: 'replace2',
  31. task: ['replace', replace(regex.classname, '$1.className')]
  32. },
  33. compressLog: {
  34. requires: 'replace3',
  35. task: ['log', 'Compressing languages files.']
  36. },
  37. minify: { requires: 'compressLog', task: 'jsminify' },
  38. rename: { requires: 'minify', task: ['rename', { extname: '.min.js' }] },
  39. writeLog: {
  40. requires: 'rename',
  41. task: ['log', 'Writing language files.']
  42. },
  43. write: { requires: 'writeLog', task: ['dest', output] }
  44. };
  45. }
  46. function moveStyles() {
  47. const css = path.join(directory.root, 'src', 'styles', '*.css'),
  48. images = path.join(directory.root, 'src', 'styles', '*.{jpg,png}'),
  49. output = path.join(directory.build, 'styles'),
  50. options = { dir: output, encoding: 'binary' };
  51. return {
  52. startLog: { task: ['log', 'Building style files.'] },
  53. readCSS: { requires: 'startLog', task: ['glob', utility.glob(css)] },
  54. readImages: {
  55. requires: 'startLog',
  56. task: ['glob', utility.glob(images, 'binary')]
  57. },
  58. compressLog: {
  59. requires: 'readCSS',
  60. task: ['log', 'Compressing style files.']
  61. },
  62. minify: { requires: 'compressLog', task: 'cssminify' },
  63. rename: {
  64. requires: 'minify',
  65. task: ['rename', { extname: '.min.css' }]
  66. },
  67. writeLog: {
  68. requires: ['rename', 'readImages'],
  69. task: ['log', 'Writing style files.']
  70. },
  71. write: { requires: 'writeLog', task: ['dest', options] }
  72. };
  73. }
  74. module.exports = function(commander, dir) {
  75. directory = dir;
  76. return utility.toQueue([moveLanguages(), moveStyles()], registry)
  77. .concat(browserBuild(commander, dir));
  78. };