'use strict';

const { parallel, src, dest } = require('gulp');
const dartSass = require('sass');
const gulpSass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const cssmin = require('gulp-cssmin');
const consola = require('consola');
const chalk = require('chalk');

const sass = gulpSass(dartSass);

function compile() {
  return src('./src/*.scss')
    .pipe(sass.sync())
    .pipe(autoprefixer({
      cascade: false
    }))
    .pipe(cleanCSS({}, (details) => {
      consola.success(
        `${chalk.cyan(details.name)}: ${chalk.yellow(
          details.stats.originalSize / 1000
        )} KB -> ${chalk.green(details.stats.minifiedSize / 1000)} KB`
      );
    }))
    // .pipe(cssmin())
    .pipe(dest('./lib'));
}

function copyfont() {
  return src('./src/fonts/**')
    .pipe(cssmin())
    .pipe(dest('./lib/fonts'));
}

exports.build = parallel(compile, copyfont);
