-
Notifications
You must be signed in to change notification settings - Fork 949
Expand file tree
/
Copy pathindex.ts
More file actions
102 lines (88 loc) · 2.74 KB
/
Copy pathindex.ts
File metadata and controls
102 lines (88 loc) · 2.74 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import path from 'path';
import pico from 'picocolors';
import fs from 'fs';
import findPodfilePath from './findPodfilePath';
import findXcodeProject from './findXcodeProject';
import findPodspec from './findPodspec';
import findAllPodfilePaths from './findAllPodfilePaths';
import {
IOSProjectParams,
IOSDependencyParams,
IOSProjectConfig,
IOSDependencyConfig,
} from '@react-native-community/cli-types';
import {CLIError} from '@react-native-community/cli-tools';
import {BuilderCommand} from '../types';
/**
* Returns project config by analyzing given folder and applying some user defaults
* when constructing final object
*/
export const getProjectConfig =
({platformName}: BuilderCommand) =>
(folder: string, userConfig: IOSProjectParams): IOSProjectConfig | null => {
if (!userConfig) {
return null;
}
const src = path.join(folder, userConfig.sourceDir ?? '');
const podfile = findPodfilePath(src, platformName);
/**
* In certain repos, the Xcode project can be generated by a tool.
* The only file that we can assume to exist on disk is `Podfile`.
*/
if (!podfile) {
return null;
}
const sourceDir = path.dirname(podfile);
const xcodeProject = findXcodeProject(fs.readdirSync(sourceDir));
return {
sourceDir,
watchModeCommandParams: userConfig.watchModeCommandParams,
xcodeProject,
automaticPodsInstallation: userConfig.automaticPodsInstallation,
assets: userConfig.assets ?? [],
};
};
/**
* Make getDependencyConfig follow the same pattern as getProjectConfig
*/
export const getDependencyConfig =
({}: BuilderCommand) =>
(
folder: string,
userConfig: IOSDependencyParams | null = {},
): IOSDependencyConfig | null => {
if (userConfig === null) {
return null;
}
const podspecPath = findPodspec(folder);
if (!podspecPath) {
return null;
}
let version = 'unresolved';
try {
const packageJson = require(path.join(folder, 'package.json'));
if (packageJson.version) {
version = packageJson.version;
}
} catch {
throw new CLIError(
`Failed to locate package.json file from ${pico.underline(
folder,
)}. This is most likely issue with your node_modules folder being corrupted. Please force install dependencies and try again`,
);
}
return {
podspecPath,
version,
configurations: userConfig.configurations || [],
scriptPhases: userConfig.scriptPhases || [],
};
};
export const findPodfilePaths = findAllPodfilePaths;