-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): print the command being invoked during build (#3325)
- Loading branch information
Showing
4 changed files
with
45 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@rnx-kit/cli": patch | ||
--- | ||
|
||
Print the command being invoked during build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,26 @@ | ||
import type { Config } from "@react-native-community/cli-types"; | ||
import ora from "ora"; | ||
import type { AndroidBuildParams } from "./types"; | ||
import { watch } from "./watcher"; | ||
|
||
export async function buildAndroid( | ||
export type BuildResult = string | number | null; | ||
|
||
export function buildAndroid( | ||
config: Config, | ||
buildParams: AndroidBuildParams, | ||
logger = ora() | ||
): Promise<string | number | null> { | ||
): Promise<BuildResult> { | ||
const { sourceDir } = config.project.android ?? {}; | ||
if (!sourceDir) { | ||
logger.fail("No Android project was found"); | ||
process.exitCode = 1; | ||
return null; | ||
return Promise.resolve(null); | ||
} | ||
|
||
return import("@rnx-kit/tools-android").then(({ assemble }) => { | ||
return new Promise((resolve) => { | ||
logger.start("Building"); | ||
|
||
const errors: Buffer[] = []; | ||
return new Promise<BuildResult>((resolve) => { | ||
const gradle = assemble(sourceDir, buildParams); | ||
|
||
gradle.stdout.on("data", () => (logger.text += ".")); | ||
gradle.stderr.on("data", (data) => errors.push(data)); | ||
|
||
gradle.on("close", (code) => { | ||
if (code === 0) { | ||
logger.succeed("Build succeeded"); | ||
resolve(sourceDir); | ||
} else { | ||
logger.fail(Buffer.concat(errors).toString()); | ||
process.exitCode = code ?? 1; | ||
resolve(code); | ||
} | ||
}); | ||
watch(gradle, logger, () => resolve(sourceDir), resolve); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { ChildProcessWithoutNullStreams } from "node:child_process"; | ||
import type { Ora } from "ora"; | ||
|
||
export function watch( | ||
subproc: ChildProcessWithoutNullStreams, | ||
logger: Ora, | ||
onSuccess: () => void, | ||
onFail: (exitCode: number | null) => void | ||
) { | ||
subproc.stdout.on("data", () => (logger.text += ".")); | ||
|
||
const errors: Buffer[] = []; | ||
subproc.stderr.on("data", (data) => errors.push(data)); | ||
|
||
subproc.on("close", (code) => { | ||
if (code === 0) { | ||
logger.succeed("Build succeeded"); | ||
onSuccess(); | ||
} else { | ||
logger.fail(Buffer.concat(errors).toString()); | ||
process.exitCode = code ?? 1; | ||
onFail(code); | ||
} | ||
}); | ||
|
||
logger.info(`Command: ${subproc.spawnargs.join(" ")}`); | ||
logger.start("Building"); | ||
} |