diff --git a/src/export/packer/compiler.ts b/src/export/packer/compiler.ts index aae80d9ff7..545897beb0 100644 --- a/src/export/packer/compiler.ts +++ b/src/export/packer/compiler.ts @@ -1,14 +1,11 @@ import * as archiver from "archiver"; import * as express from "express"; import * as fs from "fs"; -import * as path from "path"; import * as xml from "xml"; import { File } from "file"; import { Formatter } from "../formatter"; -const TEMPLATE_PATH = path.resolve(__dirname, "../../../template"); - export class Compiler { protected archive: archiver.Archiver; private formatter: Formatter; @@ -24,13 +21,6 @@ export class Compiler { public async compile(output: fs.WriteStream | express.Response): Promise { this.archive.pipe(output); - this.archive.glob("**", { - cwd: TEMPLATE_PATH, - }); - - this.archive.glob("**/.rels", { - cwd: TEMPLATE_PATH, - }); const xmlDocument = xml(this.formatter.format(this.file.Document), true); const xmlStyles = xml(this.formatter.format(this.file.Styles)); @@ -47,7 +37,8 @@ export class Compiler { const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer)); const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships)); const xmlFooterRelationships = xml(this.formatter.format(this.file.Footer.Relationships)); - // const xmlContentTypes = xml(this.formatter.format(this.file.ContentTypes)); + const xmlContentTypes = xml(this.formatter.format(this.file.ContentTypes)); + const xmlAppProperties = xml(this.formatter.format(this.file.AppProperties)); this.archive.append(xmlDocument, { name: "word/document.xml", @@ -61,6 +52,10 @@ export class Compiler { name: "docProps/core.xml", }); + this.archive.append(xmlAppProperties, { + name: "docProps/app.xml", + }); + this.archive.append(xmlNumbering, { name: "word/numbering.xml", }); @@ -85,9 +80,9 @@ export class Compiler { name: "word/_rels/footer1.xml.rels", }); - // this.archive.append(xmlContentTypes, { - // name: "[Content_Types].xml", - // }); + this.archive.append(xmlContentTypes, { + name: "[Content_Types].xml", + }); this.archive.append(xmlFileRelationships, { name: "_rels/.rels", diff --git a/src/file/app-properties/app-properties-attributes.ts b/src/file/app-properties/app-properties-attributes.ts new file mode 100644 index 0000000000..280f4d77b3 --- /dev/null +++ b/src/file/app-properties/app-properties-attributes.ts @@ -0,0 +1,13 @@ +import { XmlAttributeComponent } from "file/xml-components"; + +export interface IAppPropertiesAttributes { + xmlns: string; + vt: string; +} + +export class AppPropertiesAttributes extends XmlAttributeComponent { + protected xmlKeys = { + xmlns: "xmlns", + vt: "xmlns:vt", + }; +} diff --git a/src/file/app-properties/app-properties.ts b/src/file/app-properties/app-properties.ts new file mode 100644 index 0000000000..e984d32f57 --- /dev/null +++ b/src/file/app-properties/app-properties.ts @@ -0,0 +1,13 @@ +import { XmlComponent } from "file/xml-components"; +import { AppPropertiesAttributes } from "./app-properties-attributes"; + +export class AppProperties extends XmlComponent { + constructor() { + super("Properties"); + + this.root.push(new AppPropertiesAttributes({ + xmlns: "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties", + vt: "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes", + })); + } +} diff --git a/src/file/content-types/content-types.ts b/src/file/content-types/content-types.ts index e28397f4d5..4ce020a918 100644 --- a/src/file/content-types/content-types.ts +++ b/src/file/content-types/content-types.ts @@ -1,6 +1,7 @@ import { XmlComponent } from "file/xml-components"; import { ContentTypeAttributes } from "./content-types-attributes"; import { Default } from "./default/default"; +import { Override } from "./override/override"; export class ContentTypes extends XmlComponent { constructor() { @@ -21,27 +22,13 @@ export class ContentTypes extends XmlComponent { this.root.push(new Default("application/xml", "xml")); this.root.push( - new Default( - "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", - undefined, - "/word/document.xml", - ), - ); - this.root.push( - new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", undefined, "/word/header1.xml"), - ); - this.root.push( - new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", undefined, "/word/footer1.xml"), - ); - this.root.push( - new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", undefined, "/word/styles.xml"), - ); - this.root.push(new Default("application/vnd.openxmlformats-package.core-properties+xml", undefined, "/docProps/core.xml")); - this.root.push( - new Default("application/vnd.openxmlformats-officedocument.extended-properties+xml", undefined, "/docProps/app.xml"), - ); - this.root.push( - new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", undefined, "/word/numbering.xml"), + new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "/word/document.xml"), ); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", "/word/header1.xml")); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", "/word/footer1.xml")); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", "/word/styles.xml")); + this.root.push(new Override("application/vnd.openxmlformats-package.core-properties+xml", "/docProps/core.xml")); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.extended-properties+xml", "/docProps/app.xml")); + this.root.push(new Override("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", "/word/numbering.xml")); } } diff --git a/src/file/content-types/default/default-attributes.ts b/src/file/content-types/default/default-attributes.ts index 5ed4c40936..bbc6438c05 100644 --- a/src/file/content-types/default/default-attributes.ts +++ b/src/file/content-types/default/default-attributes.ts @@ -3,13 +3,11 @@ import { XmlAttributeComponent } from "file/xml-components"; export interface IDefaultAttributes { contentType: string; extension?: string; - partName?: string; } export class DefaultAttributes extends XmlAttributeComponent { protected xmlKeys = { contentType: "ContentType", extension: "Extension", - partName: "PartName", }; } diff --git a/src/file/content-types/default/default.ts b/src/file/content-types/default/default.ts index 17fb595784..fc72f15255 100644 --- a/src/file/content-types/default/default.ts +++ b/src/file/content-types/default/default.ts @@ -2,14 +2,13 @@ import { XmlComponent } from "file/xml-components"; import { DefaultAttributes } from "./default-attributes"; export class Default extends XmlComponent { - constructor(contentType: string, extension?: string, partName?: string) { + constructor(contentType: string, extension?: string) { super("Default"); this.root.push( new DefaultAttributes({ contentType: contentType, extension: extension, - partName: partName, }), ); } diff --git a/src/file/content-types/override/override-attributes.ts b/src/file/content-types/override/override-attributes.ts new file mode 100644 index 0000000000..ba84190750 --- /dev/null +++ b/src/file/content-types/override/override-attributes.ts @@ -0,0 +1,13 @@ +import { XmlAttributeComponent } from "file/xml-components"; + +export interface IOverrideAttributes { + contentType: string; + partName?: string; +} + +export class OverrideAttributes extends XmlAttributeComponent { + protected xmlKeys = { + contentType: "ContentType", + partName: "PartName", + }; +} diff --git a/src/file/content-types/override/override.ts b/src/file/content-types/override/override.ts new file mode 100644 index 0000000000..8c0ba6d919 --- /dev/null +++ b/src/file/content-types/override/override.ts @@ -0,0 +1,15 @@ +import { XmlComponent } from "file/xml-components"; +import { OverrideAttributes } from "./override-attributes"; + +export class Override extends XmlComponent { + constructor(contentType: string, partName?: string) { + super("Override"); + + this.root.push( + new OverrideAttributes({ + contentType: contentType, + partName: partName, + }), + ); + } +} diff --git a/src/file/file.ts b/src/file/file.ts index ac81e1c24d..81cc8405fb 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -1,3 +1,4 @@ +import { AppProperties } from "./app-properties/app-properties"; import { ContentTypes } from "./content-types/content-types"; import { CoreProperties, IPropertiesOptions } from "./core-properties"; import { Document } from "./document"; @@ -23,6 +24,7 @@ export class File { private readonly headerWrapper: HeaderWrapper; private readonly footerWrapper: FooterWrapper; private readonly contentTypes: ContentTypes; + private readonly appProperties: AppProperties; constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) { this.document = new Document(sectionPropertiesOptions); @@ -80,6 +82,7 @@ export class File { "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", "docProps/app.xml", ); + this.appProperties = new AppProperties(); } public addParagraph(paragraph: Paragraph): void { @@ -147,4 +150,8 @@ export class File { public get ContentTypes(): ContentTypes { return this.contentTypes; } + + public get AppProperties(): AppProperties { + return this.appProperties; + } } diff --git a/template/[Content_Types].xml b/template/[Content_Types].xml deleted file mode 100644 index 78030c0829..0000000000 --- a/template/[Content_Types].xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/template/docProps/app.xml b/template/docProps/app.xml deleted file mode 100644 index 87874fa9f4..0000000000 --- a/template/docProps/app.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file