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.

206 lines
5.0 KiB

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