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.

194 lines
4.6 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/ext-modelist.js',
  29. './node_modules/ace-builds/src-min-noconflict/mode-markdown.js',
  30. './node_modules/ace-builds/src-min-noconflict/theme-tomorrow_night.js',
  31. './node_modules/lodash/lodash.min.js'
  32. ],
  33. scriptlibs_acemodes: [
  34. './node_modules/ace-builds/src-min-noconflict/mode-*.js',
  35. '!./node_modules/ace-builds/src-min-noconflict/mode-markdown.js'
  36. ],
  37. scriptapps: [
  38. './client/js/app.js'
  39. ],
  40. scriptapps_watch: [
  41. './client/js/**/*.js'
  42. ],
  43. csslibs: [
  44. './node_modules/font-awesome/css/font-awesome.min.css',
  45. './node_modules/highlight.js/styles/default.css',
  46. './node_modules/simplemde/dist/simplemde.min.css'
  47. ],
  48. cssapps: [
  49. './client/scss/app.scss'
  50. ],
  51. cssapps_watch: [
  52. './client/scss/**/*.scss'
  53. ],
  54. cssapps_imports: [
  55. './node_modules/bulma/'
  56. ],
  57. fonts: [
  58. './node_modules/font-awesome/fonts/*-webfont.*',
  59. '!./node_modules/font-awesome/fonts/*-webfont.svg'
  60. ],
  61. deploypackage: [
  62. './**/*',
  63. '!node_modules', '!node_modules/**',
  64. '!coverage', '!coverage/**',
  65. '!client/js', '!client/js/**',
  66. '!client/scss', '!client/scss/**',
  67. '!dist', '!dist/**',
  68. '!tests', '!tests/**',
  69. '!.babelrc', '!.gitattributes', '!.gitignore', '!.snyk', '!.travis.yml',
  70. '!gulpfile.js', '!inch.json', '!config.yml', '!wiki.sublime-project'
  71. ]
  72. };
  73. /**
  74. * TASK - Starts server in development mode
  75. */
  76. gulp.task('server', ['scripts', 'css', 'fonts'], function() {
  77. nodemon({
  78. script: './server',
  79. ignore: ['assets/', 'client/', 'data/', 'repo/', 'tests/'],
  80. ext: 'js json',
  81. env: { 'NODE_ENV': 'development' }
  82. });
  83. });
  84. /**
  85. * TASK - Process all scripts processes
  86. */
  87. gulp.task("scripts", ['scripts-libs', 'scripts-app']);
  88. /**
  89. * TASK - Combine js libraries
  90. */
  91. gulp.task("scripts-libs", function () {
  92. return merge(
  93. gulp.src(paths.scriptlibs)
  94. .pipe(concat('libs.js'))
  95. .pipe(uglify({ mangle: false }))
  96. .pipe(gulp.dest("./assets/js")),
  97. gulp.src(paths.scriptlibs_acemodes)
  98. .pipe(gulp.dest("./assets/js/ace"))
  99. );
  100. });
  101. /**
  102. * TASK - Combine, make compatible and compress js app scripts
  103. */
  104. gulp.task("scripts-app", function () {
  105. return gulp.src(paths.scriptapps)
  106. .pipe(plumber())
  107. .pipe(concat('app.js'))
  108. .pipe(include({ extensions: "js" }))
  109. .pipe(babel())
  110. .pipe(uglify())
  111. .pipe(plumber.stop())
  112. .pipe(gulp.dest("./assets/js"));
  113. });
  114. /**
  115. * TASK - Process all css processes
  116. */
  117. gulp.task("css", ['css-libs', 'css-app']);
  118. /**
  119. * TASK - Combine css libraries
  120. */
  121. gulp.task("css-libs", function () {
  122. return gulp.src(paths.csslibs)
  123. .pipe(plumber())
  124. .pipe(concat('libs.css'))
  125. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  126. .pipe(plumber.stop())
  127. .pipe(gulp.dest("./assets/css"));
  128. });
  129. /**
  130. * TASK - Combine app css
  131. */
  132. gulp.task("css-app", function () {
  133. return gulp.src(paths.cssapps)
  134. .pipe(plumber())
  135. .pipe(sass({
  136. includePaths: paths.cssapps_imports
  137. }))
  138. .pipe(concat('app.css'))
  139. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  140. .pipe(plumber.stop())
  141. .pipe(gulp.dest("./assets/css"));
  142. });
  143. /**
  144. * TASK - Copy web fonts
  145. */
  146. gulp.task("fonts", function () {
  147. return gulp.src(paths.fonts)
  148. .pipe(gulp.dest("./assets/fonts"));
  149. });
  150. /**
  151. * TASK - Start dev watchers
  152. */
  153. gulp.task('watch', function() {
  154. gulp.watch([paths.scriptapps_watch], ['scripts-app']);
  155. gulp.watch([paths.cssapps_watch], ['css-app']);
  156. });
  157. /**
  158. * TASK - Starts development server with watchers
  159. */
  160. gulp.task('default', ['watch', 'server']);
  161. /**
  162. * TASK - Creates deployment packages
  163. */
  164. gulp.task('deploy', ['scripts', 'css', 'fonts'], function() {
  165. var zipStream = gulp.src(paths.deploypackage)
  166. .pipe(zip('requarks-wiki.zip'))
  167. .pipe(gulp.dest('dist'));
  168. var targzStream = gulp.src(paths.deploypackage)
  169. .pipe(tar('requarks-wiki.tar'))
  170. .pipe(gzip())
  171. .pipe(gulp.dest('dist'));
  172. return merge(zipStream, targzStream);
  173. });