(template: string, args: string, ctx: { cwd: string })
| 203 | |
| 204 | /** Interpolate the template body with the user-supplied args + builtin tokens. */ |
| 205 | export function renderTemplate(template: string, args: string, ctx: { cwd: string }): string { |
| 206 | const positionals = args.length > 0 ? args.split(/\s+/).filter(Boolean) : []; |
| 207 | const now = new Date(); |
| 208 | return template |
| 209 | .replace(/\{\{\s*ARGUMENTS\s*\}\}/g, args) |
| 210 | .replace(/\{\{\s*ARG:(\d+)\s*\}\}/g, (_, idx) => positionals[parseInt(idx, 10)] ?? '') |
| 211 | .replace(/\{\{\s*CWD\s*\}\}/g, ctx.cwd) |
| 212 | .replace(/\{\{\s*DATE\s*\}\}/g, now.toISOString().slice(0, 10)) |
| 213 | .replace(/\{\{\s*TIME\s*\}\}/g, now.toTimeString().slice(0, 8)); |
| 214 | } |
no outgoing calls
no test coverage detected