Skip to content

Commit 8e2b988

Browse files
committed
Reverting f82239c
1 parent 02ef3ce commit 8e2b988

File tree

1 file changed

+88
-105
lines changed

1 file changed

+88
-105
lines changed

packages/cmake-rn/src/cli.ts

Lines changed: 88 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Command,
99
Option,
1010
spawn,
11-
SpawnFailure,
1211
oraPromise,
1312
} from "@react-native-node-api/cli-utils";
1413
import { isSupportedTriplet } from "react-native-node-api";
@@ -132,126 +131,110 @@ for (const platform of platforms) {
132131

133132
program = program.action(
134133
async ({ target: requestedTargets, ...baseOptions }) => {
135-
try {
136-
const buildPath = getBuildPath(baseOptions);
137-
if (baseOptions.clean) {
138-
await fs.promises.rm(buildPath, { recursive: true, force: true });
134+
const buildPath = getBuildPath(baseOptions);
135+
if (baseOptions.clean) {
136+
await fs.promises.rm(buildPath, { recursive: true, force: true });
137+
}
138+
const targets = new Set<string>(requestedTargets);
139+
140+
for (const platform of Object.values(platforms)) {
141+
// Forcing the types a bit here, since the platform id option is dynamically added
142+
if ((baseOptions as Record<string, unknown>)[platform.id]) {
143+
for (const target of platform.targets) {
144+
targets.add(target);
145+
}
139146
}
140-
const targets = new Set<string>(requestedTargets);
147+
}
141148

149+
if (targets.size === 0) {
142150
for (const platform of Object.values(platforms)) {
143-
// Forcing the types a bit here, since the platform id option is dynamically added
144-
if ((baseOptions as Record<string, unknown>)[platform.id]) {
145-
for (const target of platform.targets) {
151+
if (platform.isSupportedByHost()) {
152+
for (const target of await platform.defaultTargets()) {
146153
targets.add(target);
147154
}
148155
}
149156
}
150-
151157
if (targets.size === 0) {
152-
for (const platform of Object.values(platforms)) {
153-
if (platform.isSupportedByHost()) {
154-
for (const target of await platform.defaultTargets()) {
155-
targets.add(target);
156-
}
157-
}
158-
}
159-
if (targets.size === 0) {
160-
throw new Error(
161-
"Found no default targets: Install some platform specific build tools",
162-
);
163-
} else {
164-
console.error(
165-
chalk.yellowBright("ℹ"),
166-
"Using default targets",
167-
chalk.dim("(" + [...targets].join(", ") + ")"),
168-
);
169-
}
158+
throw new Error(
159+
"Found no default targets: Install some platform specific build tools",
160+
);
161+
} else {
162+
console.error(
163+
chalk.yellowBright("ℹ"),
164+
"Using default targets",
165+
chalk.dim("(" + [...targets].join(", ") + ")"),
166+
);
170167
}
168+
}
171169

172-
if (!baseOptions.out) {
173-
baseOptions.out = path.join(buildPath, baseOptions.configuration);
174-
}
170+
if (!baseOptions.out) {
171+
baseOptions.out = path.join(buildPath, baseOptions.configuration);
172+
}
175173

176-
const targetContexts = [...targets].map((target) => {
177-
const platform = findPlatformForTarget(target);
178-
const targetBuildPath = getTargetBuildPath(buildPath, target);
179-
return {
180-
target,
181-
platform,
182-
buildPath: targetBuildPath,
183-
outputPath: path.join(targetBuildPath, "out"),
184-
options: baseOptions,
185-
};
186-
});
187-
188-
// Configure every triplet project
189-
const targetsSummary = chalk.dim(
190-
`(${getTargetsSummary(targetContexts)})`,
191-
);
192-
await oraPromise(
193-
Promise.all(
194-
targetContexts.map(({ platform, ...context }) =>
195-
configureProject(platform, context, baseOptions),
196-
),
174+
const targetContexts = [...targets].map((target) => {
175+
const platform = findPlatformForTarget(target);
176+
const targetBuildPath = getTargetBuildPath(buildPath, target);
177+
return {
178+
target,
179+
platform,
180+
buildPath: targetBuildPath,
181+
outputPath: path.join(targetBuildPath, "out"),
182+
options: baseOptions,
183+
};
184+
});
185+
186+
// Configure every triplet project
187+
const targetsSummary = chalk.dim(`(${getTargetsSummary(targetContexts)})`);
188+
await oraPromise(
189+
Promise.all(
190+
targetContexts.map(({ platform, ...context }) =>
191+
configureProject(platform, context, baseOptions),
197192
),
198-
{
199-
text: `Configuring projects ${targetsSummary}`,
200-
isSilent: baseOptions.verbose,
201-
successText: `Configured projects ${targetsSummary}`,
202-
failText: ({ message }) => `Failed to configure projects: ${message}`,
203-
},
204-
);
193+
),
194+
{
195+
text: `Configuring projects ${targetsSummary}`,
196+
isSilent: baseOptions.verbose,
197+
successText: `Configured projects ${targetsSummary}`,
198+
failText: ({ message }) => `Failed to configure projects: ${message}`,
199+
},
200+
);
205201

206-
// Build every triplet project
207-
await oraPromise(
208-
Promise.all(
209-
targetContexts.map(async ({ platform, ...context }) => {
210-
// Delete any stale build artifacts before building
211-
// This is important, since we might rename the output files
212-
await fs.promises.rm(context.outputPath, {
213-
recursive: true,
214-
force: true,
215-
});
216-
await buildProject(platform, context, baseOptions);
217-
}),
218-
),
202+
// Build every triplet project
203+
await oraPromise(
204+
Promise.all(
205+
targetContexts.map(async ({ platform, ...context }) => {
206+
// Delete any stale build artifacts before building
207+
// This is important, since we might rename the output files
208+
await fs.promises.rm(context.outputPath, {
209+
recursive: true,
210+
force: true,
211+
});
212+
await buildProject(platform, context, baseOptions);
213+
}),
214+
),
215+
{
216+
text: "Building projects",
217+
isSilent: baseOptions.verbose,
218+
successText: "Built projects",
219+
failText: ({ message }) => `Failed to build projects: ${message}`,
220+
},
221+
);
222+
223+
// Perform post-build steps for each platform in sequence
224+
for (const platform of platforms) {
225+
const relevantTargets = targetContexts.filter(({ target }) =>
226+
platformHasTarget(platform, target),
227+
);
228+
if (relevantTargets.length == 0) {
229+
continue;
230+
}
231+
await platform.postBuild(
219232
{
220-
text: "Building projects",
221-
isSilent: baseOptions.verbose,
222-
successText: "Built projects",
223-
failText: ({ message }) => `Failed to build projects: ${message}`,
233+
outputPath: baseOptions.out || baseOptions.source,
234+
targets: relevantTargets,
224235
},
236+
baseOptions,
225237
);
226-
227-
// Perform post-build steps for each platform in sequence
228-
for (const platform of platforms) {
229-
const relevantTargets = targetContexts.filter(({ target }) =>
230-
platformHasTarget(platform, target),
231-
);
232-
if (relevantTargets.length == 0) {
233-
continue;
234-
}
235-
await platform.postBuild(
236-
{
237-
outputPath: baseOptions.out || baseOptions.source,
238-
targets: relevantTargets,
239-
},
240-
baseOptions,
241-
);
242-
}
243-
} catch (error) {
244-
if (error instanceof SpawnFailure) {
245-
process.exitCode = 1;
246-
error.flushOutput("both");
247-
if (baseOptions.verbose) {
248-
console.error(
249-
`\nFailed running: ${chalk.dim(error.command, ...error.args)}\n`,
250-
);
251-
}
252-
} else {
253-
throw error;
254-
}
255238
}
256239
},
257240
);

0 commit comments

Comments
 (0)