Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/green-corners-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@mimicprotocol/test-ts": patch
"@mimicprotocol/cli": patch
"@mimicprotocol/lib-ts": patch
---

Add function filter to codegen
5 changes: 5 additions & 0 deletions packages/cli/src/commands/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export default class Codegen extends Command {

static override flags = {
...Functions.flags,
function: Flags.string({
char: 'f',
description: 'Function to use when resolving function configuration',
default: DefaultFunctionConfig.function,
}),
manifest: Flags.string({
char: 'm',
description: 'Specify a custom manifest file path',
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ export default class Functions extends Command {
default: false,
}),
include: Flags.string({
description: `When ${MIMIC_CONFIG_FILE} exists, only run tasks with these names (space-separated)`,
description: `When ${MIMIC_CONFIG_FILE} exists, only run functions with these names (space-separated)`,
multiple: true,
exclusive: ['exclude'],
char: 'i',
}),
exclude: Flags.string({
description: `When ${MIMIC_CONFIG_FILE} exists, exclude tasks with these names (space-separated)`,
description: `When ${MIMIC_CONFIG_FILE} exists, exclude functions with these names (space-separated)`,
multiple: true,
exclusive: ['include'],
char: 'e',
Expand Down
20 changes: 19 additions & 1 deletion packages/cli/tests/commands/codegen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ describe('codegen', () => {
const manifestPath = `${basePath}/manifests/manifest.yaml`
const typesDirectory = `${basePath}/src/types`

beforeEach('clean generated files before each test', () => {
if (fs.existsSync(typesDirectory)) fs.rmSync(typesDirectory, { recursive: true, force: true })
})

afterEach('delete generated files', () => {
if (fs.existsSync(typesDirectory)) fs.rmSync(typesDirectory, { recursive: true })
if (fs.existsSync(typesDirectory)) fs.rmSync(typesDirectory, { recursive: true, force: true })
})

context('when the manifest exists', () => {
Expand All @@ -25,6 +29,20 @@ describe('codegen', () => {
expect(fs.existsSync(`${typesDirectory}/ERC20.ts`)).to.be.true
expect(fs.existsSync(`${typesDirectory}/index.ts`)).to.be.true
})

it('accepts the function flag without affecting generated files', async () => {
const { error } = await runCommand([...command, '--function', `${basePath}/functions/function.ts`])
expect(error).to.be.undefined
expect(fs.existsSync(`${typesDirectory}/ERC20.ts`)).to.be.true
expect(fs.existsSync(`${typesDirectory}/index.ts`)).to.be.true
})

it('accepts the function shorthand flag without affecting generated files', async () => {
const { error } = await runCommand([...command, `-f ${basePath}/functions/function.ts`])
expect(error).to.be.undefined
expect(fs.existsSync(`${typesDirectory}/ERC20.ts`)).to.be.true
expect(fs.existsSync(`${typesDirectory}/index.ts`)).to.be.true
})
})

context('when there are no inputs or abis', () => {
Expand Down
Loading