gulpfile.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @Author: Bachir Soussi Chiadmi <bach>
  3. * @Date: 20-12-2017
  4. * @Email: bachir@figureslibres.io
  5. * @Filename: gulpfile.js
  6. * @Last modified by: bach
  7. * @Last modified time: 20-12-2017
  8. * @License: GPL-V3
  9. */
  10. 'use strict';
  11. var gulp = require('gulp');
  12. var gulpif = require('gulp-if');
  13. var sass = require('gulp-sass');
  14. var watch = require('gulp-watch');
  15. var autoprefixer = require('gulp-autoprefixer');
  16. var stripDebug = require('gulp-strip-debug');
  17. var jsmin = require('gulp-jsmin');
  18. var cssmin = require('gulp-cssmin');
  19. var rename = require('gulp-rename');
  20. // var mainBowerFiles = require('main-bower-files');
  21. var es = require('event-stream');
  22. var modules = ['edlp_corpus', 'edlp_studio', 'edlp_search'];
  23. // to get minified assets run `gulp --env=prod`
  24. var argv = require('minimist')(process.argv.slice(2));
  25. console.dir(argv);
  26. var prod = argv.env == 'prod' ? true : false;
  27. function handleError(err) {
  28. console.log(err.toString());
  29. }
  30. gulp.task('scripts', function () {
  31. var tasks = modules.map(function(module) {
  32. return gulp.src('./'+module+'/assets/scripts/*.js')
  33. .pipe(gulpif(prod, stripDebug()))
  34. .pipe(gulpif(prod, jsmin()))
  35. .pipe(rename({suffix: '.min'}))
  36. .pipe(gulp.dest('./'+module+'/assets/dist/scripts/'));
  37. });
  38. return es.merge.apply(null, tasks);
  39. });
  40. gulp.task('styles', function () {
  41. var tasks = modules.map(function(module) {
  42. return gulp.src('./'+module+'/assets/styles/*.scss')
  43. .pipe(sass().on('error', sass.logError))
  44. .pipe(autoprefixer({
  45. browsers: ['last 2 versions'],
  46. cascade: false
  47. })).on('error', handleError)
  48. .pipe(gulpif(prod, cssmin()))
  49. // .pipe(cssmin())
  50. .pipe(rename({suffix: '.min'}))
  51. .pipe(gulp.dest('./'+module+'/assets/dist/styles/'));
  52. });
  53. return es.merge.apply(null, tasks);
  54. });
  55. // default gulp task
  56. gulp.task('default', ['scripts', 'styles'], function() { //'bower',
  57. for (var i = 0; i < modules.length; i++) {
  58. // gulp.watch('./assets/styles/*/*.scss', ['styles']);
  59. gulp.watch('./'+modules[i]+'/assets/styles/*.scss', ['styles']);
  60. gulp.watch('./'+modules[i]+'/assets/scripts/*.js', ['scripts']);
  61. }
  62. });