Skip to content

Commit f928262

Browse files
authored
feat: graph clean command (#1363)
1 parent dab4ca1 commit f928262

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

.changeset/seven-kiwis-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': minor
3+
---
4+
5+
add `graph clean` command to delete generated artifacts

packages/cli/src/commands/clean.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Command, Flags } from '@oclif/core';
2+
import { print, filesystem } from 'gluegun';
3+
4+
export default class CleanCommand extends Command {
5+
static description = 'Clean the cache and generated files.';
6+
7+
static flags = {
8+
help: Flags.help({
9+
char: 'h',
10+
}),
11+
'codegen-dir': Flags.directory({
12+
summary: 'Directory where the "graph codegen" code is stored.',
13+
default: 'generated/',
14+
}),
15+
'build-dir': Flags.directory({
16+
summary: 'Directory where the "graph build" code is stored.',
17+
default: 'build/',
18+
}),
19+
};
20+
21+
async run() {
22+
const {
23+
flags: { 'codegen-dir': codegenDir, 'build-dir': buildDir },
24+
} = await this.parse(CleanCommand);
25+
const spinner = print.spin(`Cleaning cache and generated files`);
26+
27+
spinner.start();
28+
try {
29+
await filesystem.removeAsync(codegenDir);
30+
await filesystem.removeAsync(buildDir);
31+
spinner.succeed();
32+
print.success('Cache and generated files cleaned');
33+
} catch (e) {
34+
spinner.fail('Failed to clean cache and generated files');
35+
} finally {
36+
spinner.stop();
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)