feat: TypeScript installation wizard with @clack/prompts TUI (#1)
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #1.
This commit is contained in:
26
src/template/engine.ts
Normal file
26
src/template/engine.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export interface TemplateVars {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces {{PLACEHOLDER}} tokens with provided values.
|
||||
* Does NOT expand ${ENV_VAR} syntax — those pass through for shell resolution.
|
||||
*/
|
||||
export function renderTemplate(
|
||||
template: string,
|
||||
vars: TemplateVars,
|
||||
options: { strict?: boolean } = {},
|
||||
): string {
|
||||
return template.replace(
|
||||
/\{\{([A-Z_][A-Z0-9_]*)\}\}/g,
|
||||
(match, varName: string) => {
|
||||
if (varName in vars) {
|
||||
return vars[varName];
|
||||
}
|
||||
if (options.strict) {
|
||||
throw new Error(`Template variable not provided: {{${varName}}}`);
|
||||
}
|
||||
return '';
|
||||
},
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user