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.

186 lines
4.2 KiB

  1. var gulp = require("gulp");
  2. var merge = require('merge-stream');
  3. var babel = require("gulp-babel");
  4. var uglify = require('gulp-uglify');
  5. var concat = require('gulp-concat');
  6. var nodemon = require('gulp-nodemon');
  7. var plumber = require('gulp-plumber');
  8. var zip = require('gulp-zip');
  9. var tar = require('gulp-tar');
  10. var gzip = require('gulp-gzip');
  11. var sass = require('gulp-sass');
  12. var cleanCSS = require('gulp-clean-css');
  13. var include = require("gulp-include");
  14. /**
  15. * Paths
  16. *
  17. * @type {Object}
  18. */
  19. var paths = {
  20. scriptlibs: [
  21. './node_modules/socket.io-client/socket.io.js',
  22. './node_modules/jquery/dist/jquery.min.js',
  23. './node_modules/vue/dist/vue.min.js',
  24. './node_modules/jquery-smooth-scroll/jquery.smooth-scroll.min.js',
  25. './node_modules/sticky-js/dist/sticky.min.js',
  26. './node_modules/simplemde/dist/simplemde.min.js',
  27. './node_modules/ace-builds/src-min-noconflict/ace.js',
  28. './node_modules/ace-builds/src-min-noconflict/mode-markdown.js',
  29. './node_modules/ace-builds/src-min-noconflict/theme-tomorrow_night.js',
  30. './node_modules/lodash/lodash.min.js'
  31. ],
  32. scriptapps: [
  33. './client/js/app.js'
  34. ],
  35. scriptapps_watch: [
  36. './client/js/**/*.js'
  37. ],
  38. csslibs: [
  39. './node_modules/font-awesome/css/font-awesome.min.css',
  40. './node_modules/highlight.js/styles/default.css',
  41. './node_modules/simplemde/dist/simplemde.min.css'
  42. ],
  43. cssapps: [
  44. './client/scss/app.scss'
  45. ],
  46. cssapps_watch: [
  47. './client/scss/**/*.scss'
  48. ],
  49. cssapps_imports: [
  50. './node_modules/bulma/'
  51. ],
  52. fonts: [
  53. './node_modules/font-awesome/fonts/*-webfont.*',
  54. '!./node_modules/font-awesome/fonts/*-webfont.svg'
  55. ],
  56. deploypackage: [
  57. './assets/**/*',
  58. './client/content/**/*',
  59. './controllers/**/*',
  60. './locales/**/*',
  61. './middlewares/**/*',
  62. './models/**/*',
  63. './views/**/*',
  64. './LICENSE',
  65. './agent.js',
  66. './server.js',
  67. './package.json',
  68. './config.sample.yml'
  69. ]
  70. };
  71. /**
  72. * TASK - Starts server in development mode
  73. */
  74. gulp.task('server', ['scripts', 'css', 'fonts'], function() {
  75. nodemon({
  76. script: './server',
  77. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  78. ext: 'js json',
  79. env: { 'NODE_ENV': 'development' }
  80. });
  81. });
  82. /**
  83. * TASK - Process all scripts processes
  84. */
  85. gulp.task("scripts", ['scripts-libs', 'scripts-app']);
  86. /**
  87. * TASK - Combine js libraries
  88. */
  89. gulp.task("scripts-libs", function () {
  90. return gulp.src(paths.scriptlibs)
  91. .pipe(plumber())
  92. .pipe(concat('libs.js'))
  93. .pipe(uglify({ mangle: false }))
  94. .pipe(plumber.stop())
  95. .pipe(gulp.dest("./assets/js"));
  96. });
  97. /**
  98. * TASK - Combine, make compatible and compress js app scripts
  99. */
  100. gulp.task("scripts-app", function () {
  101. return gulp.src(paths.scriptapps)
  102. .pipe(plumber())
  103. .pipe(concat('app.js'))
  104. .pipe(include({ extensions: "js" }))
  105. .pipe(babel())
  106. .pipe(uglify())
  107. .pipe(plumber.stop())
  108. .pipe(gulp.dest("./assets/js"));
  109. });
  110. /**
  111. * TASK - Process all css processes
  112. */
  113. gulp.task("css", ['css-libs', 'css-app']);
  114. /**
  115. * TASK - Combine css libraries
  116. */
  117. gulp.task("css-libs", function () {
  118. return gulp.src(paths.csslibs)
  119. .pipe(plumber())
  120. .pipe(concat('libs.css'))
  121. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  122. .pipe(plumber.stop())
  123. .pipe(gulp.dest("./assets/css"));
  124. });
  125. /**
  126. * TASK - Combine app css
  127. */
  128. gulp.task("css-app", function () {
  129. return gulp.src(paths.cssapps)
  130. .pipe(plumber())
  131. .pipe(sass({
  132. includePaths: paths.cssapps_imports
  133. }))
  134. .pipe(concat('app.css'))
  135. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  136. .pipe(plumber.stop())
  137. .pipe(gulp.dest("./assets/css"));
  138. });
  139. /**
  140. * TASK - Copy web fonts
  141. */
  142. gulp.task("fonts", function () {
  143. return gulp.src(paths.fonts)
  144. .pipe(gulp.dest("./assets/fonts"));
  145. });
  146. /**
  147. * TASK - Start dev watchers
  148. */
  149. gulp.task('watch', function() {
  150. gulp.watch([paths.scriptapps_watch], ['scripts-app']);
  151. gulp.watch([paths.cssapps_watch], ['css-app']);
  152. });
  153. /**
  154. * TASK - Starts development server with watchers
  155. */
  156. gulp.task('default', ['watch', 'server']);
  157. /**
  158. * TASK - Creates deployment packages
  159. */
  160. gulp.task('deploy', ['scripts', 'css', 'fonts'], function() {
  161. var zipStream = gulp.src(paths.deploypackage)
  162. .pipe(zip('requarks-wiki.zip'))
  163. .pipe(gulp.dest('dist'));
  164. var targzStream = gulp.src(paths.deploypackage)
  165. .pipe(tar('requarks-wiki.tar'))
  166. .pipe(gzip())
  167. .pipe(gulp.dest('dist'));
  168. return merge(zipStream, targzStream);
  169. });