Skip to content

Commit

Permalink
New Command for Clear Option (inkdevhub#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
smnunezleal committed Nov 8, 2023
1 parent 9a9d290 commit a4327af
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/commands/node/clear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { removeDirIfExists } from "./index.js";
import { SwankyCommand } from "../../lib/swankyCommand.js";
import { BUILD_PATH, TEST_PATH, CARGO_PATH } from "./consts.js";

export class clearArtifacts extends SwankyCommand<typeof clearArtifacts> {
await removeDirIfExists(BUILD_PATH);
await removeDirIfExists(TEST_PATH);
await removeDirIfExists(CARGO_PATH);
console.info('Clear command executed successfully');
}
17 changes: 16 additions & 1 deletion src/lib/command-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { execaCommand } from "execa";
import { copy, emptyDir, ensureDir, readJSON } from "fs-extra/esm";
import { copy, emptyDir, ensureDir, readJSON, remove } from "fs-extra/esm";
import path from "node:path";
import { DEFAULT_NETWORK_URL, ARTIFACTS_PATH, TYPED_CONTRACTS_PATH } from "./consts.js";
import { SwankyConfig } from "../types/index.js";
Expand Down Expand Up @@ -120,3 +120,18 @@ export async function generateTypes(contractName: string) {
`npx typechain-polkadot --in ${relativeInputPath} --out ${relativeOutputPath}`
);
}

// Function to remove directory if it exists
export async function removeDirIfExists(path: string): Promise<void> {
try {
await remove(path);
console.info(`Removed ${path}`);
} catch (error) {
if (error.code !== 'ENOENT') {
console.error(`Error clearing ${path}: ${error}`);
throw error;
} else {
console.warn(`${path} does not exist, skipping...`);
}
}
}
4 changes: 4 additions & 0 deletions src/lib/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ export const DEFAULT_SHIBUYA_NETWORK_URL = "wss://shibuya.public.blastapi.io";

export const ARTIFACTS_PATH = "artifacts";
export const TYPED_CONTRACTS_PATH = "typedContracts";

export const BUILD_PATH = "";
export const TEST_PATH = "";
export const CARGO_PATH = "";

0 comments on commit a4327af

Please sign in to comment.