Skip to content

Commit 4a47218

Browse files
authored
Cli: Add function filter to codegen (#223)
1 parent eadecbf commit 4a47218

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

.changeset/green-corners-sleep.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@mimicprotocol/test-ts": patch
3+
"@mimicprotocol/cli": patch
4+
"@mimicprotocol/lib-ts": patch
5+
---
6+
7+
Add function filter to codegen

packages/cli/src/commands/codegen.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export default class Codegen extends Command {
2020

2121
static override flags = {
2222
...Functions.flags,
23+
function: Flags.string({
24+
char: 'f',
25+
description: 'Function to use when resolving function configuration',
26+
default: DefaultFunctionConfig.function,
27+
}),
2328
manifest: Flags.string({
2429
char: 'm',
2530
description: 'Specify a custom manifest file path',

packages/cli/src/commands/functions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ export default class Functions extends Command {
4949
default: false,
5050
}),
5151
include: Flags.string({
52-
description: `When ${MIMIC_CONFIG_FILE} exists, only run tasks with these names (space-separated)`,
52+
description: `When ${MIMIC_CONFIG_FILE} exists, only run functions with these names (space-separated)`,
5353
multiple: true,
5454
exclusive: ['exclude'],
5555
char: 'i',
5656
}),
5757
exclude: Flags.string({
58-
description: `When ${MIMIC_CONFIG_FILE} exists, exclude tasks with these names (space-separated)`,
58+
description: `When ${MIMIC_CONFIG_FILE} exists, exclude functions with these names (space-separated)`,
5959
multiple: true,
6060
exclusive: ['include'],
6161
char: 'e',

packages/cli/tests/commands/codegen.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ describe('codegen', () => {
1010
const manifestPath = `${basePath}/manifests/manifest.yaml`
1111
const typesDirectory = `${basePath}/src/types`
1212

13+
beforeEach('clean generated files before each test', () => {
14+
if (fs.existsSync(typesDirectory)) fs.rmSync(typesDirectory, { recursive: true, force: true })
15+
})
16+
1317
afterEach('delete generated files', () => {
14-
if (fs.existsSync(typesDirectory)) fs.rmSync(typesDirectory, { recursive: true })
18+
if (fs.existsSync(typesDirectory)) fs.rmSync(typesDirectory, { recursive: true, force: true })
1519
})
1620

1721
context('when the manifest exists', () => {
@@ -25,6 +29,20 @@ describe('codegen', () => {
2529
expect(fs.existsSync(`${typesDirectory}/ERC20.ts`)).to.be.true
2630
expect(fs.existsSync(`${typesDirectory}/index.ts`)).to.be.true
2731
})
32+
33+
it('accepts the function flag without affecting generated files', async () => {
34+
const { error } = await runCommand([...command, '--function', `${basePath}/functions/function.ts`])
35+
expect(error).to.be.undefined
36+
expect(fs.existsSync(`${typesDirectory}/ERC20.ts`)).to.be.true
37+
expect(fs.existsSync(`${typesDirectory}/index.ts`)).to.be.true
38+
})
39+
40+
it('accepts the function shorthand flag without affecting generated files', async () => {
41+
const { error } = await runCommand([...command, `-f ${basePath}/functions/function.ts`])
42+
expect(error).to.be.undefined
43+
expect(fs.existsSync(`${typesDirectory}/ERC20.ts`)).to.be.true
44+
expect(fs.existsSync(`${typesDirectory}/index.ts`)).to.be.true
45+
})
2846
})
2947

3048
context('when there are no inputs or abis', () => {

0 commit comments

Comments
 (0)