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.

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