gulpfile.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 (done) {
  31. return new Promise(function(resolve, reject) {
  32. modules.map(function(module) {
  33. gulp.src('./'+module+'/assets/scripts/*.js')
  34. .pipe(gulpif(prod, stripDebug()))
  35. .pipe(gulpif(prod, jsmin()))
  36. .pipe(rename({suffix: '.min'}))
  37. .pipe(gulp.dest('./'+module+'/assets/dist/scripts/'));
  38. });
  39. resolve();
  40. });
  41. });
  42. gulp.task('styles', function (done) {
  43. return new Promise(function(resolve, reject) {
  44. modules.map(function(module) {
  45. gulp.src('./'+module+'/assets/styles/*.scss')
  46. .pipe(sass().on('error', sass.logError))
  47. .pipe(autoprefixer({
  48. cascade: false
  49. })).on('error', handleError)
  50. .pipe(gulpif(prod, cssmin()))
  51. // .pipe(cssmin())
  52. .pipe(rename({suffix: '.min'}))
  53. .pipe(gulp.dest('./'+module+'/assets/dist/styles/'));
  54. });
  55. resolve();
  56. });
  57. });
  58. // default gulp task
  59. gulp.task('default', gulp.series('scripts', 'styles', done => {
  60. for (var i = 0; i < modules.length; i++) {
  61. gulp.watch('./'+modules[i]+'/assets/styles/*.scss', gulp.series('styles'));
  62. gulp.watch('./'+modules[i]+'/assets/scripts/*.js', gulp.series('scripts'));
  63. }
  64. done()
  65. }));