Skip to content

Commit 5da0615

Browse files
committed
add ios part and fix ts
1 parent b313915 commit 5da0615

File tree

6 files changed

+56
-38
lines changed

6 files changed

+56
-38
lines changed

packages/config/src/lib/config.ts

Lines changed: 22 additions & 18 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 { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
5+
import type { FingerprintSources, 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';
@@ -13,14 +13,26 @@ export type PluginOutput = {
1313
description: string;
1414
};
1515

16-
type StartDevServerFunction = (options: {
16+
export type DevServerArgs = {
17+
interactive: boolean;
18+
clientLogs: boolean;
19+
port?: string;
20+
host?: string;
21+
https?: boolean;
22+
resetCache?: boolean;
23+
platforms?: string[];
24+
[key: string]: unknown;
25+
};
26+
27+
export type StartDevServerArgs = {
1728
root: string;
18-
// TODO fix type
19-
args: any;
29+
args: DevServerArgs;
2030
reactNativeVersion: string;
2131
reactNativePath: string;
2232
platforms: Record<string, object>;
23-
}) => Promise<void>;
33+
};
34+
35+
type StartDevServerFunction = (options: StartDevServerArgs) => Promise<void>;
2436

2537
export type BundlerPluginOutput = {
2638
name: string;
@@ -41,15 +53,8 @@ export type PluginApi = {
4153
getRemoteCacheProvider: () => Promise<
4254
null | undefined | (() => RemoteBuildCache)
4355
>;
44-
<<<<<<< HEAD
4556
getFingerprintOptions: () => FingerprintSources;
46-
=======
47-
getFingerprintOptions: () => {
48-
extraSources: string[];
49-
ignorePaths: string[];
50-
};
51-
>>>>>>> 83e802f (make it run)
52-
getBundlerStart: () => ({ args }: { args: any }) => void;
57+
getBundlerStart: () => ({ args }: { args: DevServerArgs }) => void;
5358
};
5459

5560
type PluginType = (args: PluginApi) => PluginOutput;
@@ -102,6 +107,7 @@ export type ConfigOutput = {
102107
root: string;
103108
commands?: Array<CommandType>;
104109
platforms?: Record<string, PlatformOutput>;
110+
bundler?: BundlerPluginOutput;
105111
} & PluginApi;
106112

107113
const extensions = ['.js', '.ts', '.mjs'];
@@ -209,10 +215,10 @@ Read more: ${colorLink('https://rockjs.dev/docs/configuration#github-actions-pro
209215
}
210216
return validatedConfig.remoteCacheProvider;
211217
},
212-
getFingerprintOptions: () => FingerprintSources,
218+
getFingerprintOptions: () => validatedConfig.fingerprint as FingerprintSources,
213219
getBundlerStart:
214220
() =>
215-
({ args }: { args: any }) => {
221+
({ args }: { args: DevServerArgs }) => {
216222
return bundler?.start({
217223
root: api.getProjectRoot(),
218224
args,
@@ -240,12 +246,11 @@ Read more: ${colorLink('https://rockjs.dev/docs/configuration#github-actions-pro
240246
}
241247

242248
if (validatedConfig.bundler) {
243-
// @ts-expect-error tbd
244249
bundler = assignOriginToCommand(
245250
validatedConfig.bundler,
246251
api,
247252
validatedConfig
248-
);
253+
) as BundlerPluginOutput;
249254
}
250255

251256
for (const internalPlugin of internalPlugins) {
@@ -260,7 +265,6 @@ Read more: ${colorLink('https://rockjs.dev/docs/configuration#github-actions-pro
260265
root: projectRoot,
261266
commands: validatedConfig.commands ?? [],
262267
platforms: platforms ?? {},
263-
// @ts-expect-error tbd
264268
bundler,
265269
...api,
266270
};

packages/platform-android/src/lib/commands/runAndroid/command.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export function registerRunCommand(
2121
projectRoot,
2222
await api.getRemoteCacheProvider(),
2323
api.getFingerprintOptions(),
24-
api.getBundlerStart()
24+
api.getBundlerStart(),
25+
api.getReactNativeVersion(),
26+
api.getReactNativePath()
2527
);
2628
},
2729
options: runOptions,

packages/platform-android/src/lib/commands/runAndroid/runAndroid.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
AndroidProjectConfig,
55
Config,
66
} from '@react-native-community/cli-types';
7+
import type { StartDevServerArgs } from '@rock-js/config';
78
import type { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
89
import {
910
color,
@@ -50,14 +51,9 @@ export async function runAndroid(
5051
projectRoot: string,
5152
remoteCacheProvider: null | (() => RemoteBuildCache) | undefined,
5253
fingerprintOptions: FingerprintSources,
53-
startDevServer: (options: {
54-
root: string;
55-
// TODO fix type
56-
args: any;
57-
reactNativeVersion: string;
58-
reactNativePath: string;
59-
platforms: Record<string, object>;
60-
}) => void
54+
startDevServer: (options: StartDevServerArgs) => void,
55+
reactNativeVersion: string,
56+
reactNativePath: string
6157
) {
6258
intro('Running Android app');
6359

@@ -88,8 +84,8 @@ export async function runAndroid(
8884
logger.info('Starting dev server...');
8985
startDevServer({
9086
root: projectRoot,
91-
reactNativePath: './node_modules/react-native',
92-
reactNativeVersion: '0.79',
87+
reactNativePath,
88+
reactNativeVersion,
9389
platforms: { ios: {}, android: {} },
9490
args: {
9591
interactive: isInteractive(),

packages/platform-apple-helpers/src/lib/commands/run/createRun.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
22
import path from 'node:path';
3+
import type { StartDevServerArgs } from '@rock-js/config';
34
import type { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
45
import {
56
color,
@@ -34,6 +35,8 @@ export const createRun = async ({
3435
remoteCacheProvider,
3536
fingerprintOptions,
3637
reactNativePath,
38+
reactNativeVersion,
39+
startDevServer,
3740
}: {
3841
platformName: ApplePlatform;
3942
projectConfig: ProjectConfig;
@@ -42,9 +45,25 @@ export const createRun = async ({
4245
remoteCacheProvider: null | (() => RemoteBuildCache) | undefined;
4346
fingerprintOptions: FingerprintSources;
4447
reactNativePath: string;
48+
reactNativeVersion: string;
49+
startDevServer?: (options: StartDevServerArgs) => void;
4550
}) => {
4651
validateArgs(args, projectRoot);
4752

53+
if (startDevServer) {
54+
logger.info('Starting dev server...');
55+
startDevServer({
56+
root: projectRoot,
57+
reactNativePath,
58+
reactNativeVersion,
59+
platforms: { ios: {}, android: {} },
60+
args: {
61+
interactive: isInteractive(),
62+
clientLogs: true,
63+
},
64+
});
65+
}
66+
4867
const deviceOrSimulator = args.destination
4968
? // there can be multiple destinations, so we'll pick the first one
5069
args.destination[0].match(/simulator/i)

packages/platform-ios/src/lib/platformIOS.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export const platformIOS =
6161
remoteCacheProvider: await api.getRemoteCacheProvider(),
6262
fingerprintOptions: api.getFingerprintOptions(),
6363
reactNativePath: api.getReactNativePath(),
64+
reactNativeVersion: api.getReactNativeVersion(),
65+
startDevServer: api.getBundlerStart(),
6466
});
6567
outro('Success 🎉.');
6668
},

packages/plugin-metro/src/lib/start/command.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import path from 'node:path';
99
import type { PluginApi } from '@rock-js/config';
10+
import type { StartDevServerArgs } from '@rock-js/config';
1011
import { findDevServerPort, intro } from '@rock-js/tools';
1112
import type { StartCommandArgs } from './runServer.js';
1213
import runServer from './runServer.js';
@@ -17,15 +18,9 @@ export async function startDevServer({
1718
reactNativeVersion,
1819
reactNativePath,
1920
platforms,
20-
}: {
21-
root: string;
22-
args: StartCommandArgs;
23-
reactNativeVersion: string;
24-
reactNativePath: string;
25-
platforms: Record<string, object>;
26-
}) {
21+
}: StartDevServerArgs) {
2722
const { port, startDevServer } = await findDevServerPort(
28-
args.port ?? 8081,
23+
args.port ? Number(args.port) : 8081,
2924
root
3025
);
3126

@@ -35,7 +30,7 @@ export async function startDevServer({
3530

3631
return runServer(
3732
{ root, reactNativeVersion, reactNativePath, platforms },
38-
{ ...args, port }
33+
{ ...args, port, platforms: Object.keys(platforms) }
3934
);
4035
}
4136

0 commit comments

Comments
 (0)