// @ts-check

/**
 * Clean the Laravel caches
 */
function clear(callback) {
  const { execSync } = require("child_process");

  execSync(
    "php artisan config:clear && php artisan route:clear && php artisan view:clear && php artisan cache:clear && php artisan page-cache:clear"
  );

  return callback();
}

/**
 * Clean storage and public
 */
function cleanStorageAndPublic(callback) {
  const del = require("del");
  const paths = require("../paths");

  return del([
    paths.join(paths.root, "storage/**/*"),
    paths.join(paths.frontend.dest.assets),
    paths.join(paths.frontend.dest.public, "page-cache"),
  ]);
}

/**
 * Clean all generated files
 */
function clean(callback) {
  const gulp = require("gulp");
  const { tplClean } = require("./tpl");
  const { assetsClean } = require("./assets");

  return gulp.parallel(tplClean, assetsClean, cleanStorageAndPublic)(callback);
}

/**
 * Wipe out everything both `clean` and `clear`
 */
function wipe(callback) {
  const gulp = require("gulp");
  return gulp.parallel(clear, clean)(callback);
}

module.exports = {
  clean,
  clear,
  wipe,
};
