@callstack/brownfield-cli 3.12.0 → 3.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/brownfield/commands/packageAndroid.d.ts.map +1 -1
  3. package/dist/brownfield/commands/packageAndroid.js +3 -3
  4. package/dist/brownfield/commands/packageIos.d.ts.map +1 -1
  5. package/dist/brownfield/commands/packageIos.js +4 -2
  6. package/dist/brownfield/commands/publishAndroid.d.ts.map +1 -1
  7. package/dist/brownfield/commands/publishAndroid.js +3 -1
  8. package/dist/brownie/commands/codegen.d.ts +4 -2
  9. package/dist/brownie/commands/codegen.d.ts.map +1 -1
  10. package/dist/brownie/commands/codegen.js +15 -7
  11. package/dist/brownie/config.d.ts +19 -5
  12. package/dist/brownie/config.d.ts.map +1 -1
  13. package/dist/brownie/config.js +45 -9
  14. package/dist/brownie/helpers/runBrownieCodegenIfApplicable.d.ts +1 -1
  15. package/dist/brownie/helpers/runBrownieCodegenIfApplicable.d.ts.map +1 -1
  16. package/dist/brownie/helpers/runBrownieCodegenIfApplicable.js +1 -1
  17. package/dist/brownie/index.d.ts +0 -1
  18. package/dist/brownie/index.d.ts.map +1 -1
  19. package/dist/config.d.ts +7 -0
  20. package/dist/config.d.ts.map +1 -0
  21. package/dist/config.js +72 -0
  22. package/dist/navigation/commands/codegen.d.ts.map +1 -1
  23. package/dist/navigation/generators/ts.d.ts.map +1 -1
  24. package/dist/navigation/generators/ts.js +53 -4
  25. package/dist/navigation/runner.d.ts.map +1 -1
  26. package/dist/navigation/runner.js +16 -12
  27. package/dist/shared/utils/cli.d.ts +1 -1
  28. package/dist/shared/utils/cli.d.ts.map +1 -1
  29. package/dist/types.d.ts +30 -0
  30. package/dist/types.d.ts.map +1 -0
  31. package/package.json +11 -2
  32. package/schema.json +110 -0
  33. package/src/brownfield/commands/packageAndroid.ts +5 -6
  34. package/src/brownfield/commands/packageIos.ts +18 -18
  35. package/src/brownfield/commands/publishAndroid.ts +4 -1
  36. package/src/brownie/commands/codegen.ts +35 -10
  37. package/src/brownie/config.ts +72 -15
  38. package/src/brownie/helpers/runBrownieCodegenIfApplicable.ts +2 -2
  39. package/src/brownie/index.ts +0 -1
  40. package/src/config.ts +119 -0
  41. package/src/navigation/commands/codegen.ts +1 -3
  42. package/src/navigation/generators/ts.ts +61 -3
  43. package/src/navigation/runner.ts +17 -12
  44. package/src/shared/utils/cli.ts +4 -2
  45. package/src/types.ts +51 -0
  46. package/dist/brownie/types.d.ts +0 -2
  47. package/dist/brownie/types.d.ts.map +0 -1
  48. package/src/brownie/types.ts +0 -1
  49. /package/dist/{brownie/types.js → types.js} +0 -0
