// @ts-check

/**
 * Create gitignore base file
 */
function gitignoreCreate() {
  const gulp = require("gulp");
  const rename = require("gulp-rename");
  const paths = require("../paths");

  return gulp
    .src(paths.join(paths.self.templates, "gitignore"))
    .pipe(rename(".gitignore"))
    .pipe(gulp.dest(paths.root));
}

/**
 * Create gitignore files for Laravel folders
 *
 * @see https://github.com/laravel/laravel
 */
function gitignoreFoldersCreate() {
  const gulp = require("gulp");
  const rename = require("gulp-rename");
  const paths = require("../paths");

  return gulp
    .src(paths.join(paths.self.templates, "gitignore-folder"))
    .pipe(rename(".gitignore"))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/app")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/app/public")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/debugbar")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/framework")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/framework/cache")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/framework/sessions")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/framework/testing")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/framework/views")))
    .pipe(gulp.dest(paths.join(paths.root, "/storage/logs")));
}

/**
 * Collect subtasks in a single task that respect the gulp async lifecycle by
 * calling the callback on completion.
 */
module.exports = function gitignore(callback) {
  const gulp = require("gulp");
  return gulp.parallel(gitignoreCreate, gitignoreFoldersCreate)(callback);
};
