Skip to content

Commit 2705d9d

Browse files
liamjonesgrabbou
andauthored
feat: use xcbeautify for xcodebuild output if installed (react-native-community#1392)
* feat: use xcbeautify for xcodebuild output if installed The run-ios command already detects and uses xcpretty (https://github.com/xcpretty/xcpretty) if it's available. This commit adds support for another xcodebuild output formatter, xcbeautify (https://github.com/thii/xcbeautify). The logic for what is used is as follows: 1. If xcbeautify is available use it 2. If xcbeautify isn't available but xcpretty is use xcpretty 3. If neither are available fallback to raw xcodebuild output * chore: styling Co-authored-by: Mike Grabowski <[email protected]>
1 parent 4463ac6 commit 2705d9d

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

docs/commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ Do not launch packager while building.
443443

444444
#### `--verbose`
445445

446-
Do not use `xcpretty` even if installed.
446+
Do not use `xcbeautify` or `xcpretty` even if installed.
447447

448448
#### `--port <number>`
449449

packages/platform-ios/src/commands/runIOS/index.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,17 @@ function buildProject(
313313
`(using "xcodebuild ${xcodebuildArgs.join(' ')}")`,
314314
)}`,
315315
);
316-
let xcpretty: ChildProcess | any;
316+
let xcodebuildOutputFormatter: ChildProcess | any;
317317
if (!args.verbose) {
318-
xcpretty =
319-
xcprettyAvailable() &&
320-
child_process.spawn('xcpretty', [], {
318+
if (xcbeautifyAvailable()) {
319+
xcodebuildOutputFormatter = child_process.spawn('xcbeautify', [], {
321320
stdio: ['pipe', process.stdout, process.stderr],
322321
});
322+
} else if (xcprettyAvailable()) {
323+
xcodebuildOutputFormatter = child_process.spawn('xcpretty', [], {
324+
stdio: ['pipe', process.stdout, process.stderr],
325+
});
326+
}
323327
}
324328
const buildProcess = child_process.spawn(
325329
'xcodebuild',
@@ -331,8 +335,8 @@ function buildProject(
331335
buildProcess.stdout.on('data', (data: Buffer) => {
332336
const stringData = data.toString();
333337
buildOutput += stringData;
334-
if (xcpretty) {
335-
xcpretty.stdin.write(data);
338+
if (xcodebuildOutputFormatter) {
339+
xcodebuildOutputFormatter.stdin.write(data);
336340
} else {
337341
if (logger.isVerbose()) {
338342
logger.debug(stringData);
@@ -347,8 +351,8 @@ function buildProject(
347351
errorOutput += data;
348352
});
349353
buildProcess.on('close', (code: number) => {
350-
if (xcpretty) {
351-
xcpretty.stdin.end();
354+
if (xcodebuildOutputFormatter) {
355+
xcodebuildOutputFormatter.stdin.end();
352356
} else {
353357
loader.stop();
354358
}
@@ -454,6 +458,17 @@ function getPlatformName(buildOutput: string) {
454458
return platformNameMatch[1];
455459
}
456460

461+
function xcbeautifyAvailable() {
462+
try {
463+
child_process.execSync('xcbeautify --version', {
464+
stdio: [0, 'pipe', 'ignore'],
465+
});
466+
} catch (error) {
467+
return false;
468+
}
469+
return true;
470+
}
471+
457472
function xcprettyAvailable() {
458473
try {
459474
child_process.execSync('xcpretty --version', {
@@ -600,7 +615,7 @@ export default {
600615
},
601616
{
602617
name: '--verbose',
603-
description: 'Do not use xcpretty even if installed',
618+
description: 'Do not use xcbeautify or xcpretty even if installed',
604619
},
605620
{
606621
name: '--port <number>',

0 commit comments

Comments
 (0)