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.

210 lines
5.2 KiB

  1. 'use strict'
  2. const gulp = require('gulp')
  3. const watch = require('gulp-watch')
  4. const merge = require('merge-stream')
  5. const babel = require('gulp-babel')
  6. const uglify = require('gulp-uglify')
  7. const concat = require('gulp-concat')
  8. const nodemon = require('gulp-nodemon')
  9. const plumber = require('gulp-plumber')
  10. const zip = require('gulp-zip')
  11. const tar = require('gulp-tar')
  12. const gzip = require('gulp-gzip')
  13. const sass = require('gulp-sass')
  14. const cleanCSS = require('gulp-clean-css')
  15. const include = require('gulp-include')
  16. const run = require('run-sequence')
  17. /**
  18. * Paths
  19. *
  20. * @type {Object}
  21. */
  22. const paths = {
  23. scripts: {
  24. combine: [
  25. './node_modules/socket.io-client/dist/socket.io.min.js',
  26. './node_modules/jquery/dist/jquery.min.js',
  27. './node_modules/vue/dist/vue.min.js',
  28. './node_modules/jquery-smooth-scroll/jquery.smooth-scroll.min.js',
  29. './node_modules/jquery-simple-upload/simpleUpload.min.js',
  30. './node_modules/jquery-contextmenu/dist/jquery.contextMenu.min.js',
  31. './node_modules/sticky-js/dist/sticky.min.js',
  32. './node_modules/simplemde/dist/simplemde.min.js',
  33. './node_modules/ace-builds/src-min-noconflict/ace.js',
  34. './node_modules/ace-builds/src-min-noconflict/ext-modelist.js',
  35. './node_modules/ace-builds/src-min-noconflict/mode-markdown.js',
  36. './node_modules/ace-builds/src-min-noconflict/theme-tomorrow_night.js',
  37. './node_modules/filesize.js/dist/filesize.min.js',
  38. './node_modules/lodash/lodash.min.js'
  39. ],
  40. ace: [
  41. './node_modules/ace-builds/src-min-noconflict/mode-*.js',
  42. '!./node_modules/ace-builds/src-min-noconflict/mode-markdown.js'
  43. ],
  44. compile: [
  45. './client/js/*.js'
  46. ],
  47. watch: [
  48. './client/js/**/*.js'
  49. ]
  50. },
  51. css: {
  52. combine: [
  53. './node_modules/highlight.js/styles/tomorrow.css',
  54. './node_modules/simplemde/dist/simplemde.min.css'
  55. ],
  56. compile: [
  57. './client/scss/*.scss'
  58. ],
  59. includes: [
  60. './node_modules/requarks-core' //! MUST BE LAST
  61. ],
  62. watch: [
  63. './client/scss/**/*.scss',
  64. '../core/core-client/scss/**/*.scss'
  65. ]
  66. },
  67. fonts: [
  68. '../node_modules/requarks-core/core-client/fonts/**/*' //! MUST BE LAST
  69. ],
  70. deploy: [
  71. './**/*',
  72. '!client/js', '!client/js/**',
  73. '!client/scss', '!client/scss/**',
  74. '!coverage', '!coverage/**',
  75. '!data', '!data/**',
  76. '!dist', '!dist/**',
  77. '!node_modules', '!node_modules/**',
  78. '!npm', '!npm/**',
  79. '!repo', '!repo/**',
  80. '!test', '!test/**',
  81. '!gulpfile.js', '!config.yml'
  82. ]
  83. }
  84. /**
  85. * TASK - Starts server in development mode
  86. */
  87. gulp.task('server', ['scripts', 'css', 'fonts'], function () {
  88. nodemon({
  89. script: './server',
  90. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  91. ext: 'js json',
  92. env: { 'NODE_ENV': 'development' }
  93. })
  94. })
  95. /**
  96. * TASK - Process all scripts processes
  97. */
  98. gulp.task('scripts', ['scripts-libs', 'scripts-app'])
  99. /**
  100. * TASK - Combine js libraries
  101. */
  102. gulp.task('scripts-libs', function () {
  103. return merge(
  104. gulp.src(paths.scripts.combine)
  105. .pipe(concat('libs.js', {newLine: ';\n'}))
  106. .pipe(uglify({ mangle: false }))
  107. .pipe(gulp.dest('./assets/js')),
  108. gulp.src(paths.scripts.ace)
  109. .pipe(gulp.dest('./assets/js/ace'))
  110. )
  111. })
  112. /**
  113. * TASK - Combine, make compatible and compress js app scripts
  114. */
  115. gulp.task('scripts-app', function () {
  116. return gulp.src(paths.scripts.compile)
  117. .pipe(plumber())
  118. .pipe(include({ extensions: 'js' }))
  119. .pipe(babel())
  120. .pipe(uglify())
  121. .pipe(plumber.stop())
  122. .pipe(gulp.dest('./assets/js'))
  123. })
  124. /**
  125. * TASK - Process all css processes
  126. */
  127. gulp.task('css', ['css-libs', 'css-app'])
  128. /**
  129. * TASK - Combine css libraries
  130. */
  131. gulp.task('css-libs', function () {
  132. return gulp.src(paths.css.combine)
  133. .pipe(plumber())
  134. .pipe(concat('libs.css'))
  135. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  136. .pipe(plumber.stop())
  137. .pipe(gulp.dest('./assets/css'))
  138. })
  139. /**
  140. * TASK - Combine app css
  141. */
  142. gulp.task('css-app', function () {
  143. return gulp.src(paths.css.compile)
  144. .pipe(plumber())
  145. .pipe(sass.sync({ includePaths: paths.css.includes }))
  146. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  147. .pipe(plumber.stop())
  148. .pipe(gulp.dest('./assets/css'))
  149. })
  150. /**
  151. * TASK - Copy web fonts
  152. */
  153. gulp.task('fonts', function () {
  154. return gulp.src(paths.fonts)
  155. .pipe(gulp.dest('./assets/fonts'))
  156. })
  157. /**
  158. * TASK - Start dev watchers
  159. */
  160. gulp.task('watch', function () {
  161. return merge(
  162. watch(paths.scripts.watch, {base: './'}, function () { return gulp.start('scripts-app') }),
  163. watch(paths.css.watch, {base: './'}, function () { return gulp.start('css-app') })
  164. )
  165. })
  166. /**
  167. * TASK - Starts development server with watchers
  168. */
  169. gulp.task('default', ['watch', 'server'])
  170. gulp.task('dev', function () {
  171. paths.css.includes.pop()
  172. paths.css.includes.push('../core')
  173. paths.fonts.pop()
  174. paths.fonts.push('../core/core-client/fonts/**/*')
  175. return run('default')
  176. })
  177. /**
  178. * TASK - Creates deployment packages
  179. */
  180. gulp.task('deploy', ['scripts', 'css', 'fonts'], function () {
  181. var zipStream = gulp.src(paths.deploy)
  182. .pipe(zip('wiki-js.zip'))
  183. .pipe(gulp.dest('dist'))
  184. var targzStream = gulp.src(paths.deploy)
  185. .pipe(tar('wiki-js.tar'))
  186. .pipe(gzip())
  187. .pipe(gulp.dest('dist'))
  188. return merge(zipStream, targzStream)
  189. })