-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathrn-cli.ts
More file actions
58 lines (50 loc) · 1.54 KB
/
Copy pathrn-cli.ts
File metadata and controls
58 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import type { PackageAarFlags } from '@rock-js/platform-android';
import type {
AndroidProjectConfig,
Config as UserConfig,
ProjectConfig,
} from '@react-native-community/cli-types';
import cliConfigImport from '@react-native-community/cli-config';
const cliConfig: typeof cliConfigImport =
typeof cliConfigImport === 'function'
? cliConfigImport
: // @ts-expect-error: interop default
cliConfigImport.default;
import { findProjectRoot, makeRelativeProjectConfigPaths } from './paths.js';
/**
* Gets the project info for the given platform from the current working directory
* @param platform the platform for which to get project info
* @returns project root and android project config
*/
export function getProjectInfo<Platform extends 'ios' | 'android'>(
platform: Platform
): {
projectRoot: string;
userConfig: UserConfig;
platformConfig: ProjectConfig[Platform];
} {
const projectRoot = findProjectRoot();
const userConfig = cliConfig({
projectRoot,
selectedPlatform: platform,
});
// below: relative sourceDir path is required by RN CLI's API
const platformConfig = makeRelativeProjectConfigPaths(
projectRoot,
userConfig.project[platform]
);
if (!platformConfig) {
throw new Error(`${platform} project not found.`);
}
return { projectRoot, userConfig, platformConfig };
}
export const getAarConfig = (
args: PackageAarFlags,
androidConfig: AndroidProjectConfig
) => {
const config = {
sourceDir: androidConfig.sourceDir,
moduleName: args.moduleName ?? '',
};
return config;
};