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.

190 lines
4.6 KiB

8 years ago
8 years ago
  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/jquery-simple-upload/simpleUpload.min.js',
  26. './node_modules/jquery-contextmenu/dist/jquery.contextMenu.min.js',
  27. './node_modules/sticky-js/dist/sticky.min.js',
  28. './node_modules/simplemde/dist/simplemde.min.js',
  29. './node_modules/ace-builds/src-min-noconflict/ace.js',
  30. './node_modules/ace-builds/src-min-noconflict/ext-modelist.js',
  31. './node_modules/ace-builds/src-min-noconflict/mode-markdown.js',
  32. './node_modules/ace-builds/src-min-noconflict/theme-tomorrow_night.js',
  33. './node_modules/filesize.js/dist/filesize.min.js',
  34. './node_modules/lodash/lodash.min.js'
  35. ],
  36. scriptlibs_acemodes: [
  37. './node_modules/ace-builds/src-min-noconflict/mode-*.js',
  38. '!./node_modules/ace-builds/src-min-noconflict/mode-markdown.js'
  39. ],
  40. scriptapps: [
  41. './client/js/*.js'
  42. ],
  43. scriptapps_watch: [
  44. './client/js/**/*.js'
  45. ],
  46. csslibs: [
  47. './node_modules/font-awesome/css/font-awesome.min.css',
  48. './node_modules/highlight.js/styles/default.css',
  49. './node_modules/simplemde/dist/simplemde.min.css'
  50. ],
  51. cssapps: [
  52. './client/scss/*.scss'
  53. ],
  54. cssapps_watch: [
  55. './client/scss/**/*.scss'
  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', {newLine: ';\n'}))
  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(include({ extensions: "js" }))
  108. .pipe(babel())
  109. .pipe(uglify())
  110. .pipe(plumber.stop())
  111. .pipe(gulp.dest("./assets/js"));
  112. });
  113. /**
  114. * TASK - Process all css processes
  115. */
  116. gulp.task("css", ['css-libs', 'css-app']);
  117. /**
  118. * TASK - Combine css libraries
  119. */
  120. gulp.task("css-libs", function () {
  121. return gulp.src(paths.csslibs)
  122. .pipe(plumber())
  123. .pipe(concat('libs.css'))
  124. .pipe(cleanCSS({ keepSpecialComments: 0 }))
  125. .pipe(plumber.stop())
  126. .pipe(gulp.dest("./assets/css"));
  127. });
  128. /**
  129. * TASK - Combine app css
  130. */
  131. gulp.task("css-app", function () {
  132. return gulp.src(paths.cssapps)
  133. .pipe(plumber())
  134. .pipe(sass())
  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. });