const gulp = require("gulp");
const css = require("gulp-cssimport");
const sass = require("gulp-sass");
const tildeImporter = require("node-sass-tilde-importer");
const classPrefix = require("gulp-class-prefix");
const rtlcss = require("gulp-rtlcss");
const cleanCSS = require("gulp-clean-css");
const rename = require("gulp-rename");
const tasks = [];

gulp.task(`compile-themes`, () =>
  gulp
    .src(`index.scss`)
    .pipe(sass())
    .pipe(css())
    .pipe(gulp.dest(`./`))
);

gulp.task(`compile-themes-rtl`, () =>
  gulp
    .src(`index.rtl.scss`)
    .pipe(sass())
    .pipe(css())
    .pipe(gulp.dest(`./`))
);

gulp.task(`compile-themes-bootstrap4`, () => {
  gulp
    .src(`bootstrap4/index.scss`)
    .pipe(
      sass({
        includePaths: ["node_modules"],
        importer: tildeImporter
      })
    )
    .pipe(classPrefix("fr-", { ignored: [".fa"] }))
    .pipe(css())
    .pipe(gulp.dest(`./bootstrap4/`));
  return gulp
    .src(`bootstrap4/index.scss`)
    .pipe(
      sass({
        includePaths: ["node_modules"],
        importer: tildeImporter
      })
    )
    .pipe(classPrefix("fr-", { ignored: [".fa"] }))
    .pipe(cleanCSS())
    .pipe(css())
    .pipe(rename("index.min.css"))
    .pipe(gulp.dest(`./bootstrap4/`));
});

gulp.task(`compile-themes-rtl-bootstrap4`, () => {
  gulp
    .src(`bootstrap4/index.rtl.scss`)
    .pipe(
      sass({
        includePaths: ["node_modules"],
        importer: tildeImporter
      })
    )
    .pipe(classPrefix("fr-"))
    .pipe(rtlcss())
    .pipe(css())
    .pipe(gulp.dest(`./bootstrap4/`));
  return gulp
    .src(`bootstrap4/index.rtl.scss`)
    .pipe(
      sass({
        includePaths: ["node_modules"],
        importer: tildeImporter
      })
    )
    .pipe(classPrefix("fr-"))
    .pipe(rtlcss())
    .pipe(css())
    .pipe(cleanCSS())
    .pipe(rename("index.rtl.min.css"))
    .pipe(gulp.dest(`./bootstrap4/`));
});
