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.

96 lines
3.8 KiB

  1. 'use strict'
  2. const _ = require('lodash')
  3. const Promise = require('bluebird')
  4. const colors = require('colors/safe')
  5. const fs = Promise.promisifyAll(require('fs-extra'))
  6. const path = require('path')
  7. const uglify = require('uglify-es')
  8. module.exports = Promise.mapSeries([
  9. /**
  10. * SimpleMDE
  11. */
  12. () => {
  13. return fs.accessAsync('./assets/js/simplemde').then(() => {
  14. console.info(colors.white(' └── ') + colors.magenta('SimpleMDE directory already exists. Task aborted.'))
  15. return true
  16. }).catch(err => {
  17. if (err.code === 'ENOENT') {
  18. console.info(colors.white(' └── ') + colors.green('Copy + Minify SimpleMDE to assets...'))
  19. return fs.copy('./node_modules/simplemde/dist/simplemde.min.js', './assets/js/simplemde/simplemde.min.js')
  20. } else {
  21. throw err
  22. }
  23. })
  24. },
  25. /**
  26. * ACE Modes
  27. */
  28. () => {
  29. return fs.accessAsync('./assets/js/ace').then(() => {
  30. console.info(colors.white(' └── ') + colors.magenta('ACE modes directory already exists. Task aborted.'))
  31. return true
  32. }).catch(err => {
  33. if (err.code === 'ENOENT') {
  34. console.info(colors.white(' └── ') + colors.green('Copy + Minify ACE modes to assets...'))
  35. return fs.ensureDirAsync('./assets/js/ace').then(() => {
  36. return Promise.join(
  37. // Core
  38. Promise.all([
  39. fs.readFileAsync('./node_modules/brace/index.js', 'utf8'),
  40. fs.readFileAsync('./node_modules/brace/ext/modelist.js', 'utf8'),
  41. fs.readFileAsync('./node_modules/brace/theme/dawn.js', 'utf8'),
  42. fs.readFileAsync('./node_modules/brace/theme/tomorrow_night.js', 'utf8'),
  43. fs.readFileAsync('./node_modules/brace/mode/markdown.js', 'utf8')
  44. ]).then(items => {
  45. console.info(colors.white(' ace.js'))
  46. let result = uglify.minify(items.join(';\n'), { output: { 'max_line_len': 1000000 } })
  47. return fs.writeFileAsync('./assets/js/ace/ace.js', result.code)
  48. }),
  49. // Modes
  50. fs.readdirAsync('./node_modules/brace/mode').then(modeList => {
  51. return Promise.map(modeList, mdFile => {
  52. return fs.readFileAsync(path.join('./node_modules/brace/mode', mdFile), 'utf8').then(modeCode => {
  53. console.info(colors.white(' mode-' + mdFile))
  54. let result = uglify.minify(modeCode, { output: { 'max_line_len': 1000000 } })
  55. return fs.writeFileAsync(path.join('./assets/js/ace', 'mode-' + mdFile), result.code)
  56. })
  57. }, { concurrency: 3 })
  58. })
  59. )
  60. })
  61. } else {
  62. throw err
  63. }
  64. })
  65. },
  66. /**
  67. * i18n
  68. */
  69. () => {
  70. console.info(colors.white(' └── ') + colors.green('Copying i18n client files...'))
  71. return fs.ensureDirAsync('./assets/js/i18n').then(() => {
  72. return fs.readJsonAsync('./server/locales/en/browser.json').then(enContent => {
  73. return fs.readdirAsync('./server/locales').then(langs => {
  74. return Promise.map(langs, lang => {
  75. console.info(colors.white(' ' + lang + '.json'))
  76. let outputPath = path.join('./assets/js/i18n', lang + '.json')
  77. return fs.readJsonAsync(path.join('./server/locales', lang + '.json'), 'utf8').then((content) => {
  78. return fs.outputJsonAsync(outputPath, _.defaultsDeep(content, enContent))
  79. }).catch(err => { // eslint-disable-line handle-callback-err
  80. return fs.outputJsonAsync(outputPath, enContent)
  81. })
  82. })
  83. })
  84. })
  85. })
  86. },
  87. /**
  88. * Delete Fusebox cache
  89. */
  90. () => {
  91. console.info(colors.white(' └── ') + colors.green('Clearing fuse-box cache...'))
  92. return fs.emptyDirAsync('./.fusebox')
  93. }
  94. ], f => { return f() })