gulpfile.mjs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. import gulp from 'gulp';
  12. const { series, src, dest, watch } = gulp;
  13. import gulpif from 'gulp-if';
  14. import * as dartSass from 'sass';
  15. import gulpSass from 'gulp-sass';
  16. const sass = gulpSass(dartSass);
  17. import autoprefixer from 'gulp-autoprefixer';
  18. import stripDebug from 'gulp-strip-debug';
  19. import jsmin from 'gulp-jsmin';
  20. import cssmin from 'gulp-cssmin';
  21. import rename from 'gulp-rename';
  22. import minimist from 'minimist';
  23. // var es = require('event-stream');
  24. var modules = ['edlp_corpus', 'edlp_studio', 'edlp_search'];
  25. // to get minified assets run `gulp --env=prod`
  26. var argv = minimist(process.argv.slice(2));
  27. console.dir(argv);
  28. var prod = argv.env == 'prod' ? true : false;
  29. function handleError(err) {
  30. console.log(err.toString());
  31. }
  32. function scripts() {
  33. return new Promise(function(resolve, reject) {
  34. modules.map(function(module) {
  35. src('./'+module+'/assets/scripts/*.js')
  36. .pipe(gulpif(prod, stripDebug()))
  37. .pipe(gulpif(prod, jsmin()))
  38. .pipe(rename({suffix: '.min'}))
  39. .pipe(gulp.dest('./'+module+'/assets/dist/scripts/'));
  40. });
  41. resolve();
  42. });
  43. };
  44. function styles() {
  45. return new Promise(function(resolve, reject) {
  46. modules.map(function(module) {
  47. src('./'+module+'/assets/styles/*.scss')
  48. .pipe(sass().on('error', sass.logError))
  49. .pipe(autoprefixer({
  50. cascade: false
  51. })).on('error', handleError)
  52. .pipe(gulpif(prod, cssmin()))
  53. // .pipe(cssmin())
  54. .pipe(rename({suffix: '.min'}))
  55. .pipe(gulp.dest('./'+module+'/assets/dist/styles/'));
  56. });
  57. resolve();
  58. });
  59. };
  60. // default gulp task
  61. function defaultTask () {
  62. series('scripts', 'styles', done => {
  63. for (var i = 0; i < modules.length; i++) {
  64. watch('./'+modules[i]+'/assets/styles/*.scss', series('styles'));
  65. watch('./'+modules[i]+'/assets/scripts/*.js', series('scripts'));
  66. }
  67. done()
  68. })
  69. };
  70. function devwatch(){
  71. watch('./assets/styles/*.scss', series('styles'));
  72. watch('./assets/styles/base/*.scss', series('styles'));
  73. watch('./assets/scripts/*.js', series('scripts'));
  74. }
  75. export {
  76. scripts as scripts,
  77. styles as styles,
  78. devwatch as devwatch,
  79. defaultTask as default
  80. }