'use strict'; import gulp from 'gulp'; const { series, src, dest, watch } = gulp; import gulpif from 'gulp-if'; import * as dartSass from 'sass'; import gulpSass from 'gulp-sass'; const sass = gulpSass(dartSass); import autoprefixer from 'gulp-autoprefixer'; import stripDebug from 'gulp-strip-debug'; import jsmin from 'gulp-jsmin'; import cssmin from 'gulp-cssmin'; import rename from 'gulp-rename'; import minimist from 'minimist'; // var es = require('event-stream'); var modules = ['edlp_corpus', 'edlp_studio', 'edlp_search']; // to get minified assets run `gulp --env=prod` var argv = minimist(process.argv.slice(2)); console.dir(argv); var prod = argv.env == 'prod' ? true : false; function handleError(err) { console.log(err.toString()); } function scripts() { return new Promise(function(resolve, reject) { modules.map(function(module) { src('./'+module+'/assets/scripts/*.js') .pipe(gulpif(prod, stripDebug())) .pipe(gulpif(prod, jsmin())) .pipe(rename({suffix: '.min'})) .pipe(gulp.dest('./'+module+'/assets/dist/scripts/')); }); resolve(); }); }; function styles() { return new Promise(function(resolve, reject) { modules.map(function(module) { src('./'+module+'/assets/styles/*.scss') .pipe(sass().on('error', sass.logError)) .pipe(autoprefixer({ cascade: false })).on('error', handleError) .pipe(gulpif(prod, cssmin())) // .pipe(cssmin()) .pipe(rename({suffix: '.min'})) .pipe(gulp.dest('./'+module+'/assets/dist/styles/')); }); resolve(); }); }; // default gulp task function devwatch () { // series(scripts, styles, done => { for (var i = 0; i < modules.length; i++) { watch('./'+modules[i]+'/assets/styles/*.scss', styles); watch('./'+modules[i]+'/assets/scripts/*.js', scripts); } // done() // }) }; export default series(scripts, styles); export { devwatch }