gulpfile.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. const fs = require('fs')
  2. const utils = require('util')
  3. const cp = require('child_process')
  4. const exec = utils.promisify(cp.exec)
  5. const path = require('path')
  6. const gulp = require('gulp')
  7. const cleanCSS = require('gulp-clean-css')
  8. const del = require('del')
  9. const outputPath = path.join(__dirname, 'static')
  10. const resourcesPath = path.join(__dirname, 'resources')
  11. const publicStaticPath = path.join(__dirname, 'public/static')
  12. const sourcePath = path.join(__dirname, 'src/main/frontend')
  13. const resourceFilePath = path.join(resourcesPath, '**')
  14. const outputFilePath = path.join(outputPath, '**')
  15. const css = {
  16. watchCSS () {
  17. return cp.spawn(`yarn css:watch`, {
  18. shell: true,
  19. stdio: 'inherit'
  20. })
  21. },
  22. buildCSS (...params) {
  23. return cp.spawn(`yarn css:build`, {
  24. shell: true,
  25. stdio: 'inherit'
  26. })
  27. }
  28. }
  29. const common = {
  30. clean () {
  31. return del(['./static/**/*', '!./static/yarn.lock', '!./static/node_modules'])
  32. },
  33. syncResourceFile () {
  34. return gulp.src(resourceFilePath).pipe(gulp.dest(outputPath))
  35. },
  36. syncAssetFiles () {
  37. return gulp.src([
  38. "./node_modules/@excalidraw/excalidraw/dist/excalidraw-assets/**",
  39. "!**/*/i18n-*.js"
  40. ])
  41. .pipe(gulp.dest(path.join(outputPath, 'js', 'excalidraw-assets')))
  42. },
  43. keepSyncResourceFile () {
  44. return gulp.watch(resourceFilePath, { ignoreInitial: true }, common.syncResourceFile)
  45. },
  46. syncAllStatic () {
  47. return gulp.src([
  48. outputFilePath,
  49. '!' + path.join(outputPath, 'node_modules/**')
  50. ]).pipe(gulp.dest(publicStaticPath))
  51. },
  52. syncJS_CSSinRt () {
  53. return gulp.src([
  54. path.join(outputPath, 'js/**'),
  55. path.join(outputPath, 'css/**')
  56. ], { base: outputPath }).pipe(gulp.dest(publicStaticPath))
  57. },
  58. keepSyncStaticInRt () {
  59. return gulp.watch([
  60. path.join(outputPath, 'js/**'),
  61. path.join(outputPath, 'css/**')
  62. ], { ignoreInitial: true }, common.syncJS_CSSinRt)
  63. }
  64. }
  65. exports.electron = () => {
  66. if (!fs.existsSync(path.join(outputPath, 'node_modules'))) {
  67. cp.execSync('yarn', {
  68. cwd: outputPath,
  69. stdio: 'inherit'
  70. })
  71. }
  72. cp.execSync('yarn electron:dev', {
  73. cwd: outputPath,
  74. stdio: 'inherit'
  75. })
  76. }
  77. exports.electronMaker = async () => {
  78. cp.execSync('yarn cljs:release-electron', {
  79. stdio: 'inherit'
  80. })
  81. const pkgPath = path.join(outputPath, 'package.json')
  82. const pkg = require(pkgPath)
  83. const version = fs.readFileSync(path.join(__dirname, 'src/main/frontend/version.cljs'))
  84. .toString().match(/[0-9.]{3,}/)[0]
  85. if (!version) {
  86. throw new Error('release version error in src/**/*/version.cljs')
  87. }
  88. pkg.version = version
  89. fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2))
  90. if (!fs.existsSync(path.join(outputPath, 'node_modules'))) {
  91. cp.execSync('yarn', {
  92. cwd: outputPath,
  93. stdio: 'inherit'
  94. })
  95. }
  96. cp.execSync('yarn electron:make', {
  97. cwd: outputPath,
  98. stdio: 'inherit'
  99. })
  100. }
  101. exports.clean = common.clean
  102. exports.watch = gulp.series(common.syncResourceFile, common.syncAssetFiles, common.syncAllStatic,
  103. gulp.parallel(common.keepSyncResourceFile, css.watchCSS, common.keepSyncStaticInRt))
  104. exports.build = gulp.series(common.clean, common.syncResourceFile, common.syncAssetFiles, css.buildCSS)