Skip to content

Commit d6d6db9

Browse files
artus9033thymikee
andauthored
feat: expose brownfield plugin actions & types (#666)
* feat: expose RockCLIOptions type * feat: expose brownfield plugin actions * refactor: use RockCLIOptions type in platform-ios * chore: add changeset * refactor fn signatures to be more explicit instead of using api * fix(types): add PublishLocalAarFlags * feat: expose types from @rock-js/platform-apple-helpers * feat: Rock escape hatch in plugin-brownfield-ios * fix: debug logs in mergeFrameworks not showing path to removed framework before writing merge output * rename FingerprintSources to FingerprintOptions and run prettier * fixup test types * cleanup; iosConfig is from autolinking; derivedDataDir can be overriden by --build-folder arg * cleanup unused type * feat: add skipCache parameter to buildApp, packageIosAction and installPodsIfNeeded * feat: make args.buildFolder override getBuildPaths in iOS brownfield plugin to work with non-Rock projects * feat: add packageDir to override artifact outputs path in non-Rock projects --------- Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 3547ac0 commit d6d6db9

36 files changed

Lines changed: 317 additions & 230 deletions

File tree

.changeset/itchy-nails-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rock-js/platform-apple-helpers': patch
3+
---
4+
5+
fix: debug logs in mergeFrameworks not showing path to removed framework before writing merge output

.changeset/itchy-spoons-trade.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@rock-js/plugin-brownfield-android': patch
3+
'@rock-js/plugin-brownfield-ios': patch
4+
---
5+
6+
feat: expose logic of brownfield plugin actions

.github/pr-labeler.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
'release: bug fix':
44
- '/^fix/'
55
'release: breaking change':
6-
- '/^breaking/'
6+
- '/^breaking/'

packages/cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Choose your path based on your current situation:
3232

3333
### Creating a new project
3434

35-
> [!TIP]
35+
> [!TIP]
3636
> For **new projects**, we recommend starting with [Expo](https://expo.dev) for the best developer experience and similar remote caching capabilities. Rock is designed for teams who have outgrown the Community CLI.
3737
3838
To create a fresh React Native app with Rock, open a terminal and run:

packages/cli/src/lib/plugins/fingerprint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHash } from 'node:crypto';
22
import { performance } from 'node:perf_hooks';
33
import type { PluginApi } from '@rock-js/config';
4-
import type { FingerprintInputHash, FingerprintSources } from '@rock-js/tools';
4+
import type { FingerprintInputHash, FingerprintOptions } from '@rock-js/tools';
55
import {
66
color,
77
intro,
@@ -39,7 +39,7 @@ type NativeFingerprintCommandOptions = {
3939

4040
export async function nativeFingerprintCommand(
4141
path: string,
42-
{ extraSources, ignorePaths, env }: FingerprintSources,
42+
{ extraSources, ignorePaths, env }: FingerprintOptions,
4343
options: NativeFingerprintCommandOptions,
4444
) {
4545
validateOptions(options);

packages/cli/src/lib/plugins/remoteCache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'node:fs';
22
import os from 'node:os';
33
import path from 'node:path';
44
import type { PluginApi, PluginOutput } from '@rock-js/config';
5-
import type { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
5+
import type { FingerprintOptions, RemoteBuildCache } from '@rock-js/tools';
66
import {
77
color,
88
colorLink,
@@ -48,7 +48,7 @@ async function remoteCache({
4848
args: Flags;
4949
remoteCacheProvider: null | (() => RemoteBuildCache);
5050
projectRoot: string;
51-
fingerprintOptions: FingerprintSources;
51+
fingerprintOptions: FingerprintOptions;
5252
}) {
5353
const isJsonOutput = args.json;
5454
if (!remoteCacheProvider) {

packages/config/src/lib/config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'node:fs';
22
import { createRequire } from 'node:module';
33
import * as path from 'node:path';
44
import { pathToFileURL } from 'node:url';
5-
import type { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
5+
import type { FingerprintOptions, RemoteBuildCache } from '@rock-js/tools';
66
import { colorLink, getReactNativeVersion, logger } from '@rock-js/tools';
77
import type { ValidationError } from 'joi';
88
import { ConfigTypeSchema } from './schema.js';
@@ -54,7 +54,7 @@ export type PluginApi = {
5454
getRemoteCacheProvider: () => Promise<
5555
null | undefined | (() => RemoteBuildCache)
5656
>;
57-
getFingerprintOptions: () => FingerprintSources;
57+
getFingerprintOptions: () => FingerprintOptions;
5858
getBundlerStart: () => ({ args }: { args: DevServerArgs }) => void;
5959
getUsePrebuiltRNCore: () => number | undefined;
6060
};
@@ -103,7 +103,7 @@ export type ConfigType = {
103103
ignorePaths?: string[];
104104
env?: string[];
105105
};
106-
usePrebuiltRNCore?: number,
106+
usePrebuiltRNCore?: number;
107107
};
108108

109109
export type ConfigOutput = {
@@ -219,7 +219,7 @@ Read more: ${colorLink('https://rockjs.dev/docs/configuration#github-actions-pro
219219
return validatedConfig.remoteCacheProvider;
220220
},
221221
getFingerprintOptions: () =>
222-
validatedConfig.fingerprint as FingerprintSources,
222+
validatedConfig.fingerprint as FingerprintOptions,
223223
getBundlerStart:
224224
() =>
225225
({ args }: { args: DevServerArgs }) => {

packages/create-app/src/lib/utils/__tests__/initInExistingProject.test.ts

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'node:fs';
22
import * as path from 'node:path';
33
import { cleanup, getTempDirectory, writeFiles } from '@rock-js/test-helpers';
44
import * as tools from '@rock-js/tools';
5-
import { updateAndroidBuildGradle } from "../initInExistingProject.js";
5+
import { updateAndroidBuildGradle } from '../initInExistingProject.js';
66

77
const directory = getTempDirectory('test_updateAndroidBuildGradle');
88

@@ -61,15 +61,23 @@ describe('updateAndroidBuildGradle', () => {
6161
},
6262
];
6363

64-
it.each(workingCases)('should update the Android build.gradle file when $name', ({ content, expected }) => {
65-
const files = {
66-
'android/app/build.gradle': content,
67-
};
68-
writeFiles(directory, files);
69-
updateAndroidBuildGradle(directory, 'android');
70-
71-
expect(fs.readFileSync(path.join(directory, 'android/app/build.gradle'), 'utf8')).toStrictEqual(expected)
72-
});
64+
it.each(workingCases)(
65+
'should update the Android build.gradle file when $name',
66+
({ content, expected }) => {
67+
const files = {
68+
'android/app/build.gradle': content,
69+
};
70+
writeFiles(directory, files);
71+
updateAndroidBuildGradle(directory, 'android');
72+
73+
expect(
74+
fs.readFileSync(
75+
path.join(directory, 'android/app/build.gradle'),
76+
'utf8',
77+
),
78+
).toStrictEqual(expected);
79+
},
80+
);
7381

7482
it('should not update the Android build.gradle file when cliFile is already set', () => {
7583
const content = `
@@ -84,7 +92,9 @@ describe('updateAndroidBuildGradle', () => {
8492
writeFiles(directory, files);
8593
updateAndroidBuildGradle(directory, 'android');
8694

87-
expect(fs.readFileSync(path.join(directory, 'android/app/build.gradle'), 'utf8')).toStrictEqual(content)
95+
expect(
96+
fs.readFileSync(path.join(directory, 'android/app/build.gradle'), 'utf8'),
97+
).toStrictEqual(content);
8898
});
8999

90100
it('should display a warning when unable to update the Android build.gradle file', () => {
@@ -101,10 +111,12 @@ describe('updateAndroidBuildGradle', () => {
101111
writeFiles(directory, files);
102112
updateAndroidBuildGradle(directory, 'android');
103113

104-
expect(fs.readFileSync(path.join(directory, 'android/app/build.gradle'), 'utf8')).toStrictEqual(content)
114+
expect(
115+
fs.readFileSync(path.join(directory, 'android/app/build.gradle'), 'utf8'),
116+
).toStrictEqual(content);
105117

106118
expect(warn).toHaveBeenCalledWith(
107-
expect.stringContaining('Unable to update')
108-
)
119+
expect.stringContaining('Unable to update'),
120+
);
109121
});
110122
});

packages/platform-android/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export {
55
options as packageAarOptions,
66
} from './lib/commands/aar/packageAar.js';
77
export {
8+
type PublishLocalAarFlags,
89
publishLocalAar,
910
options as publishLocalAarOptions,
1011
} from './lib/commands/aar/publishLocalAar.js';
Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { RockCLIOptions } from '@rock-js/tools';
12
import { outro } from '@rock-js/tools';
23
import { runGradleAar } from '../runGradle.js';
34
import { toPascalCase } from '../toPascalCase.js';
@@ -12,35 +13,24 @@ export type PackageAarFlags = {
1213
moduleName?: string;
1314
};
1415

15-
export async function packageAar(
16-
aarProject: AarProject,
17-
args: PackageAarFlags,
18-
) {
19-
normalizeArgs(args);
16+
export async function packageAar(aarProject: AarProject, variant: string) {
17+
normalizeVariant(variant);
18+
const tasks = [`assemble${toPascalCase(variant)}`];
2019

21-
const tasks = [`assemble${toPascalCase(args.variant)}`];
22-
23-
await runGradleAar({ tasks, aarProject, variant: args.variant });
20+
await runGradleAar({ tasks, aarProject, variant });
2421
outro('Success 🎉.');
2522
}
2623

27-
export async function localPublishAar(
28-
aarProject: AarProject,
29-
args: PackageAarFlags,
30-
) {
24+
export async function localPublishAar(aarProject: AarProject, variant: string) {
3125
const tasks = ['publishToMavenLocal'];
3226

33-
await runGradleAar({
34-
tasks,
35-
aarProject,
36-
variant: args.variant,
37-
});
27+
await runGradleAar({ tasks, aarProject, variant });
3828
outro('Success 🎉.');
3929
}
4030

41-
function normalizeArgs(args: PackageAarFlags) {
42-
if (!args.variant) {
43-
args.variant = 'debug';
31+
function normalizeVariant(variant: string) {
32+
if (!variant) {
33+
variant = 'debug';
4434
}
4535
}
4636

@@ -54,4 +44,4 @@ export const options = [
5444
name: '--module-name <string>',
5545
description: 'AAR module name',
5646
},
57-
];
47+
] satisfies RockCLIOptions;

0 commit comments

Comments
 (0)