diff --git a/.github/ISSUE_TEMPLATE/backlog-ticket.md b/.github/ISSUE_TEMPLATE/backlog-ticket.md index 23ec03d9..1d1fab10 100644 --- a/.github/ISSUE_TEMPLATE/backlog-ticket.md +++ b/.github/ISSUE_TEMPLATE/backlog-ticket.md @@ -1,7 +1,7 @@ --- -name: Clear command -about: New feature/clearCommand -title: 'Clear command' +name: Backlog Ticket +about: New feature/ticket for the project +title: '' labels: '' assignees: '' @@ -24,4 +24,4 @@ assignees: '' - [ ] PR approved and merged to master (delete if not applicable) # Open Issues and Blockers -{Dependencies issue or PR or some other blocker.} \ No newline at end of file +{Dependencies issue or PR or some other blocker.} diff --git a/src/commands/clear/index.ts b/src/commands/clear/index.ts index 2761a4bd..0d43a400 100644 --- a/src/commands/clear/index.ts +++ b/src/commands/clear/index.ts @@ -1,10 +1,8 @@ -import { Spinner } from "../../lib/index.js"; import { SwankyCommand } from "../../lib/swankyCommand.js"; import { ConfigError, FileError } from "../../lib/errors.js"; import fs from "fs-extra" -import path from "path" +import path from "node:path" import { Args, Flags } from "@oclif/core"; -import { flagUsage } from "@oclif/core/lib/parser/help.js"; type Folder = {name: string, contractName?: string, path: string} @@ -25,27 +23,21 @@ export default class Clear extends SwankyCommand { }), }; - static async deleteFolder(path: string): Promise { + async deleteFolder(path: string): Promise { try { await fs.remove(path); } catch (err) { throw new FileError( - `Error while to delete the folder ${path}: ${err}Error while to delete the folder ${path}: ${err}` + `Error deleting the folder ${path}.`, {cause: err} ); } } public async run(): Promise { - const spinner = new Spinner(); - const { flags, args } = await this.parse(Clear); - if(!flags.all && !args.contractName) throw new ConfigError("You need to send any flag or argument.") - - if(flags.all && args.contractName) { - throw new ConfigError("You can't sent the flag '-a' or '--all' and argument in the same time.") - } + if(args.contractName === undefined && !flags.all) throw new ConfigError("You need to send any flag or argument.") const workDirectory = process.cwd(); let foldersToDelete: Folder[] = [] @@ -60,15 +52,11 @@ export default class Clear extends SwankyCommand { path: path.join(workDirectory, './target') }) - foldersToDelete.map(async (folder) => { - - this.log(`Deleting the ${folder.name} folder`) - - // await spinner.runCommand(async () => - await Clear.deleteFolder(folder.path) - // , `Deleting the ${folder.name} folder`, `The folder has been deleted`); - - }) + for await (const folder of foldersToDelete) { + let resultSpinner = await this.spinner.runCommand( async () => this.deleteFolder(folder.path), + `Deleting the ${folder.name} folder` + ) + } } else if (args.contractName) { foldersToDelete.push({ @@ -79,27 +67,16 @@ export default class Clear extends SwankyCommand { name: "Target", path: path.join(workDirectory, './target') }, { - name: "Test", + name: "TestArtifacts", contractName: args.contractName, path: path.join(workDirectory, './tests/', args.contractName, "/artifacts") }) - - foldersToDelete.map(async (folder) => { - - if (fs.existsSync(folder.path)) { - - this.log(`Deleting the ${folder.name} folder`) - - // await spinner.runCommand(async () => - await Clear.deleteFolder(folder.path) - // , `Deleting the ${folder.name} folder`, `The folder has been deleted`); - - } else { - throw new FileError( - `Path to contract ${args.contractName} does not exist: ${folder.path}` - ); - } - } ) + + for await (const folder of foldersToDelete) { + let resultSpinner = await this.spinner.runCommand( async () => this.deleteFolder(folder.path), + `Deleting the ${folder.name} folder` + ) + } } } } \ No newline at end of file