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.

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