gulpfile.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. 'use strict';
  2. import gulp from 'gulp';
  3. const { series, src, dest, watch } = gulp;
  4. import gulpif from 'gulp-if';
  5. import * as dartSass from 'sass';
  6. import gulpSass from 'gulp-sass';
  7. const sass = gulpSass(dartSass);
  8. import autoprefixer from 'gulp-autoprefixer';
  9. import stripDebug from 'gulp-strip-debug';
  10. import jsmin from 'gulp-jsmin';
  11. import cssmin from 'gulp-cssmin';
  12. import rename from 'gulp-rename';
  13. import minimist from 'minimist';
  14. // var es = require('event-stream');
  15. var modules = [
  16. {
  17. modname:'edlp_studio',
  18. srcjs:['./edlp_studio/assets/scripts/edlp_studio.js']
  19. },
  20. {
  21. modname:'edlp_search',
  22. srcjs:['./edlp_search/assets/scripts/edlp_search.js']
  23. },
  24. {
  25. modname:'edlp_corpus',
  26. srcjs:['./edlp_corpus/assets/scripts/corpus.js', './edlp_corpus/assets/scripts/physics.js'],
  27. srccss:['./edlp_corpus/assets/styles/corpus.scss']
  28. }];
  29. // to get minified assets run `gulp --env=prod`
  30. var argv = minimist(process.argv.slice(2));
  31. console.dir(argv);
  32. var prod = argv.env === 'prod' ? true : false;
  33. function handleError(err) {
  34. console.log(err.toString());
  35. }
  36. function scripts() {
  37. return new Promise(function(resolve, reject) {
  38. modules.map(function(module) {
  39. // console.log('module', module);
  40. src(module.srcjs, {allowEmpty: true})
  41. .on('data', function(file) {
  42. console.log('File src:', file.path);
  43. })
  44. .pipe(gulpif(prod, stripDebug()))
  45. .pipe(gulpif(prod, jsmin()))
  46. .pipe(rename({suffix: '.min'}))
  47. .pipe(dest(`./${module.modname}/assets/dist/scripts/`));
  48. // .on('data', function(file) {
  49. // console.log('File dest:', file.path);
  50. // });
  51. });
  52. resolve();
  53. });
  54. // return src(['./edlp_studio/assets/scripts/edlp_studio.js'])
  55. // .pipe(gulpif(prod, stripDebug()))
  56. // .pipe(gulpif(prod, jsmin()))
  57. // .pipe(rename({suffix: '.min'}))
  58. // .pipe(dest('./edlp_studio/assets/dist/scripts/'));
  59. };
  60. function styles() {
  61. return new Promise(function(resolve, reject) {
  62. modules.map(function(module) {
  63. if (module.srccss) {
  64. src(module.srccss, {allowEmpty: true})
  65. .pipe(sass().on('error', sass.logError))
  66. .pipe(autoprefixer({
  67. cascade: false
  68. })).on('error', handleError)
  69. .pipe(gulpif(prod, cssmin()))
  70. // .pipe(cssmin())
  71. .pipe(rename({suffix: '.min'}))
  72. .pipe(dest('./'+module.modname+'/assets/dist/styles/'));
  73. }
  74. });
  75. resolve();
  76. });
  77. // return src('./edlp_studio/assets/styles/*.scss')
  78. // .pipe(sass().on('error', sass.logError))
  79. // .pipe(autoprefixer({
  80. // cascade: false
  81. // })).on('error', handleError)
  82. // .pipe(gulpif(prod, cssmin()))
  83. // // .pipe(cssmin())
  84. // .pipe(rename({suffix: '.min'}))
  85. // .pipe(dest('./edlp_studio/assets/dist/styles/'));
  86. };
  87. // default gulp task
  88. function devwatch () {
  89. // series(scripts, styles, done => {
  90. for (var i = 0; i < modules.length; i++) {
  91. watch('./'+modules[i].modname+'/assets/styles/*.scss', styles);
  92. watch('./'+modules[i].modname+'/assets/scripts/*.js', scripts);
  93. }
  94. // done()
  95. // })
  96. };
  97. export default series(scripts, styles); //
  98. export { devwatch }