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.

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