From cf0c2c7691a8a2271b6dc5ae5541a31a4be2c3e9 Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 7 Aug 2018 02:23:58 +0100 Subject: [PATCH] Add Express packer deprecation warning --- docs/usage/packers.md | 19 +++++++++++++++---- src/export/packer/express.ts | 3 +++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/usage/packers.md b/docs/usage/packers.md index 1994781639..db837702de 100644 --- a/docs/usage/packers.md +++ b/docs/usage/packers.md @@ -32,21 +32,32 @@ const docx = require("docx"); const doc = new docx.Document(); const exporter = new docx.StreamPacker(doc); -const buffer = exporter.pack(); +const stream = exporter.pack(); ``` ## Express Packer +The old express packer is now deprecated and may disappear soon, so you should upgrade. + +The reason for this is because it means this project needs to know about and use `express`, which for a Word document generator, does not sound right. Seperation of concerns. + +It will still be usable (for now), but it is ill advised. + I used the express exporter in my [website](http://www.dolan.bio). -Pass in the necessary parameters: +The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library: ```js const docx = require("docx"); const doc = new docx.Document(); -const exporter = new docx.ExpressPacker(doc, res); -exporter.pack("My Document"); +const exporter = new docx.StreamPacker(doc); + +const stream = exporter.pack(); + +// Express' response object +res.attachment('yourfile.xlsx'); +stream.pipe(res); ``` where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser. diff --git a/src/export/packer/express.ts b/src/export/packer/express.ts index 4f99298424..3a4fa4b3ef 100644 --- a/src/export/packer/express.ts +++ b/src/export/packer/express.ts @@ -4,6 +4,9 @@ import { File } from "file"; import { Compiler } from "./compiler"; import { IPacker } from "./packer"; +/** + * @deprecated ExpressPacker is now deprecated. Please use the StreamPacker instead and pipe that to `express`' `res` object + */ export class ExpressPacker implements IPacker { private readonly packer: Compiler;