Skip to content

Commit

Permalink
feat: handle filenames with variables between brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano committed Jan 10, 2023
1 parent b1f915c commit 7edad45
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ const render = (data, variables) =>
return result;
}, data.toString());

const renderFilePath = (data, variables) =>
Object.entries(variables).reduce((rendered, [varname, varvalue]) => {
const result = rendered.replace(
new RegExp(`\\[ {0,}?${varname}{0,}?\\]`, 'g'),
varvalue
);
return result;
}, data.toString());

export default async function Renderer({
source,
output,
Expand All @@ -40,7 +49,7 @@ export default async function Renderer({

const outpath = path.resolve(
output,
path.relative(path.resolve(source), filepath)
path.relative(path.resolve(source), renderFilePath(filepath, env))
);

if (!config.dryRun) {
Expand Down

0 comments on commit 7edad45

Please sign in to comment.