Skip to content

Commit 10473c1

Browse files
authored
refactor(brownie): hide kotlin codegen until ready for release (#192)
- Remove kotlin from default platforms, require explicit -p kotlin - Make brownie config optional in package.json - Update docs to remove kotlin references - Update tests for new behavior
1 parent 74a4028 commit 10473c1

File tree

8 files changed

+32
-134
lines changed

8 files changed

+32
-134
lines changed

apps/RNApp/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,5 @@
4949
},
5050
"engines": {
5151
"node": ">=20"
52-
},
53-
"brownie": {
54-
"kotlin": "./android/BrownfieldLib/src/main/java/com/rnapp/brownfieldlib/Generated",
55-
"kotlinPackageName": "com.rnapp.brownfieldlib"
5652
}
5753
}

apps/TesterIntegrated/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,5 @@
3535
},
3636
"engines": {
3737
"node": ">=20"
38-
},
39-
"brownie": {
40-
"swift": "./swift/Generated",
41-
"kotlin": "./kotlin/app/src/main/java/com/callstack/kotlinexample/Generated",
42-
"kotlinPackageName": "com.callstack.kotlinexample"
4338
}
4439
}

docs/docs/brownie/codegen.mdx

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,15 @@ The Brownfield CLI generates native types from your TypeScript store definitions
55
## Usage
66

77
```bash
8-
brownfield codegen # Generate for all configured platforms
9-
brownfield codegen -p swift # Generate Swift only
10-
brownfield codegen --platform kotlin # Generate Kotlin only (coming soon)
11-
brownfield --help # Show help
12-
brownfield --version # Show version
8+
brownfield codegen # Generate for all configured platforms
9+
brownfield codegen -p swift # Generate Swift only
10+
brownfield --help # Show help
11+
brownfield --version # Show version
1312
```
1413

1514
## Configuration
1615

17-
Add to your app's `package.json`:
18-
19-
```json
20-
{
21-
"brownie": {
22-
"kotlin": "./android/app/src/main/java/com/example/",
23-
"kotlinPackageName": "com.example"
24-
}
25-
}
26-
```
27-
28-
Note: This config is subject to change as Android support is rolled out. Ideally this will be removed in favor of auto-detection.
29-
30-
| Field | Required | Description |
31-
| ------------------- | -------- | ---------------------------------------------------------- |
32-
| `kotlin` | No | Output directory for Kotlin files |
33-
| `kotlinPackageName` | No | Kotlin package name (extracted from path if not specified) |
34-
35-
**Note:** Swift files are always generated to `node_modules/@callstack/brownie/ios/Generated/`. This path is auto-resolved and not configurable.
16+
Swift files are always generated to `node_modules/@callstack/brownie/ios/Generated/`. This path is auto-resolved and not configurable.
3617

3718
## Generated Output
3819

@@ -73,21 +54,6 @@ The generated struct:
7354
- Conforms to `BrownieStoreProtocol` with auto-generated `storeName`
7455
- Uses mutable `var` properties
7556

76-
### Kotlin Output (Coming Soon)
77-
78-
```kotlin
79-
package com.example
80-
81-
data class BrownfieldStore(
82-
val counter: Double,
83-
val user: User
84-
)
85-
86-
data class User(
87-
val name: String
88-
)
89-
```
90-
9157
## Auto-Generation Hooks
9258

9359
### iOS (Podfile)
@@ -100,17 +66,6 @@ pre_install do |installer|
10066
end
10167
```
10268

103-
### Android (build.gradle.kts)
104-
105-
Run codegen before build:
106-
107-
```kotlin
108-
tasks.register("generateBrownfieldStore") {
109-
exec { commandLine("npx", "brownie", "codegen", "-p", "kotlin") }
110-
}
111-
preBuild.dependsOn("generateBrownfieldStore")
112-
```
113-
11469
## How It Works
11570

11671
1. CLI recursively finds all `*.brownie.ts` files

docs/docs/docs/cli/brownie.mdx

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,12 @@ The `brownfield codegen` CLI command generates `@callstack/brownie` (Brownie) st
55
## Usage
66

77
```bash
8-
brownfield codegen # Generate for all configured platforms
9-
brownfield codegen -p swift # Generate Swift only
10-
brownfield codegen --platform kotlin # Generate Kotlin only
11-
brownfield codegen --help # Show help for Brownie state management codegen
12-
brownfield --version # Show version
8+
brownfield codegen # Generate Swift types
9+
brownfield codegen -p swift # Generate Swift only
10+
brownfield codegen --help # Show help for Brownie state management codegen
11+
brownfield --version # Show version
1312
```
1413

15-
## Configuration
16-
17-
Add to your app's `package.json`:
18-
19-
```json
20-
{
21-
"brownie": {
22-
"swift": "./ios/Generated/",
23-
"kotlin": "./android/app/src/main/java/com/example/",
24-
"kotlinPackageName": "com.example"
25-
}
26-
}
27-
```
28-
29-
| Field | Required | Description |
30-
| ------------------- | -------- | ----------------------------------------- |
31-
| `swift` | No\* | Output directory for Swift files |
32-
| `kotlin` | No\* | Output directory for Kotlin files |
33-
| `kotlinPackageName` | No | Kotlin package name (extracted from path) |
34-
35-
\*At least one of `swift` or `kotlin` is required.
36-
3714
## Store Definition
3815

3916
Stores are auto-discovered from `*.brownie.ts` files. Define your store shape using module augmentation:
@@ -91,17 +68,7 @@ struct BrownfieldStore: Codable {
9168
}
9269
```
9370

