Skip to content

Commit 2d2935a

Browse files
committed
feat: add abstract app guard to cw-plus namespace
1 parent 67b0900 commit 2d2935a

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

.changeset/mighty-icons-flow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@abstract-money/cli": patch
3+
---
4+
5+
Adds a guard to never generate abstractApp for cw-plus namespace and allows a user to configure other namespaces to not generate abstractApp for.

packages/cli/src/plugins/react.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@ const codegen = (_codegen as any).default as typeof _codegen
1414

1515
type ReactResult = RequiredBy<Plugin, 'run'>
1616

17-
export function react(): ReactResult {
17+
const DISABLED_APPSTRACT_APP_FOR_NAMESPACES_LIST = ['cw-plus']
18+
19+
type ReactOptions = {
20+
disableAppstractAppFor?: string[]
21+
}
22+
23+
export function react(options: ReactOptions = {}): ReactResult {
24+
const disableAppstractAppFor = [
25+
...(options.disableAppstractAppFor ?? []),
26+
...DISABLED_APPSTRACT_APP_FOR_NAMESPACES_LIST,
27+
]
28+
1829
return {
1930
name: 'React',
2031
async run({ contracts, out, isTypeScript }) {
@@ -24,7 +35,7 @@ export function react(): ReactResult {
2435
contracts.some(({ name }) => DISALLOWED_CONTRACT_NAMES.includes(name))
2536
)
2637
throw new Error(
27-
'`proxy` and `manager` contract generations are disallowed. Use `@abstract-money/core` methods or `@abstract-money/react` methods',
38+
'`proxy` and `manager` contract generations are disallowed. Use `@abstract-money/core` methods or `@abstract-money/react` hooks.',
2839
)
2940

3041
// Prepare default config options
@@ -46,12 +57,37 @@ export function react(): ReactResult {
4657

4758
const cosmwasmCodegenDirPath = join(out, 'cosmwasm-codegen')
4859

60+
// Guard speicfic contracts to not have the abstract app generated
61+
const guardedContracts = contracts.filter(({ namespace }) =>
62+
disableAppstractAppFor.includes(namespace),
63+
)
64+
4965
await codegen({
5066
options: codegenOptions,
51-
contracts: contracts.map(({ name, path }) => ({ name, dir: path })),
67+
contracts: contracts
68+
.filter(
69+
({ namespace }) =>
70+
!disableAppstractAppFor.includes(namespace) &&
71+
guardedContracts.every(
72+
(guardedContract) => guardedContract.namespace !== namespace,
73+
),
74+
)
75+
.map(({ name, path }) => ({ name, dir: path })),
5276
outPath: cosmwasmCodegenDirPath,
5377
})
5478

79+
if (guardedContracts.length !== 0)
80+
await codegen({
81+
options: { ...codegenOptions, abstractApp: { enabled: false } },
82+
contracts: [
83+
...guardedContracts,
84+
...contracts.filter(({ namespace }) =>
85+
disableAppstractAppFor.includes(namespace),
86+
),
87+
].map(({ name, path }) => ({ name, dir: path })),
88+
outPath: cosmwasmCodegenDirPath,
89+
})
90+
5591
const imports: string[] = []
5692
const content: string[] = []
5793

0 commit comments

Comments
 (0)