@@ -56,14 +56,72 @@ export default TurboModuleRegistry.getEnforcing<Spec>(
56
56
  `;
57
57
  }
58
58
 
59
+ const SKIP_TYPE_TOKENS = new Set([
60
+ 'Array',
61
+ 'Date',
62
+ 'Map',
63
+ 'Object',
64
+ 'Promise',
65
+ 'ReadonlyArray',
66
+ 'Record',
67
+ 'Set',
68
+ 'any',
69
+ 'boolean',
70
+ 'false',
71
+ 'null',
72
+ 'number',
73
+ 'object',
74
+ 'string',
75
+ 'true',
76
+ 'undefined',
77
+ 'unknown',
78
+ 'void',
79
+ ]);
80
+
81
+ function collectTypesUsedByMethods(methods: MethodSignature[]): Set<string> {
82
+ const used = new Set<string>();
83
+
84
+ for (const method of methods) {
85
+ const typeTexts = [
86
+ method.returnType,
87
+ ...method.params.map((param) => param.type),
88
+ ];
89
+
90
+ for (const typeText of typeTexts) {
91
+ const matches = typeText.match(/\b[A-Za-z_]\w*\b/g);
92
+ if (!matches) {
93
+ continue;
94
+ }
95
+
96
+ for (const name of matches) {
97
+ if (!SKIP_TYPE_TOKENS.has(name)) {
98
+ used.add(name);
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ return used;
105
+ }
106
+
59
107
  function buildTypeImportLine(
108
+ methods: MethodSignature[],
60
109
  referencedTypeDeclarations: TypeDeclaration[]
61
110
  ): string {
62
111
  if (referencedTypeDeclarations.length === 0) {
63
112
  return '';
64
113
  }
65
114
 
66
- const names = referencedTypeDeclarations.map((entry) => entry.name).join(', ');
115
+ const usedTypes = collectTypesUsedByMethods(methods);
116
+ const names = referencedTypeDeclarations
117
+ .map((entry) => entry.name)
118
+ .filter((name) => usedTypes.has(name))
119
+ .join(', ');
120
+
121
+ if (names.length === 0) {
122
+ return '';
123
+ }
124
+
67
125
  return `import type { ${names} } from './NativeBrownfieldNavigation';\n`;
68
126
  }
69
127
 
@@ -71,7 +129,7 @@ export function generateIndexTs(
71
129
  methods: MethodSignature[],
72
130
  referencedTypeDeclarations: TypeDeclaration[] = []
73
131
  ): string {
74
- const typeImportLine = buildTypeImportLine(referencedTypeDeclarations);
132
+ const typeImportLine = buildTypeImportLine(methods, referencedTypeDeclarations);
75
133
  const functionImplementations = methods
76
134
  .map((method) => {
77
135
  const params = method.params
@@ -155,7 +213,7 @@ export function generateIndexDts(
155
213
  methods: MethodSignature[],
156
214
  referencedTypeDeclarations: TypeDeclaration[] = []
157
215
  ): string {
158
- const typeImportLine = buildTypeImportLine(referencedTypeDeclarations);
216
+ const typeImportLine = buildTypeImportLine(methods, referencedTypeDeclarations);
159
217
  const methodSignatures = methods
160
218
  .map((method) => {
161
219
  const params = method.params
@@ -122,47 +122,52 @@ function getOutputPaths(
122
122
  };
123
123
  }
124
124
 
125
+ function writeFileEnsuringDir(filePath: string, content: string): void {
126
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
127
+ fs.writeFileSync(filePath, content);
128
+ }
129
+
125
130
  function writeArtifacts(
126
131
  paths: NavigationOutputPaths,
127
132
  artifacts: GeneratedNavigationArtifacts
128
133
  ): void {
129
- fs.writeFileSync(paths.turboModuleSpec, artifacts.turboModuleSpec);
134
+ writeFileEnsuringDir(paths.turboModuleSpec, artifacts.turboModuleSpec);
130
135
  logger.success(`Generated ${paths.turboModuleSpec}`);
131
136
 
132
- fs.writeFileSync(paths.navigationTs, artifacts.indexTs);
137
+ writeFileEnsuringDir(paths.navigationTs, artifacts.indexTs);
133
138
  logger.success(`Generated ${paths.navigationTs}`);
134
139
 
135
- fs.writeFileSync(paths.commonjsIndexJs, artifacts.indexJs);
140
+ writeFileEnsuringDir(paths.commonjsIndexJs, artifacts.indexJs);
136
141
  logger.success(`Generated ${paths.commonjsIndexJs}`);
137
142
 
138
- fs.writeFileSync(paths.moduleIndexJs, artifacts.indexJs);
143
+ writeFileEnsuringDir(paths.moduleIndexJs, artifacts.indexJs);
139
144
  logger.success(`Generated ${paths.moduleIndexJs}`);
140
145
 
141
- fs.writeFileSync(paths.commonjsIndexDts, artifacts.indexDts);
146
+ writeFileEnsuringDir(paths.commonjsIndexDts, artifacts.indexDts);
142
147
  logger.success(`Generated ${paths.commonjsIndexDts}`);
143
148
 
144
- fs.writeFileSync(paths.moduleIndexDts, artifacts.indexDts);
149
+ writeFileEnsuringDir(paths.moduleIndexDts, artifacts.indexDts);
145
150
  logger.success(`Generated ${paths.moduleIndexDts}`);
146
151
 
147
- fs.writeFileSync(paths.swiftDelegate, artifacts.swiftDelegate);
152
+ writeFileEnsuringDir(paths.swiftDelegate, artifacts.swiftDelegate);
148
153
  logger.success(`Generated ${paths.swiftDelegate}`);
149
154
 
150
155
  if (artifacts.swiftModels) {
151
- fs.writeFileSync(paths.swiftModels, artifacts.swiftModels);
156
+ writeFileEnsuringDir(paths.swiftModels, artifacts.swiftModels);
152
157
  logger.success(`Generated ${paths.swiftModels}`);
153
158
  }
154
159
 
155
- fs.writeFileSync(paths.objcImplementation, artifacts.objcImplementation);
160
+ writeFileEnsuringDir(paths.objcImplementation, artifacts.objcImplementation);
156
161
  logger.success(`Generated ${paths.objcImplementation}`);
157
162
 
158
- fs.writeFileSync(paths.kotlinDelegate, artifacts.kotlinDelegate);
163
+ writeFileEnsuringDir(paths.kotlinDelegate, artifacts.kotlinDelegate);
159
164
  logger.success(`Generated ${paths.kotlinDelegate}`);
160
165
 
161
- fs.writeFileSync(paths.kotlinModule, artifacts.kotlinModule);
166
+ writeFileEnsuringDir(paths.kotlinModule, artifacts.kotlinModule);
162
167
  logger.success(`Generated ${paths.kotlinModule}`);
163
168
 
164
169
  if (artifacts.kotlinModels) {
165
- fs.writeFileSync(paths.kotlinModels, artifacts.kotlinModels);
170
+ writeFileEnsuringDir(paths.kotlinModels, artifacts.kotlinModels);
166
171
  logger.success(`Generated ${paths.kotlinModels}`);
167
172
  }
168
173
  }
@@ -23,8 +23,10 @@ export function curryOptions(programCommand: Command, options: RockCLIOptions) {
23
23
  return programCommand;
24
24
  }
25
25
 
26
- export function actionRunner<T, R>(fn: (...args: T[]) => Promise<R>) {
27
- return async function wrappedCLIAction(...args: T[]) {
26
+ export function actionRunner<Args extends unknown[], R>(
27
+ fn: (...args: Args) => Promise<R>
28
+ ) {
29
+ return async function wrappedCLIAction(...args: Args) {
28
30
  try {
29
31
  await fn(...args);
30
32
  } catch (error) {
package/src/types.ts ADDED
@@ -0,0 +1,51 @@
1
+ import type {
2
+ PublishLocalAarFlags,
3
+ PackageAarFlags,
4
+ } from '@rock-js/platform-android';
5
+ import type { BuildFlags as AppleBuildFlags } from '@rock-js/platform-apple-helpers';
6
+
7
+ export type Platform = 'swift' | 'kotlin';
8
+
9
+ export type BrownfieldCommonOptions = Partial<{
10
+ verbose: boolean;
11
+ }>;
12
+
13
+ export type BrownfieldConfigMetadata = Partial<{
14
+ $schema: string;
15
+ }>;
16
+
17
+ export type BrownieConfig = {
18
+ kotlin?: string;
19
+ kotlinPackageName?: string;
20
+ };
21
+
22
+ export type PackageIosOptions = AppleBuildFlags & {
23
+ /** Set when `--use-prebuilt-rn-core` is passed; omitted when the flag is absent (Rock applies RN version defaults). */
24
+ usePrebuiltRnCore?: boolean;
25
+ /** When set, generate a local Swift Package Manager manifest next to the packaged XCFramework outputs. */
26
+ addSpmPackage?: boolean;
27
+ };
28
+
29
+ export type BrownfieldPackageAndroidOptions = BrownfieldCommonOptions &
30
+ Partial<PackageAarFlags>;
31
+ export type BrownfieldPublishAndroidOptions = BrownfieldCommonOptions &
32
+ Partial<PublishLocalAarFlags>;
33
+ export type BrownfieldPackageIosOptions = BrownfieldCommonOptions &
34
+ Partial<PackageIosOptions>;
35
+
36
+ export type BrownfieldAndroidConfig = Omit<
37
+ Partial<PackageAarFlags> & Partial<PublishLocalAarFlags>,
38
+ keyof BrownfieldCommonOptions
39
+ >;
40
+ export type BrownfieldIosConfig = Omit<
41
+ Partial<PackageIosOptions>,
42
+ keyof BrownfieldCommonOptions
43
+ >;
44
+
45
+ export type BrownfieldConfig = BrownfieldConfigMetadata &
46
+ BrownfieldCommonOptions &
47
+ Partial<{
48
+ android: BrownfieldAndroidConfig;
49
+ ios: BrownfieldIosConfig;
50
+ brownie: BrownieConfig;
51
+ }>;
@@ -1,2 +0,0 @@
1
- export type Platform = 'swift' | 'kotlin';
2
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/brownie/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC"}
@@ -1 +0,0 @@
1
- export type Platform = 'swift' | 'kotlin';
File without changes