diff --git a/packages/cli-utils/src/index.ts b/packages/cli-utils/src/index.ts index bf9232fa..0fa6ff4a 100644 --- a/packages/cli-utils/src/index.ts +++ b/packages/cli-utils/src/index.ts @@ -5,3 +5,4 @@ export * from "bufout"; export * from "./actions.js"; export * from "./errors.js"; +export * from "./paths.js"; diff --git a/packages/cli-utils/src/paths.ts b/packages/cli-utils/src/paths.ts new file mode 100644 index 00000000..6ff8bd2e --- /dev/null +++ b/packages/cli-utils/src/paths.ts @@ -0,0 +1,8 @@ +import chalk from "chalk"; +import path from "node:path"; + +export function prettyPath(p: string) { + return chalk.dim( + path.relative(process.cwd(), p) || chalk.italic("current directory"), + ); +} diff --git a/packages/cmake-rn/src/platforms/android.ts b/packages/cmake-rn/src/platforms/android.ts index dbf9d887..b7b758c3 100644 --- a/packages/cmake-rn/src/platforms/android.ts +++ b/packages/cmake-rn/src/platforms/android.ts @@ -2,7 +2,11 @@ import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; -import { Option, oraPromise, chalk } from "@react-native-node-api/cli-utils"; +import { + Option, + oraPromise, + prettyPath, +} from "@react-native-node-api/cli-utils"; import { createAndroidLibsDirectory, AndroidTriplet as Triplet, @@ -177,9 +181,7 @@ export const platform: Platform = { }), { text: `Assembling Android libs directory (${libraryName})`, - successText: `Android libs directory (${libraryName}) assembled into ${chalk.dim( - path.relative(process.cwd(), prebuildOutputPath), - )}`, + successText: `Android libs directory (${libraryName}) assembled into ${prettyPath(prebuildOutputPath)}`, failText: ({ message }) => `Failed to assemble Android libs directory (${libraryName}): ${message}`, }, diff --git a/packages/cmake-rn/src/platforms/apple.ts b/packages/cmake-rn/src/platforms/apple.ts index 849ccfe5..91f5e7fd 100644 --- a/packages/cmake-rn/src/platforms/apple.ts +++ b/packages/cmake-rn/src/platforms/apple.ts @@ -2,7 +2,11 @@ import assert from "node:assert/strict"; import path from "node:path"; import fs from "node:fs"; -import { Option, oraPromise, chalk } from "@react-native-node-api/cli-utils"; +import { + Option, + oraPromise, + prettyPath, +} from "@react-native-node-api/cli-utils"; import { AppleTriplet as Triplet, createAppleFramework, @@ -187,9 +191,7 @@ export const platform: Platform = { }), { text: `Assembling XCFramework (${libraryName})`, - successText: `XCFramework (${libraryName}) assembled into ${chalk.dim( - path.relative(process.cwd(), xcframeworkOutputPath), - )}`, + successText: `XCFramework (${libraryName}) assembled into ${prettyPath(xcframeworkOutputPath)}`, failText: ({ message }) => `Failed to assemble XCFramework (${libraryName}): ${message}`, }, diff --git a/packages/ferric/src/build.ts b/packages/ferric/src/build.ts index 2bd0bded..fdf961e3 100644 --- a/packages/ferric/src/build.ts +++ b/packages/ferric/src/build.ts @@ -8,6 +8,7 @@ import { oraPromise, assertFixable, wrapAction, + prettyPath, } from "@react-native-node-api/cli-utils"; import { @@ -19,7 +20,6 @@ import { createXCframework, createUniversalAppleLibrary, determineLibraryBasename, - prettyPath, } from "react-native-node-api"; import { ensureCargo, build } from "./cargo.js"; @@ -258,9 +258,7 @@ export const buildCommand = new Command("build") }), { text: "Assembling XCFramework", - successText: `XCFramework assembled into ${chalk.dim( - path.relative(process.cwd(), xcframeworkOutputPath), - )}`, + successText: `XCFramework assembled into ${prettyPath(xcframeworkOutputPath)}`, failText: ({ message }) => `Failed to assemble XCFramework: ${message}`, }, diff --git a/packages/gyp-to-cmake/src/cli.ts b/packages/gyp-to-cmake/src/cli.ts index 52d14984..1045ba45 100644 --- a/packages/gyp-to-cmake/src/cli.ts +++ b/packages/gyp-to-cmake/src/cli.ts @@ -1,7 +1,10 @@ import fs from "node:fs"; import path from "node:path"; - -import { Command, wrapAction } from "@react-native-node-api/cli-utils"; +import { + Command, + prettyPath, + wrapAction, +} from "@react-native-node-api/cli-utils"; import { readBindingFile } from "./gyp.js"; import { @@ -29,15 +32,18 @@ export function transformBindingGypFile( ...restOfOptions }: TransformOptions, ) { - console.log("Transforming", gypPath); - const gyp = readBindingFile(gypPath, disallowUnknownProperties); const parentPath = path.dirname(gypPath); + const cmakeListsPath = path.join(parentPath, "CMakeLists.txt"); + console.log( + `Transforming ${prettyPath(gypPath)} → ${prettyPath(cmakeListsPath)}`, + ); + + const gyp = readBindingFile(gypPath, disallowUnknownProperties); const result = bindingGypToCmakeLists({ gyp, projectName, ...restOfOptions, }); - const cmakeListsPath = path.join(parentPath, "CMakeLists.txt"); fs.writeFileSync(cmakeListsPath, result, "utf-8"); } diff --git a/packages/host/src/node/cli/hermes.ts b/packages/host/src/node/cli/hermes.ts index 817b7524..541a324e 100644 --- a/packages/host/src/node/cli/hermes.ts +++ b/packages/host/src/node/cli/hermes.ts @@ -9,11 +9,10 @@ import { spawn, UsageError, wrapAction, + prettyPath, } from "@react-native-node-api/cli-utils"; import { packageDirectorySync } from "pkg-dir"; -import { prettyPath } from "../path-utils"; - const HOST_PACKAGE_ROOT = path.resolve(__dirname, "../../.."); // FIXME: make this configurable with reasonable fallback before public release const HERMES_GIT_URL = "https://github.com/kraenhansen/hermes.git"; diff --git a/packages/host/src/node/cli/link-modules.ts b/packages/host/src/node/cli/link-modules.ts index 9b44d921..8b3bf2e0 100644 --- a/packages/host/src/node/cli/link-modules.ts +++ b/packages/host/src/node/cli/link-modules.ts @@ -1,7 +1,11 @@ import path from "node:path"; import fs from "node:fs"; -import { chalk, SpawnFailure } from "@react-native-node-api/cli-utils"; +import { + chalk, + SpawnFailure, + prettyPath, +} from "@react-native-node-api/cli-utils"; import { findNodeApiModulePathsByDependency, @@ -10,7 +14,6 @@ import { logModulePaths, NamingStrategy, PlatformName, - prettyPath, } from "../path-utils"; export type ModuleLinker = ( diff --git a/packages/host/src/node/cli/program.ts b/packages/host/src/node/cli/program.ts index 37950d6d..cba9994a 100644 --- a/packages/host/src/node/cli/program.ts +++ b/packages/host/src/node/cli/program.ts @@ -8,6 +8,7 @@ import { SpawnFailure, oraPromise, wrapAction, + prettyPath, } from "@react-native-node-api/cli-utils"; import { @@ -19,7 +20,6 @@ import { normalizeModulePath, PlatformName, PLATFORMS, - prettyPath, } from "../path-utils"; import { command as vendorHermes } from "./hermes"; diff --git a/packages/host/src/node/index.ts b/packages/host/src/node/index.ts index 878eeb01..dd914402 100644 --- a/packages/host/src/node/index.ts +++ b/packages/host/src/node/index.ts @@ -22,6 +22,6 @@ export { determineXCFrameworkFilename, } from "./prebuilds/apple.js"; -export { determineLibraryBasename, prettyPath } from "./path-utils.js"; +export { determineLibraryBasename } from "./path-utils.js"; export { weakNodeApiPath } from "./weak-node-api.js"; diff --git a/packages/host/src/node/path-utils.ts b/packages/host/src/node/path-utils.ts index 1fe6170e..9ac1da93 100644 --- a/packages/host/src/node/path-utils.ts +++ b/packages/host/src/node/path-utils.ts @@ -5,7 +5,7 @@ import { packageDirectorySync } from "pkg-dir"; import { readPackageSync } from "read-pkg"; import { createRequire } from "node:module"; -import { chalk } from "@react-native-node-api/cli-utils"; +import { chalk, prettyPath } from "@react-native-node-api/cli-utils"; import { findDuplicates } from "./duplicates"; @@ -194,12 +194,6 @@ export function getLibraryName(modulePath: string, naming: NamingStrategy) { )}`; } -export function prettyPath(p: string) { - return chalk.dim( - path.relative(process.cwd(), p) || chalk.italic("current directory"), - ); -} - export function resolvePackageRoot( requireFromPackageRoot: NodeJS.Require, packageName: string,