@@ -4,14 +4,18 @@ import { ResultAsync } from "@/result";
44import { errorToMessage } from "./error" ;
55import { PromiseWithResolvers } from "./promise" ;
66
7- export const $ = ( cmd : TemplateStringsArray | string ) => {
8- const command = isString ( cmd ) ? cmd : cmd [ 0 ] ! ;
7+ export function $ ( cmd : string ) : ResultAsync < { stdout : string ; stderr : string } , string > ;
8+ export function $ (
9+ cmd : TemplateStringsArray ,
10+ ...values : any [ ]
11+ ) : ResultAsync < { stdout : string ; stderr : string } , string > ;
12+ export function $ ( cmd : string | TemplateStringsArray , ...values : any [ ] ) {
13+ const command = isString ( cmd )
14+ ? cmd
15+ : cmd . reduce ( ( acc , part , index ) => acc + part + ( values [ index ] ?? "" ) , "" ) ;
916
1017 const promise = import ( "node:child_process" ) . then ( ( { exec } ) => {
11- const { promise, reject, resolve } = PromiseWithResolvers < {
12- stdout : string ;
13- stderr : string ;
14- } > ( ) ;
18+ const { promise, reject, resolve } = PromiseWithResolvers ( ) ;
1519
1620 exec ( command , ( error , stdout , stderr ) => {
1721 if ( error ) {
@@ -25,4 +29,4 @@ export const $ = (cmd: TemplateStringsArray | string) => {
2529 } ) ;
2630
2731 return ResultAsync . fromPromise ( promise , errorToMessage ( `Failed to execute command: ${ cmd } ` ) ) ;
28- } ;
32+ }
0 commit comments