@@ -74,7 +74,7 @@ const tripletOption = new Option(
7474const buildPathOption = new Option (
7575 "--build <path>" ,
7676 "Specify the build directory to store the configured CMake project" ,
77- ) ;
77+ ) . default ( "{source}/build" ) ;
7878
7979const cleanOption = new Option (
8080 "--clean" ,
@@ -84,7 +84,7 @@ const cleanOption = new Option(
8484const 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
8989const 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+
154163program = 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 { out, 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 }
@@ -197,10 +215,6 @@ program = program.action(
197215 }
198216 }
199217
200- if ( ! baseOptions . out ) {
201- baseOptions . out = path . join ( buildPath , baseOptions . configuration ) ;
202- }
203-
204218 const tripletContexts = [ ...triplets ] . map ( ( triplet ) => {
205219 const platform = findPlatformForTriplet ( triplet ) ;
206220 const tripletBuildPath = getTripletBuildPath ( buildPath , triplet ) ;
@@ -262,7 +276,7 @@ program = program.action(
262276 }
263277 await platform . postBuild (
264278 {
265- outputPath : baseOptions . out || baseOptions . source ,
279+ outputPath : out ,
266280 triplets : relevantTriplets ,
267281 } ,
268282 baseOptions ,
@@ -288,11 +302,6 @@ function getTripletsSummary(
288302 . join ( " / " ) ;
289303}
290304
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-
296305/**
297306 * Namespaces the output path with a triplet name
298307 */
0 commit comments