94-
**Kotlin** (data class):
95-
96-
```kotlin
97-
package com.example
98-
99-
data class BrownfieldStore (
100-
val counter: Double,
101-
val isLoading: Boolean,
102-
val user: String
103-
)
104-
```
71+
Swift files are always generated to `node_modules/@callstack/brownie/ios/Generated/`. This path is auto-resolved and not configurable.
10572

10673
### Store Discovery
10774

@@ -127,7 +94,5 @@ JSON Schema
12794
12895
quicktype-core
12996
130-
├──▶ Swift (lang: 'swift', mutable-properties: true)
131-
132-
└──▶ Kotlin (lang: 'kotlin', framework: 'just-types')
97+
└──▶ Swift (lang: 'swift', mutable-properties: true)
13398
```

packages/cli/src/brownie/__tests__/commands/codegen.test.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe('runCodegen', () => {
9292
expect(mockGenerateKotlin).not.toHaveBeenCalled();
9393
});
9494

95-
it('generates kotlin files for discovered store', async () => {
95+
it('generates kotlin files when platform is kotlin', async () => {
9696
tempDir = createTempPackageJson({
9797
brownie: {
9898
kotlin: './Generated',
@@ -101,7 +101,7 @@ describe('runCodegen', () => {
101101
});
102102
mockCwd.mockReturnValue(tempDir);
103103

104-
await runCodegen({});
104+
await runCodegen({ platform: 'kotlin' });
105105

106106
expect(mockGenerateKotlin).toHaveBeenCalledWith({
107107
name: 'TestStore',
@@ -110,10 +110,10 @@ describe('runCodegen', () => {
110110
outputPath: 'Generated/TestStore.kt',
111111
packageName: 'com.test',
112112
});
113-
expect(mockGenerateSwift).toHaveBeenCalled();
113+
expect(mockGenerateSwift).not.toHaveBeenCalled();
114114
});
115115

116-
it('generates both swift and kotlin when configured', async () => {
116+
it('generates only swift by default even when kotlin is configured', async () => {
117117
tempDir = createTempPackageJson({
118118
brownie: {
119119
kotlin: './Generated',
@@ -124,7 +124,7 @@ describe('runCodegen', () => {
124124
await runCodegen({});
125125

126126
expect(mockGenerateSwift).toHaveBeenCalled();
127-
expect(mockGenerateKotlin).toHaveBeenCalled();
127+
expect(mockGenerateKotlin).not.toHaveBeenCalled();
128128
});
129129

130130
it('generates only specified platform', async () => {
@@ -172,19 +172,6 @@ describe('runCodegen', () => {
172172
});
173173
});
174174

175-
it('exits with error for invalid platform', async () => {
176-
tempDir = createTempPackageJson({
177-
brownie: {},
178-
});
179-
mockCwd.mockReturnValue(tempDir);
180-
181-
// @ts-expect-error - testing invalid input
182-
await expect(runCodegen({ platform: 'invalid' })).rejects.toThrow(
183-
'process.exit(1)'
184-
);
185-
expect(mockLoggerError).toHaveBeenCalled();
186-
});
187-
188175
it('exits with error when generator fails', async () => {
189176
tempDir = createTempPackageJson({
190177
brownie: {},
@@ -206,4 +193,13 @@ describe('runCodegen', () => {
206193

207194
expect(mockGenerateKotlin).not.toHaveBeenCalled();
208195
});
196+
197+
it('works without brownie config in package.json', async () => {
198+
tempDir = createTempPackageJson({});
199+
mockCwd.mockReturnValue(tempDir);
200+
201+
await runCodegen({});
202+
203+
expect(mockGenerateSwift).toHaveBeenCalled();
204+
});
209205
});

packages/cli/src/brownie/__tests__/config.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ describe('loadConfig', () => {
4343
expect(() => loadConfig()).toThrow('package.json not found');
4444
});
4545

46-
it('throws when brownie config missing', () => {
46+
it('returns empty config when brownie config missing', () => {
4747
tempDir = createTempPackageJson({});
4848
mockCwd.mockReturnValue(tempDir);
49-
expect(() => loadConfig()).toThrow(
50-
'brownie config not found in package.json'
51-
);
49+
const config = loadConfig();
50+
expect(config).toEqual({});
5251
});
5352

5453
it('loads empty config', () => {

packages/cli/src/brownie/commands/codegen.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,8 @@ export async function runCodegen({ platform }: RunCodegenOptions) {
114114
if (platform) {
115115
platforms = [platform];
116116
} else {
117+
// Only generate Swift by default (Kotlin not yet released)
117118
platforms = ['swift'];
118-
if (config.kotlin) {
119-
platforms.push('kotlin');
120-
}
121119
}
122120

123121
await generateForStore(store, config, platforms, isMultipleStores);
@@ -131,8 +129,8 @@ export const codegenCommand = new Command('codegen')
131129
.addOption(
132130
new Option(
133131
'-p, --platform <platform>',
134-
'Generate for specific platform (swift, kotlin)'
135-
).choices(['swift', 'kotlin'])
132+
'Generate for specific platform (swift)'
133+
).choices(['swift'])
136134
)
137135
.action(
138136
actionRunner(async (options: RunCodegenOptions) => {

packages/cli/src/brownie/config.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,5 @@ export function loadConfig(): BrownieConfig {
6767
const packageJson: PackageJson = JSON.parse(
6868
fs.readFileSync(packageJsonPath, 'utf-8')
6969
);
70-
const config = packageJson.brownie;
71-
72-
if (!config) {
73-
throw new Error('brownie config not found in package.json');
74-
}
75-
76-
return config;
70+
return packageJson.brownie ?? {};
7771
}

0 commit comments

Comments
 (0)