Skip to content

Commit

Permalink
Fix: Fixed the problems with observations
Browse files Browse the repository at this point in the history
  • Loading branch information
Juminstock committed Nov 2, 2023
1 parent 93aa5dc commit af9f441
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/backlog-ticket.md
Original file line number Diff line number Diff line change
@@ -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: ''

Expand All @@ -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.}
{Dependencies issue or PR or some other blocker.}
55 changes: 16 additions & 39 deletions src/commands/clear/index.ts
Original file line number Diff line number Diff line change
@@ -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}

Check failure on line 7 in src/commands/clear/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

Use an `interface` instead of a `type`

Expand All @@ -25,27 +23,21 @@ export default class Clear extends SwankyCommand<typeof Clear> {
}),
};

static async deleteFolder(path: string): Promise<void> {
async deleteFolder(path: string): Promise<void> {
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<any> {

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[] = []

Check failure on line 43 in src/commands/clear/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

'foldersToDelete' is never reassigned. Use 'const' instead
Expand All @@ -60,15 +52,11 @@ export default class Clear extends SwankyCommand<typeof Clear> {
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),

Check failure on line 56 in src/commands/clear/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

'resultSpinner' is never reassigned. Use 'const' instead

Check failure on line 56 in src/commands/clear/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

'resultSpinner' is assigned a value but never used
`Deleting the ${folder.name} folder`
)
}
} else if (args.contractName) {

foldersToDelete.push({
Expand All @@ -79,27 +67,16 @@ export default class Clear extends SwankyCommand<typeof Clear> {
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),

Check failure on line 76 in src/commands/clear/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

'resultSpinner' is never reassigned. Use 'const' instead

Check failure on line 76 in src/commands/clear/index.ts

View workflow job for this annotation

GitHub Actions / lint-check

'resultSpinner' is assigned a value but never used
`Deleting the ${folder.name} folder`
)
}
}
}
}

0 comments on commit af9f441

Please sign in to comment.