1import chalk from 'chalk';
2import fs from 'fs-extra';
3
4import { Task } from './Task';
5
6export type RemoveDirectorySettings = {
7  target?: string;
8  name?: string;
9};
10
11/**
12 * A task which will remove the working directory.
13 */
14export class RemoveDirectory extends Task {
15  private target?: string;
16
17  constructor({ target }: RemoveDirectorySettings) {
18    super();
19    this.target = target;
20  }
21
22  protected overrideWorkingDirectory(): string {
23    return this.target || '<workingDirectory>';
24  }
25
26  async execute() {
27    const workDirectory = this.getWorkingDirectory();
28
29    this.logSubStep(`�� remove ${chalk.yellow(this.overrideWorkingDirectory())}`);
30    return await fs.remove(workDirectory);
31  }
32}
33