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.

178 lines
4.0 KiB

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