19657025fSTomasz Sapetaimport chalk from 'chalk';
29657025fSTomasz Sapetaimport fs from 'fs-extra';
39657025fSTomasz Sapeta
4*a272999eSBartosz Kaszubowskiimport { Task } from './Task';
5*a272999eSBartosz Kaszubowski
69657025fSTomasz Sapetaexport type RemoveDirectorySettings = {
79657025fSTomasz Sapeta  target?: string;
89657025fSTomasz Sapeta  name?: string;
99657025fSTomasz Sapeta};
109657025fSTomasz Sapeta
119657025fSTomasz Sapeta/**
129657025fSTomasz Sapeta * A task which will remove the working directory.
139657025fSTomasz Sapeta */
149657025fSTomasz Sapetaexport class RemoveDirectory extends Task {
159657025fSTomasz Sapeta  private target?: string;
169657025fSTomasz Sapeta
179657025fSTomasz Sapeta  constructor({ target }: RemoveDirectorySettings) {
189657025fSTomasz Sapeta    super();
199657025fSTomasz Sapeta    this.target = target;
209657025fSTomasz Sapeta  }
219657025fSTomasz Sapeta
22*a272999eSBartosz Kaszubowski  protected overrideWorkingDirectory(): string {
23*a272999eSBartosz Kaszubowski    return this.target || '<workingDirectory>';
249657025fSTomasz Sapeta  }
259657025fSTomasz Sapeta
269657025fSTomasz Sapeta  async execute() {
279657025fSTomasz Sapeta    const workDirectory = this.getWorkingDirectory();
289657025fSTomasz Sapeta
29*a272999eSBartosz Kaszubowski    this.logSubStep(`�� remove ${chalk.yellow(this.overrideWorkingDirectory())}`);
309657025fSTomasz Sapeta    return await fs.remove(workDirectory);
319657025fSTomasz Sapeta  }
329657025fSTomasz Sapeta}
33