Skip to content

Commit a9857c6

Browse files
committed
Fix expansion of options in --build and --out
1 parent b1d0dde commit a9857c6

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

.changeset/fresh-frogs-enter.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cmake-rn": patch
3+
---
4+
5+
Fix expansion of options in --build and --out

packages/cmake-rn/src/cli.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const tripletOption = new Option(
7474
const buildPathOption = new Option(
7575
"--build <path>",
7676
"Specify the build directory to store the configured CMake project",
77-
);
77+
).default("{source}/build");
7878

7979
const cleanOption = new Option(
8080
"--clean",
@@ -84,7 +84,7 @@ const cleanOption = new Option(
8484
const outPathOption = new Option(
8585
"--out <path>",
8686
"Specify the output directory to store the final build artifacts",
87-
).default(false, "./{build}/{configuration}");
87+
).default("./{build}/{configuration}");
8888

8989
const defineOption = new Option(
9090
"-D,--define <entry...>",
@@ -151,8 +151,27 @@ for (const platform of platforms) {
151151
program = platform.amendCommand(program);
152152
}
153153

154+
function expandTemplate(
155+
input: string,
156+
values: Record<string, unknown>,
157+
): string {
158+
return input.replaceAll(/{([^}]+)}/g, (_, key: string) =>
159+
typeof values[key] === "string" ? values[key] : "",
160+
);
161+
}
162+
154163
program = program.action(
155164
wrapAction(async ({ triplet: requestedTriplets, ...baseOptions }) => {
165+
baseOptions.build = path.resolve(
166+
process.cwd(),
167+
expandTemplate(baseOptions.build, baseOptions),
168+
);
169+
baseOptions.out = path.resolve(
170+
process.cwd(),
171+
expandTemplate(baseOptions.out, baseOptions),
172+
);
173+
const { verbose, clean, source, build: buildPath } = baseOptions;
174+
156175
assertFixable(
157176
fs.existsSync(path.join(baseOptions.source, "CMakeLists.txt")),
158177
`No CMakeLists.txt found in source directory: ${chalk.dim(baseOptions.source)}`,
@@ -161,7 +180,6 @@ program = program.action(
161180
},
162181
);
163182

164-
const buildPath = getBuildPath(baseOptions);
165183
if (baseOptions.clean) {
166184
await fs.promises.rm(buildPath, { recursive: true, force: true });
167185
}
@@ -288,11 +306,6 @@ function getTripletsSummary(
288306
.join(" / ");
289307
}
290308

291-
function getBuildPath({ build, source }: BaseOpts) {
292-
// TODO: Add configuration (debug vs release)
293-
return path.resolve(process.cwd(), build || path.join(source, "build"));
294-
}
295-
296309
/**
297310
* Namespaces the output path with a triplet name
298311
*/

0 commit comments

Comments
 (0)