'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 mainBowerFiles from 'main-bower-files'; import svgmin from 'gulp-svgmin'; import minimist from 'minimist'; // var shared_variables = JSON.parse(fs.readFileSync('./assets/json/shared_variables.json')); // 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 src(['./assets/scripts/main.js', './assets/scripts/redirect.js']) // './assets/scripts/shared_variables.js', // .pipe(concat('main.js')) .pipe(gulpif(prod, stripDebug())) .pipe(gulpif(prod, jsmin())) .pipe(rename({suffix: '.min'})) .pipe(dest('./assets/dist/scripts/')); }; function styles() { return src(['./assets/styles/app.scss']) .pipe(sass().on('error', sass.logError)) .pipe(autoprefixer({ browsers: ['last 2 versions'], cascade: false })).on('error', handleError) // .pipe(prod ? cssmin() : util.noop()) .pipe(gulpif(prod, cssmin())) // .pipe(cssmin()) .pipe(rename({suffix: '.min'})) .pipe(gulp.dest('./assets/dist/styles/')); }; function bower(){ return src(mainBowerFiles({ "overrides":{ "masonry-layout":{ "main":"./dist/masonry.pkgd.min.js" }, "imagesloaded":{ "main":"./imagesloaded.pkgd.min.js" }, "jquery":{"ignore":true}, "ev-emitter":{"ignore":true}, "fizzy-ui-utils":{"ignore":true}, "get-size":{"ignore":true}, "outlayer":{"ignore":true}, } })) .pipe(gulp.dest('./assets/dist/bower/')); }; function minsvg(){ return src(['./assets/img/*.svg', '!./assets/img/edlp-loader-anim.svg']) .pipe(svgmin()) .pipe(gulp.dest('./assets/dist/img')); }; function svg(){ return src('./assets/img/edlp-loader-anim.svg') .pipe(gulp.dest('./assets/dist/img')); }; function devwatch(){ watch('./assets/styles/*.scss', series('styles')); watch('./assets/styles/base/*.scss', series('styles')); watch('./assets/scripts/*.js', series('scripts')); watch('./assets/img/*.svg', series('svg')); } // default gulp task // , 'vars2sass' 'vars2js', // gulp.task('default', ['bower', 'scripts', 'styles', 'svg'], function() { // gulp.task('default', gulp.series('bower', 'scripts', 'styles', 'svg', function(done) { // // gulp.watch('./assets/json/*.json', ['vars2js', 'styles', 'scripts']); //, 'vars2sass' // gulp.watch('./assets/styles/*.scss', gulp.series('styles')); // gulp.watch('./assets/styles/base/*.scss', gulp.series('styles')); // gulp.watch('./assets/scripts/*.js', gulp.series('scripts')); // gulp.watch('./assets/img/*.svg', gulp.series('svg')); // done() // })); function defaultTask(){series('bower', 'scripts', 'styles', 'svg', 'minsvg', 'devwatch')}; export { scripts as scripts, styles as styles, bower as bower, svg as svg, minsvg as minsvg, devwatch as devwatch, defaultTask as default } // this task stays here just for memeomry about how to share variables between js and css // gulp.task('vars2sass', function () { // gulp.src('./assets/json/shared_variables.json') // .pipe(jsonToSass({ // jsonPath: './assets/json/shared_variables.json', // scssPath: './assets/styles/base/_shared_variables.scss' // })); // }); // this one is not working, works first run but then it's like it's caching the source // gulp.task('variables2js', function() { // gulp.src('./assets/scripts/shared_variables_model.js') // .pipe(rename('shared_variables.js')) // .pipe(data(function(file) { // delete require.cache['./assets/json/shared_variables.json']; // return require('./assets/json/shared_variables.json'); // })) // .pipe(json2js()) // .pipe(gulp.dest('./assets/scripts/')); // }); // gulp.task('vars2js', function() { // gulp.src('./assets/json/shared_variables.json') // .pipe(rename('shared_variables.js')) // .pipe(through.obj(function (file, enc, cb) { // // console.log('file',String(file.contents)); // // small pipe to wrappe json data into a js variable // file.contents = new Buffer("edlp_vars = "+String(file.contents).trim()+";"); // cb(null, file); // })) // .pipe(gulp.dest('./assets/scripts/')); // });