Skip to content

Commit 6996e73

Browse files
authored
Move prettyPath to cli-utils package (#279)
* Move prettyPath to cli-utils * Use prettyPath more * Removed unused Option
1 parent 0c3e8ba commit 6996e73

File tree

11 files changed

+43
-30
lines changed

11 files changed

+43
-30
lines changed

packages/cli-utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export * from "bufout";
55

66
export * from "./actions.js";
77
export * from "./errors.js";
8+
export * from "./paths.js";

packages/cli-utils/src/paths.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import chalk from "chalk";
2+
import path from "node:path";
3+
4+
export function prettyPath(p: string) {
5+
return chalk.dim(
6+
path.relative(process.cwd(), p) || chalk.italic("current directory"),
7+
);
8+
}

packages/cmake-rn/src/platforms/android.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import assert from "node:assert/strict";
22
import fs from "node:fs";
33
import path from "node:path";
44

5-
import { Option, oraPromise, chalk } from "@react-native-node-api/cli-utils";
5+
import {
6+
Option,
7+
oraPromise,
8+
prettyPath,
9+
} from "@react-native-node-api/cli-utils";
610
import {
711
createAndroidLibsDirectory,
812
AndroidTriplet as Triplet,
@@ -177,9 +181,7 @@ export const platform: Platform<Triplet[], AndroidOpts> = {
177181
}),
178182
{
179183
text: `Assembling Android libs directory (${libraryName})`,
180-
successText: `Android libs directory (${libraryName}) assembled into ${chalk.dim(
181-
path.relative(process.cwd(), prebuildOutputPath),
182-
)}`,
184+
successText: `Android libs directory (${libraryName}) assembled into ${prettyPath(prebuildOutputPath)}`,
183185
failText: ({ message }) =>
184186
`Failed to assemble Android libs directory (${libraryName}): ${message}`,
185187
},

packages/cmake-rn/src/platforms/apple.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import assert from "node:assert/strict";
22
import path from "node:path";
33
import fs from "node:fs";
44

5-
import { Option, oraPromise, chalk } from "@react-native-node-api/cli-utils";
5+
import {
6+
Option,
7+
oraPromise,
8+
prettyPath,
9+
} from "@react-native-node-api/cli-utils";
610
import {
711
AppleTriplet as Triplet,
812
createAppleFramework,
@@ -187,9 +191,7 @@ export const platform: Platform<Triplet[], AppleOpts> = {
187191
}),
188192
{
189193
text: `Assembling XCFramework (${libraryName})`,
190-
successText: `XCFramework (${libraryName}) assembled into ${chalk.dim(
191-
path.relative(process.cwd(), xcframeworkOutputPath),
192-
)}`,
194+
successText: `XCFramework (${libraryName}) assembled into ${prettyPath(xcframeworkOutputPath)}`,
193195
failText: ({ message }) =>
194196
`Failed to assemble XCFramework (${libraryName}): ${message}`,
195197
},

packages/ferric/src/build.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
oraPromise,
99
assertFixable,
1010
wrapAction,
11+
prettyPath,
1112
} from "@react-native-node-api/cli-utils";
1213

1314
import {
@@ -19,7 +20,6 @@ import {
1920
createXCframework,
2021
createUniversalAppleLibrary,
2122
determineLibraryBasename,
22-
prettyPath,
2323
} from "react-native-node-api";
2424

2525
import { ensureCargo, build } from "./cargo.js";
@@ -258,9 +258,7 @@ export const buildCommand = new Command("build")
258258
}),
259259
{
260260
text: "Assembling XCFramework",
261-
successText: `XCFramework assembled into ${chalk.dim(
262-
path.relative(process.cwd(), xcframeworkOutputPath),
263-
)}`,
261+
successText: `XCFramework assembled into ${prettyPath(xcframeworkOutputPath)}`,
264262
failText: ({ message }) =>
265263
`Failed to assemble XCFramework: ${message}`,
266264
},

packages/gyp-to-cmake/src/cli.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
4-
import { Command, wrapAction } from "@react-native-node-api/cli-utils";
3+
import {
4+
Command,
5+
prettyPath,
6+
wrapAction,
7+
} from "@react-native-node-api/cli-utils";
58

69
import { readBindingFile } from "./gyp.js";
710
import {
@@ -29,15 +32,18 @@ export function transformBindingGypFile(
2932
...restOfOptions
3033
}: TransformOptions,
3134
) {
32-
console.log("Transforming", gypPath);
33-
const gyp = readBindingFile(gypPath, disallowUnknownProperties);
3435
const parentPath = path.dirname(gypPath);
36+
const cmakeListsPath = path.join(parentPath, "CMakeLists.txt");
37+
console.log(
38+
`Transforming ${prettyPath(gypPath)}${prettyPath(cmakeListsPath)}`,
39+
);
40+
41+
const gyp = readBindingFile(gypPath, disallowUnknownProperties);
3542
const result = bindingGypToCmakeLists({
3643
gyp,
3744
projectName,
3845
...restOfOptions,
3946
});
40-
const cmakeListsPath = path.join(parentPath, "CMakeLists.txt");
4147
fs.writeFileSync(cmakeListsPath, result, "utf-8");
4248
}
4349

packages/host/src/node/cli/hermes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ import {
99
spawn,
1010
UsageError,
1111
wrapAction,
12+
prettyPath,
1213
} from "@react-native-node-api/cli-utils";
1314
import { packageDirectorySync } from "pkg-dir";
1415

15-
import { prettyPath } from "../path-utils";
16-
1716
const HOST_PACKAGE_ROOT = path.resolve(__dirname, "../../..");
1817
// FIXME: make this configurable with reasonable fallback before public release
1918
const HERMES_GIT_URL = "https://github.com/kraenhansen/hermes.git";

packages/host/src/node/cli/link-modules.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import path from "node:path";
22
import fs from "node:fs";
33

4-
import { chalk, SpawnFailure } from "@react-native-node-api/cli-utils";
4+
import {
5+
chalk,
6+
SpawnFailure,
7+
prettyPath,
8+
} from "@react-native-node-api/cli-utils";
59

610
import {
711
findNodeApiModulePathsByDependency,
@@ -10,7 +14,6 @@ import {
1014
logModulePaths,
1115
NamingStrategy,
1216
PlatformName,
13-
prettyPath,
1417
} from "../path-utils";
1518

1619
export type ModuleLinker = (

packages/host/src/node/cli/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SpawnFailure,
99
oraPromise,
1010
wrapAction,
11+
prettyPath,
1112
} from "@react-native-node-api/cli-utils";
1213

1314
import {
@@ -19,7 +20,6 @@ import {
1920
normalizeModulePath,
2021
PlatformName,
2122
PLATFORMS,
22-
prettyPath,
2323
} from "../path-utils";
2424

2525
import { command as vendorHermes } from "./hermes";

packages/host/src/node/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ export {
2222
determineXCFrameworkFilename,
2323
} from "./prebuilds/apple.js";
2424

25-
export { determineLibraryBasename, prettyPath } from "./path-utils.js";
25+
export { determineLibraryBasename } from "./path-utils.js";
2626

2727
export { weakNodeApiPath } from "./weak-node-api.js";

0 commit comments

Comments
 (0)