Skip to content

Commit 91a163c

Browse files
authored
feat: CLI wrapper scripts provided by library packages (#191)
* feat: bin script wrappers for brownie & brownfield packages * fix: typescript compilation issues * chore: use CLI script provided by brownfield & brownie in demo apps * fix: exports in cli package.json * fix: normalize CJS/ESM interop for cli-config
1 parent cf1430b commit 91a163c

File tree

15 files changed

+56
-19
lines changed

15 files changed

+56
-19
lines changed

apps/RNApp/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"@babel/core": "^7.25.2",
3131
"@babel/preset-env": "^7.25.3",
3232
"@babel/runtime": "^7.25.0",
33-
"@callstack/brownfield-cli": "workspace:^",
3433
"@react-native-community/cli": "20.0.0",
3534
"@react-native-community/cli-platform-android": "20.0.0",
3635
"@react-native-community/cli-platform-ios": "20.0.0",

apps/TesterIntegrated/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"@babel/core": "^7.25.2",
2424
"@babel/preset-env": "^7.25.3",
2525
"@babel/runtime": "^7.25.0",
26-
"@callstack/brownfield-cli": "workspace:^",
2726
"@react-native-community/cli": "20.0.0",
2827
"@react-native-community/cli-platform-android": "20.0.0",
2928
"@react-native-community/cli-platform-ios": "20.0.0",

packages/brownie/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "0.0.1",
44
"license": "MIT",
55
"author": "Oskar Kwaśniewski <oskarkwasniewski@icloud.com>",
6+
"bin": {
7+
"brownfield": "./lib/commonjs/scripts/brownfield.js"
8+
},
69
"contributors": [
710
"Artur Morys-Magiera <artus9033@gmail.com>",
811
"Oskar Kwasniewski <oskarkwasniewski@icloud.com>"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { runCLI } from '@callstack/brownfield-cli';
4+
5+
runCLI(process.argv);

packages/cli/package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"author": "Artur Morys-Magiera <artus9033@gmail.com>",
66
"bin": {
7-
"brownfield": "./dist/index.js"
7+
"brownfield": "./dist/main.js"
88
},
99
"type": "module",
1010
"contributors": [
@@ -15,7 +15,19 @@
1515
"description": "Brownfield CLI for React Native, gathering all packages of the RN brownfield ecosystem",
1616
"exports": {
1717
".": {
18-
"source": "./src/index.ts"
18+
"source": "./src/index.ts",
19+
"types": "./dist/index.d.ts",
20+
"default": "./dist/index.js"
21+
},
22+
"./brownfield": {
23+
"source": "./src/brownfield/index.ts",
24+
"types": "./dist/brownfield/index.d.ts",
25+
"default": "./dist/brownfield/index.js"
26+
},
27+
"./brownie": {
28+
"source": "./src/brownie/index.ts",
29+
"types": "./dist/brownie/index.d.ts",
30+
"default": "./dist/brownie/index.js"
1931
},
2032
"./package.json": "./package.json"
2133
},

packages/cli/src/brownfield/utils/rn-cli.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ import type {
44
Config as UserConfig,
55
ProjectConfig,
66
} from '@react-native-community/cli-types';
7-
import cliConfig from '@react-native-community/cli-config';
7+
import cliConfigImport from '@react-native-community/cli-config';
8+
9+
const cliConfig: typeof cliConfigImport =
10+
typeof cliConfigImport === 'function'
11+
? cliConfigImport
12+
: // @ts-expect-error: interop default
13+
cliConfigImport.default;
814

915
import { findProjectRoot, makeRelativeProjectConfigPaths } from './paths.js';
1016

@@ -22,7 +28,7 @@ export function getProjectInfo<Platform extends 'ios' | 'android'>(
2228
} {
2329
const projectRoot = findProjectRoot();
2430

25-
const userConfig = cliConfig.default({
31+
const userConfig = cliConfig({
2632
projectRoot,
2733
selectedPlatform: platform,
2834
});

packages/cli/src/brownie/__fixtures__/SecondStore.brownie.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ type SecondStore = {
33
enabled: boolean;
44
};
55

6-
// @ts-expect-error: inexistent module augmentation
76
declare module '@callstack/brownie' {
87
interface BrownieStores {
98
SecondStore: SecondStore;

packages/cli/src/brownie/__fixtures__/TestStore.brownie.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ type TestStore = {
44
isActive: boolean;
55
};
66

7-
// @ts-expect-error: inexistent module augmentation
87
declare module '@callstack/brownie' {
98
interface BrownieStores {
109
TestStore: TestStore;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import { generateSwift } from '../generators/swift.js';
1515
import { generateKotlin } from '../generators/kotlin.js';
1616
import { discoverStores, type DiscoveredStore } from '../store-discovery.js';
17-
import { Platform } from '../types.js';
17+
import type { Platform } from '../types.js';
1818

1919
function getOutputPath(dir: string, name: string, ext: string): string {
2020
return path.join(dir, `${name}.${ext}`);

packages/cli/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
import { styleText } from 'node:util';
42

53
import { logger } from '@rock-js/tools';
@@ -77,8 +75,10 @@ registrationHelper(brownieCommands, brownieCommandsGroupName);
7775

7876
program.commandsGroup('Utility commands').helpCommand('help [command]');
7977

80-
program.parse(process.argv);
78+
export function runCLI(argv: string[]): void {
79+
program.parse(argv);
8180

82-
if (!process.argv.slice(2).length) {
83-
program.outputHelp();
81+
if (!argv.slice(2).length) {
82+
program.outputHelp();
83+
}
8484
}

0 commit comments

Comments
 (0)