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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
const {dependencies, platforms} = require('./configuration');
const yargs = require('yargs');
/*::
import type {Dependency, Destination, Platform} from './types';
*/
// CI can't use commas in cache keys, so 'macOS,variant=Mac Catalyst' was creating troubles
// This map that converts from platforms to valid Xcodebuild destinations.
const platformToDestination /*: $ReadOnly<{|[Platform]: Destination|}> */ = {
ios: 'iOS',
'ios-simulator': 'iOS Simulator',
macos: 'macOS',
'mac-catalyst': 'macOS,variant=Mac Catalyst',
tvos: 'tvOS',
'tvos-simulator': 'tvOS Simulator',
xros: 'visionOS',
'xros-simulator': 'visionOS Simulator',
};
const arrayLike = (value /*: Array<any> */) /*: Array<any> */ =>
Array.isArray(value) ? value : [value];
const cli = yargs
.usage(
'This script prepares iOS prebuilds for React Native. It downloads the dependencies, prepare them, builds them and creates the XCFrameworks.' +
'Calling the script with no options will build all the dependencies for all the slices and configurations.',
)
.option('setup', {
alias: 's',
type: 'boolean',
describe: 'Download and setup dependencies',
})
.option('swiftpackage', {
alias: 'w',
type: 'boolean',
describe: 'Creates the Package.swift file',
})
.option('build', {
alias: 'b',
type: 'boolean',
describe: 'Build dependencies/platforms',
})
.option('compose', {
alias: 'c',
type: 'boolean',
describe: 'Compose xcframework from built dependencies',
})
.option('platforms', {
alias: 'p',
type: 'array',
default: platforms,
describe: 'Specify one or more platforms to build for',
})
.option('dependencies', {
alias: 'd',
type: 'array',
default: dependencies.filter(d => !d.disabled).map(d => d.name),
describe: 'Specify one or more dependencies',
})
.option('configuration', {
alias: 'r',
type: 'string',
default: 'Debug',
describe: 'Specify the configuration to build, Release or Debug (default).',
})
.option('identity', {
alias: 'i',
type: 'string',
describe:
'Specify the code signing identity to use for signing the frameworks.',
})
.help();
/**
* Returns the tasks that need to be run based on the command line arguments
*/
async function getCLIConfiguration() /*: Promise<?{|
tasks: {|
setup: boolean,
swiftpackage: boolean,
build: boolean,
compose: boolean,
|},
destinations: $ReadOnlyArray<Destination>,
dependencies: $ReadOnlyArray<Dependency>,
configuration: string,
identity: ?string,
|}> */ {
// Run input parsing
const argv = await cli.argv;
// Verify that the platforms argument is valid
const invalidPlatforms = arrayLike(argv.platforms).filter(
rs => !platforms.includes(rs),
);
if (invalidPlatforms.length > 0) {
console.error(
`Invalid platform specified: ${invalidPlatforms.join(', ')}\nValid platforms are: ${platforms.join(', ')}`,
);
return undefined;
}
// Verify that the dependencies argument is valid
const invalidDependencies = arrayLike(argv.dependencies).filter(
rd => !dependencies.map(d => d.name).includes(rd),
);
if (invalidDependencies.length > 0) {
console.error(
`Invalid dependency specified: ${invalidDependencies.join(', ')}.\nValid dependencies are: ${dependencies
.map(d => d.name)
.join(', ')}`,
);
return undefined;
}
// Prepare platforms and dependencies
const resolvedPlatforms = platforms
.filter(p => argv.platforms.includes(p))
.map(p => platformToDestination[p]);
const resolvedDependencies = dependencies.filter(d =>
argv.dependencies.includes(d.name),
);
// Are we running all commands?
const runAllCommands =
argv.setup == null &&
argv.swiftpackage == null &&
argv.build == null &&
argv.compose == null;
return {
tasks: {
setup: runAllCommands || argv.setup != null,
swiftpackage: runAllCommands || argv.swiftpackage != null,
build: runAllCommands || argv.build != null,
compose: runAllCommands || argv.compose != null,
},
destinations: resolvedPlatforms,
dependencies: resolvedDependencies,
configuration: argv.configuration,
identity: argv.identity,
};
}
module.exports = {getCLIConfiguration};