Feat: subfile overrides (#2941)

* Adds overrides parameter to Packer methods and compiler

* Adds tests for overrides parameter

* Update Packer usage examples
This commit is contained in:
adamSherwoodGenieAI
2025-01-27 02:39:23 -08:00
committed by GitHub
parent eb2174e566
commit 05fcf6edd4
5 changed files with 136 additions and 17 deletions

View File

@ -9,7 +9,7 @@ import { ImageReplacer } from "./image-replacer";
import { NumberingReplacer } from "./numbering-replacer";
import { PrettifyType } from "./packer";
type IXmlifyedFile = {
export type IXmlifyedFile = {
readonly data: string;
readonly path: string;
};
@ -47,7 +47,11 @@ export class Compiler {
this.numberingReplacer = new NumberingReplacer();
}
public compile(file: File, prettifyXml?: (typeof PrettifyType)[keyof typeof PrettifyType]): JSZip {
public compile(
file: File,
prettifyXml?: (typeof PrettifyType)[keyof typeof PrettifyType],
overrides: readonly IXmlifyedFile[] = [],
): JSZip {
const zip = new JSZip();
const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml);
const map = new Map<string, IXmlifyedFile | readonly IXmlifyedFile[]>(Object.entries(xmlifiedFileMapping));
@ -62,6 +66,10 @@ export class Compiler {
}
}
for (const subFile of overrides) {
zip.file(subFile.path, subFile.data);
}
for (const data of file.Media.Array) {
if (data.type !== "svg") {
zip.file(`word/media/${data.fileName}`, data.data);