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.

79 lines
3.0 KiB

  1. const Promise = require('bluebird')
  2. const colors = require('colors/safe')
  3. const fs = Promise.promisifyAll(require('fs-extra'))
  4. const path = require('path')
  5. const uglify = require('uglify-es')
  6. module.exports = Promise.mapSeries([
  7. /**
  8. * SimpleMDE
  9. */
  10. () => {
  11. return fs.accessAsync('./assets/js/simplemde').then(() => {
  12. console.info(colors.white(' └── ') + colors.magenta('SimpleMDE directory already exists. Task aborted.'))
  13. return true
  14. }).catch(err => {
  15. if (err.code === 'ENOENT') {
  16. console.info(colors.white(' └── ') + colors.green('Copy + Minify SimpleMDE to assets...'))
  17. return fs.copy('./node_modules/simplemde/dist/simplemde.min.js', './assets/js/simplemde/simplemde.min.js')
  18. } else {
  19. throw err
  20. }
  21. })
  22. },
  23. /**
  24. * ACE Modes
  25. */
  26. () => {
  27. return fs.accessAsync('./assets/js/ace').then(() => {
  28. console.info(colors.white(' └── ') + colors.magenta('ACE modes directory already exists. Task aborted.'))
  29. return true
  30. }).catch(err => {
  31. if (err.code === 'ENOENT') {
  32. console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...'))
  33. return fs.ensureDirAsync('./assets/js/ace').then(() => {
  34. return Promise.join(
  35. // Core
  36. Promise.all([
  37. fs.readFileAsync('./node_modules/brace/index.js', 'utf8'),
  38. fs.readFileAsync('./node_modules/brace/ext/modelist.js', 'utf8'),
  39. fs.readFileAsync('./node_modules/brace/theme/dawn.js', 'utf8'),
  40. fs.readFileAsync('./node_modules/brace/theme/tomorrow_night.js', 'utf8'),
  41. fs.readFileAsync('./node_modules/brace/mode/markdown.js', 'utf8')
  42. ]).then(items => {
  43. console.info(colors.white(' ace.js'))
  44. let result = uglify.minify(items.join(';\n'), { output: { 'max_line_len': 1000000 } })
  45. return fs.writeFileAsync('./assets/js/ace/ace.js', result.code)
  46. }),
  47. // Modes
  48. fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
  49. return Promise.map(modeList, mdFile => {
  50. return fs.readFileAsync(path.join('./node_modules/brace/mode', mdFile), 'utf8').then(modeCode => {
  51. console.info(colors.white(' mode-' + mdFile))
  52. let result = uglify.minify(modeCode, { output: { 'max_line_len': 1000000 } })
  53. return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code)
  54. })
  55. }, { concurrency: 3 })
  56. })
  57. )
  58. })
  59. } else {
  60. throw err
  61. }
  62. })
  63. },
  64. /**
  65. * Delete Fusebox cache
  66. */
  67. () => {
  68. console.info(colors.white(' └── ') + colors.green('Clearing fuse-box cache...'))
  69. return fs.emptyDirAsync('./.fusebox')
  70. },
  71. /**
  72. * Delete Test Results
  73. */
  74. () => {
  75. console.info(colors.white(' └── ') + colors.green('Clearing test results...'))
  76. return fs.remove('./test_results')
  77. }
  78. ], f => { return f() })