Remove all references to template
This commit is contained in:
@ -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<void> {
|
||||
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",
|
||||
|
13
src/file/app-properties/app-properties-attributes.ts
Normal file
13
src/file/app-properties/app-properties-attributes.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IAppPropertiesAttributes {
|
||||
xmlns: string;
|
||||
vt: string;
|
||||
}
|
||||
|
||||
export class AppPropertiesAttributes extends XmlAttributeComponent<IAppPropertiesAttributes> {
|
||||
protected xmlKeys = {
|
||||
xmlns: "xmlns",
|
||||
vt: "xmlns:vt",
|
||||
};
|
||||
}
|
13
src/file/app-properties/app-properties.ts
Normal file
13
src/file/app-properties/app-properties.ts
Normal file
@ -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",
|
||||
}));
|
||||
}
|
||||
}
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -3,13 +3,11 @@ import { XmlAttributeComponent } from "file/xml-components";
|
||||
export interface IDefaultAttributes {
|
||||
contentType: string;
|
||||
extension?: string;
|
||||
partName?: string;
|
||||
}
|
||||
|
||||
export class DefaultAttributes extends XmlAttributeComponent<IDefaultAttributes> {
|
||||
protected xmlKeys = {
|
||||
contentType: "ContentType",
|
||||
extension: "Extension",
|
||||
partName: "PartName",
|
||||
};
|
||||
}
|
||||
|
@ -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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
13
src/file/content-types/override/override-attributes.ts
Normal file
13
src/file/content-types/override/override-attributes.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IOverrideAttributes {
|
||||
contentType: string;
|
||||
partName?: string;
|
||||
}
|
||||
|
||||
export class OverrideAttributes extends XmlAttributeComponent<IOverrideAttributes> {
|
||||
protected xmlKeys = {
|
||||
contentType: "ContentType",
|
||||
partName: "PartName",
|
||||
};
|
||||
}
|
15
src/file/content-types/override/override.ts
Normal file
15
src/file/content-types/override/override.ts
Normal file
@ -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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
|
||||
<Default Extension="png" ContentType="image/png"/>
|
||||
<Default Extension="jpeg" ContentType="image/jpeg"/>
|
||||
<Default Extension="jpg" ContentType="image/jpeg"/>
|
||||
<Default Extension="bmp" ContentType="image/bmp"/>
|
||||
<Default Extension="gif" ContentType="image/gif"/>
|
||||
<Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
|
||||
<Default Extension="xml" ContentType="application/xml" />
|
||||
<Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml" />
|
||||
<Override PartName="/word/header1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml"/>
|
||||
<Override PartName="/word/footer1.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml"/>
|
||||
<Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml" />
|
||||
<Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml" />
|
||||
<Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml" />
|
||||
<Override PartName="/word/numbering.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml" />
|
||||
</Types>
|
@ -1,3 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
|
||||
</Properties>
|
Reference in New Issue
Block a user