UNPKG

sekrab-gulpbin

Version:

sekrab gulp tasks shared amongst shut cricket and other libs

120 lines (90 loc) 3.32 kB
// replaceing gulp-cssmin with gulp-clean-css, the output is almost the same // removing autoprefixer, should never rely on unsupported features in shut // this is a replicate of assets because i want to generate shut files here const gulp = require('gulp'); const less = require('gulp-less'); const cleancss = require('gulp-clean-css'); const rename = require('gulp-rename'); const concat = require('gulp-concat'); let options = require('./config.json'); // save sh.css in src/css/ const fwCss = function () { const { shutPath } = options; return gulp .src(shutPath + 'less/sh.less') .pipe(less()) .on('error', function (err) { console.log(err); this.emit('end'); }) // .pipe(rename({ basename: 'sh' })) .pipe(gulp.dest(shutPath + 'css')) .on('error', console.error.bind(console)); }; const fwRtlCss = function () { const { shutPath } = options; return gulp .src(shutPath + 'less/sh.rtl.less') .pipe(less()) .pipe(gulp.dest(shutPath + 'css')) .on('error', console.error.bind(console)); }; // minify src/css/sh.css into dist/css/sh.min.css const fwBuildCss = function () { const { shutPath, shutDistUrl } = options; return gulp .src(shutPath + 'css/sh.css') .pipe(cleancss({ // level: 2 did not produce the same output level: { 2: { all: true } } })) .pipe(rename({ basename: 'sh', suffix: '.min' })) .pipe(gulp.dest(shutDistUrl + 'css')); }; // minify src/css/sh.rtl.css into dist/css/sh.rtl.min.css const fwBuildRtlCss = function () { const { shutPath, shutDistUrl } = options; return gulp .src(shutPath + 'css/sh.rtl.css') // fix this .pipe(cleancss({ level: { 2: { all: true } } })) .pipe(rename({ basename: 'sh', suffix: '.rtl.min' })) .pipe(gulp.dest(shutDistUrl + 'css')); }; // copy fonts to dist/ const fwDistResources = function () { const { shutPath, shutDistUrl } = options; return gulp .src(shutPath + 'fonts/*', { base: shutPath }) .pipe(gulp.dest(shutDistUrl)); }; module.exports = (config) => { // one time use, change if i want more flexibility options = { ...config.assets }; const ret = {}; if (options.isRtl) { ret.rawshut = gulp.series(fwCss, fwRtlCss); ret.buildshut = gulp.series(ret.rawshut, gulp.parallel(fwDistResources, fwBuildCss, fwBuildRtlCss)); ret.watch = function () { gulp.watch(options.shutPath + 'less/(sh|css|rtl){1,}\.*.less', { ignoreInitial: false }, gulp.series(fwCss, fwRtlCss)); }; } else { ret.rawshut = fwCss; ret.buildshut = gulp.parallel(fwDistResources, gulp.series(fwCss, fwBuildCss)); ret.watch = function () { // place code for your default task here gulp.watch(options.shutPath + 'less/(sh|css){1,}\.*.less', { ignoreInitial: false }, fwCss); } } return ret; }