(template: string, filePath: string)
| 48 | /** Build the local argv from a template + file path. Substitutes `{file}`; appends it when the |
| 49 | * template has no placeholder. Returns `['sh','-c', …]` so a normal command line Just Works. PURE. */ |
| 50 | export function buildCommand(template: string, filePath: string): string[] { |
| 51 | const line = template.includes('{file}') |
| 52 | ? template.replaceAll('{file}', shellQuote(filePath)) |
| 53 | : `${template} ${shellQuote(filePath)}`; |
| 54 | return ['sh', '-c', line]; |
| 55 | } |
| 56 | |
| 57 | function shellQuote(s: string): string { |
| 58 | return `'${s.replaceAll("'", `'\\''`)}'`; |
no test coverage detected