Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/build/src/packaging/package/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,19 @@ export async function generateDirFromTemplate(sourceDir: string, interpolations:
await copyDirAndApplyTemplates(sourceFile, targetFile);
} else {
const sourceText = await fs.readFile(sourceFile, 'utf8');
const interpolatedText = sourceText.replace(
/\{\{(\w+)\}\}/g,
(_match, identifier) => {
if (!(identifier in interpolations)) {
throw new Error(`Need ${identifier} for replacement in ${sourceFile}`);
}
return interpolations[identifier];
});
await fs.writeFile(targetFile, interpolatedText);
if (!sourceText.includes('\ufffd')) { // This is valid UTF-8, i.e. a text file
const interpolatedText = sourceText.replace(
/\{\{(\w+)\}\}/g,
(_match, identifier) => {
if (!(identifier in interpolations)) {
throw new Error(`Need ${identifier} for replacement in ${sourceFile}`);
}
return interpolations[identifier];
});
await fs.writeFile(targetFile, interpolatedText);
} else {
await fs.copyFile(sourceFile, targetFile);
}
}
}
}
Expand Down