office-templates 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +6 -6
- package/CHANGELOG.md +13 -12
- package/LICENSE +21 -21
- package/README.md +662 -662
- package/lib/browser.js +15 -24
- package/lib/browser.js.map +1 -1
- package/lib/bundled.d.ts +1 -0
- package/lib/debug.js +2 -2
- package/lib/errors.js +2 -2
- package/lib/main.js +8 -7
- package/lib/process-template.js +45 -12
- package/lib/sandbox.js +4 -3
- package/lib/types.d.ts +1 -0
- package/lib/xml.d.ts +2 -0
- package/lib/xml.js +2 -2
- package/package.json +102 -102
- package/rollup.config.mjs +61 -61
- package/tsconfig.json +19 -19
package/lib/bundled.d.ts
CHANGED
package/lib/debug.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.logger = void 0;
|
|
4
|
-
exports.setDebugLogSink = setDebugLogSink;
|
|
3
|
+
exports.setDebugLogSink = exports.logger = void 0;
|
|
5
4
|
exports.logger = { debug: function () { } };
|
|
6
5
|
function setDebugLogSink(f) {
|
|
7
6
|
exports.logger.debug = f;
|
|
8
7
|
}
|
|
8
|
+
exports.setDebugLogSink = setDebugLogSink;
|
package/lib/errors.js
CHANGED
|
@@ -15,12 +15,12 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
15
15
|
};
|
|
16
16
|
})();
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.UnterminatedForLoopError = exports.IncompleteConditionalStatementError = exports.TemplateParseError = exports.InternalError = exports.ImageError = exports.CommandExecutionError = exports.InvalidCommandError = exports.CommandSyntaxError = exports.ObjectCommandResultError = exports.NullishCommandResultError = void 0;
|
|
19
|
-
exports.isError = isError;
|
|
18
|
+
exports.UnterminatedForLoopError = exports.IncompleteConditionalStatementError = exports.TemplateParseError = exports.InternalError = exports.ImageError = exports.CommandExecutionError = exports.InvalidCommandError = exports.CommandSyntaxError = exports.ObjectCommandResultError = exports.NullishCommandResultError = exports.isError = void 0;
|
|
20
19
|
function isError(err) {
|
|
21
20
|
return (err instanceof Error ||
|
|
22
21
|
(typeof err === 'object' && !!err && 'name' in err && 'message' in err));
|
|
23
22
|
}
|
|
23
|
+
exports.isError = isError;
|
|
24
24
|
/**
|
|
25
25
|
* Thrown when `rejectNullish` is set to `true` and a command returns `null` or `undefined`.
|
|
26
26
|
*/
|
package/lib/main.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g
|
|
13
|
-
return g
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -48,11 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
48
48
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
49
|
};
|
|
50
50
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.parseTemplate =
|
|
52
|
-
exports.listCommands = listCommands;
|
|
53
|
-
exports.getMetadata = getMetadata;
|
|
54
|
-
exports.readContentTypes = readContentTypes;
|
|
55
|
-
exports.getMainDoc = getMainDoc;
|
|
51
|
+
exports.getMainDoc = exports.readContentTypes = exports.getMetadata = exports.listCommands = exports.parseTemplate = void 0;
|
|
56
52
|
var zip_1 = require("./zip");
|
|
57
53
|
var xml_1 = require("./xml");
|
|
58
54
|
var preprocess_template_1 = __importDefault(require("./preprocess-template"));
|
|
@@ -110,6 +106,7 @@ function parseTemplate(template) {
|
|
|
110
106
|
});
|
|
111
107
|
});
|
|
112
108
|
}
|
|
109
|
+
exports.parseTemplate = parseTemplate;
|
|
113
110
|
function prepSecondaryXMLs(zip, main_doc_path, templatePath, options) {
|
|
114
111
|
return __awaiter(this, void 0, void 0, function () {
|
|
115
112
|
var secondary_xml_files, xmlFileRegex, prepped_secondaries, _i, secondary_xml_files_1, f, raw, js0, js;
|
|
@@ -430,6 +427,7 @@ function listCommands(template, delimiter) {
|
|
|
430
427
|
});
|
|
431
428
|
});
|
|
432
429
|
}
|
|
430
|
+
exports.listCommands = listCommands;
|
|
433
431
|
/**
|
|
434
432
|
* Extract metadata from a document, such as the number of pages or words.
|
|
435
433
|
* @param template the docx or pptx template as a Buffer-like object
|
|
@@ -500,6 +498,7 @@ function getMetadata(template) {
|
|
|
500
498
|
});
|
|
501
499
|
});
|
|
502
500
|
}
|
|
501
|
+
exports.getMetadata = getMetadata;
|
|
503
502
|
function parsePath(zip, xml_path) {
|
|
504
503
|
return __awaiter(this, void 0, void 0, function () {
|
|
505
504
|
var xmlFile, node;
|
|
@@ -530,9 +529,11 @@ function readContentTypes(zip) {
|
|
|
530
529
|
});
|
|
531
530
|
});
|
|
532
531
|
}
|
|
532
|
+
exports.readContentTypes = readContentTypes;
|
|
533
533
|
function getMainDoc(contentTypes) {
|
|
534
534
|
return getMainPart(contentTypes).replace(/^(word|ppt)\//, '');
|
|
535
535
|
}
|
|
536
|
+
exports.getMainDoc = getMainDoc;
|
|
536
537
|
function getMainPart(contentTypes) {
|
|
537
538
|
var MAIN_DOC_MIMES = [
|
|
538
539
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml',
|
package/lib/process-template.js
CHANGED
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g
|
|
24
|
-
return g
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -47,12 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.newContext =
|
|
51
|
-
exports.produceJsReport = produceJsReport;
|
|
52
|
-
exports.findHighestImgId = findHighestImgId;
|
|
53
|
-
exports.walkTemplate = walkTemplate;
|
|
54
|
-
exports.getCommand = getCommand;
|
|
55
|
-
exports.splitCommand = splitCommand;
|
|
50
|
+
exports.splitCommand = exports.getCommand = exports.walkTemplate = exports.findHighestImgId = exports.produceJsReport = exports.newContext = void 0;
|
|
56
51
|
var report_utils_1 = require("./report-utils");
|
|
57
52
|
var sandbox_1 = require("./sandbox");
|
|
58
53
|
var types_1 = require("./types");
|
|
@@ -86,6 +81,7 @@ function newContext(options, imageAndShapeIdIncrement, relationshipIds) {
|
|
|
86
81
|
options: options,
|
|
87
82
|
};
|
|
88
83
|
}
|
|
84
|
+
exports.newContext = newContext;
|
|
89
85
|
function produceJsReport(data, template, ctx) {
|
|
90
86
|
return __awaiter(this, void 0, void 0, function () {
|
|
91
87
|
return __generator(this, function (_a) {
|
|
@@ -93,6 +89,7 @@ function produceJsReport(data, template, ctx) {
|
|
|
93
89
|
});
|
|
94
90
|
});
|
|
95
91
|
}
|
|
92
|
+
exports.produceJsReport = produceJsReport;
|
|
96
93
|
function findHighestImgId(mainDoc) {
|
|
97
94
|
var doc_ids = [];
|
|
98
95
|
var search = function (n) {
|
|
@@ -120,6 +117,7 @@ function findHighestImgId(mainDoc) {
|
|
|
120
117
|
return Math.max.apply(Math, doc_ids);
|
|
121
118
|
return 0;
|
|
122
119
|
}
|
|
120
|
+
exports.findHighestImgId = findHighestImgId;
|
|
123
121
|
// Ignore XML indentation and property nodes when checking rendered content.
|
|
124
122
|
var hasTemplateText = function (node) {
|
|
125
123
|
return node._fTextNode
|
|
@@ -129,6 +127,16 @@ var hasTemplateText = function (node) {
|
|
|
129
127
|
node._text.length > 0
|
|
130
128
|
: node._children.some(hasTemplateText);
|
|
131
129
|
};
|
|
130
|
+
var getContainingCell = function (node) {
|
|
131
|
+
var current = node;
|
|
132
|
+
while (current) {
|
|
133
|
+
if (!current._fTextNode && (0, report_utils_1.normalizeTag)(current._tag) === 'w:tc') {
|
|
134
|
+
return current;
|
|
135
|
+
}
|
|
136
|
+
current = current._parent;
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
};
|
|
132
140
|
var debugPrintNode = function (node) {
|
|
133
141
|
return JSON.stringify(node._fTextNode
|
|
134
142
|
? {
|
|
@@ -145,7 +153,7 @@ var debugPrintNode = function (node) {
|
|
|
145
153
|
};
|
|
146
154
|
function walkTemplate(data, template, ctx, processor) {
|
|
147
155
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
|
-
var out, nodeIn, nodeOut, move, deltaJump, errors, loopCount, maximumWalkingDepth, _loop_1, state_1, err, innermost_loop, err;
|
|
156
|
+
var out, nodeIn, nodeOut, move, deltaJump, errors, preservedCells, loopCount, maximumWalkingDepth, _loop_1, state_1, err, innermost_loop, err;
|
|
149
157
|
var _a;
|
|
150
158
|
return __generator(this, function (_b) {
|
|
151
159
|
switch (_b.label) {
|
|
@@ -155,10 +163,11 @@ function walkTemplate(data, template, ctx, processor) {
|
|
|
155
163
|
nodeOut = out;
|
|
156
164
|
deltaJump = 0;
|
|
157
165
|
errors = [];
|
|
166
|
+
preservedCells = new WeakSet();
|
|
158
167
|
loopCount = 0;
|
|
159
168
|
maximumWalkingDepth = ((_a = ctx.options) === null || _a === void 0 ? void 0 : _a.maximumWalkingDepth) || 1000000;
|
|
160
169
|
_loop_1 = function () {
|
|
161
|
-
var curLoop, nextSibling, parent_1, tag, fRemoveNode, buffers, hasDrawingElements_1, preceding, nodeOutParent, imgNode, captionNodes, parent_2, linkNode, parent_3, htmlNode, parent_4, paragraph, texts_1, first_1, tag, newNode, newNodeTag, parent_5, result;
|
|
170
|
+
var curLoop, nextSibling, parent_1, tag, fRemoveNode, buffers, hasDrawingElements_1, preceding, nodeOutParent, imgNode, captionNodes, parent_2, linkNode, parent_3, htmlNode, parent_4, paragraph, texts_1, first_1, tag, newNode, newNodeTag, parent_5, result, cell;
|
|
162
171
|
var _c;
|
|
163
172
|
return __generator(this, function (_d) {
|
|
164
173
|
switch (_d.label) {
|
|
@@ -258,6 +267,15 @@ function walkTemplate(data, template, ctx, processor) {
|
|
|
258
267
|
fRemoveNode = !(nodeOut._children.filter(function (child) { return !child._fTextNode && (0, report_utils_1.normalizeTag)(child._tag) === 'w:tbl'; }).length > 0);
|
|
259
268
|
}
|
|
260
269
|
}
|
|
270
|
+
// An IF wholly inside a cell only controls its contents. Preserve that
|
|
271
|
+
// cell and its row, but let enclosing FOR/IF exploration remove them.
|
|
272
|
+
if (fRemoveNode &&
|
|
273
|
+
!(0, report_utils_1.isLoopExploring)(ctx) &&
|
|
274
|
+
(tag === 'w:tc' || tag === 'w:tr') &&
|
|
275
|
+
(preservedCells.has(nodeOut) ||
|
|
276
|
+
nodeOut._children.some(function (child) { return preservedCells.has(child); }))) {
|
|
277
|
+
fRemoveNode = false;
|
|
278
|
+
}
|
|
261
279
|
// Execute removal, if needed. The node will no longer be part of the output, but
|
|
262
280
|
// the parent will be accessible from the child (so that we can still move up the tree)
|
|
263
281
|
if (fRemoveNode && nodeOut._parent != null) {
|
|
@@ -347,7 +365,7 @@ function walkTemplate(data, template, ctx, processor) {
|
|
|
347
365
|
// `w:tc` nodes shouldn't be left with no `w:p` or 'w:altChunk' children; if that's the
|
|
348
366
|
// case, add an empty `w:p` inside
|
|
349
367
|
if (!nodeOut._fTextNode &&
|
|
350
|
-
|
|
368
|
+
nodeOut._tag === 'w:tc' &&
|
|
351
369
|
!nodeOut._children.filter(function (o) {
|
|
352
370
|
return !o._fTextNode &&
|
|
353
371
|
((0, report_utils_1.normalizeTag)(o._tag) === 'w:p' ||
|
|
@@ -357,7 +375,7 @@ function walkTemplate(data, template, ctx, processor) {
|
|
|
357
375
|
_parent: nodeOut,
|
|
358
376
|
_children: [],
|
|
359
377
|
_fTextNode: false,
|
|
360
|
-
_tag:
|
|
378
|
+
_tag: 'w:p',
|
|
361
379
|
_attrs: {},
|
|
362
380
|
});
|
|
363
381
|
}
|
|
@@ -419,6 +437,12 @@ function walkTemplate(data, template, ctx, processor) {
|
|
|
419
437
|
return [4 /*yield*/, processText(data, nodeIn, ctx, processor)];
|
|
420
438
|
case 1:
|
|
421
439
|
result = _d.sent();
|
|
440
|
+
if (ctx.pendingCellPreservation) {
|
|
441
|
+
cell = getContainingCell(newNode);
|
|
442
|
+
if (cell)
|
|
443
|
+
preservedCells.add(cell);
|
|
444
|
+
delete ctx.pendingCellPreservation;
|
|
445
|
+
}
|
|
422
446
|
if (typeof result === 'string') {
|
|
423
447
|
// TODO: improve typesafety of conversion Node to TextNode.
|
|
424
448
|
newNode._text = result;
|
|
@@ -494,6 +518,7 @@ function walkTemplate(data, template, ctx, processor) {
|
|
|
494
518
|
});
|
|
495
519
|
});
|
|
496
520
|
}
|
|
521
|
+
exports.walkTemplate = walkTemplate;
|
|
497
522
|
var processText = function (data, node, ctx, onCommand) { return __awaiter(void 0, void 0, void 0, function () {
|
|
498
523
|
var _a, cmdDelimiter, failFast, text, segments, outText, errors, idx, segment, cmdResultText;
|
|
499
524
|
return __generator(this, function (_b) {
|
|
@@ -730,6 +755,7 @@ function getCommand(command, shorthands, fixSmartQuotes) {
|
|
|
730
755
|
}
|
|
731
756
|
return cmd.trim();
|
|
732
757
|
}
|
|
758
|
+
exports.getCommand = getCommand;
|
|
733
759
|
function splitCommand(cmd) {
|
|
734
760
|
// Extract command name
|
|
735
761
|
var cmdNameMatch = /^(\S+)\s*/.exec(cmd);
|
|
@@ -741,6 +767,7 @@ function splitCommand(cmd) {
|
|
|
741
767
|
}
|
|
742
768
|
return { cmdName: cmdName, cmdRest: cmdRest };
|
|
743
769
|
}
|
|
770
|
+
exports.splitCommand = splitCommand;
|
|
744
771
|
// ==========================================
|
|
745
772
|
// Individual commands
|
|
746
773
|
// ==========================================
|
|
@@ -843,6 +870,12 @@ var processEndForIf = function (node, ctx, cmd, cmdName, cmdRest) {
|
|
|
843
870
|
else {
|
|
844
871
|
// loop finished
|
|
845
872
|
ctx.loops.pop();
|
|
873
|
+
if (isIf && curLoop.loopOver.length === 0 && !(0, report_utils_1.isLoopExploring)(ctx)) {
|
|
874
|
+
var cell = getContainingCell(node);
|
|
875
|
+
if (cell && cell === getContainingCell(curLoop.refNode)) {
|
|
876
|
+
ctx.pendingCellPreservation = true;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
846
879
|
}
|
|
847
880
|
};
|
|
848
881
|
var imageToContext = function (ctx, img) {
|
package/lib/sandbox.js
CHANGED
|
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g
|
|
24
|
-
return g
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -47,7 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
-
exports.runUserJsAndGetRaw =
|
|
50
|
+
exports.runUserJsAndGetRaw = void 0;
|
|
51
51
|
var errors_1 = require("./errors");
|
|
52
52
|
var debug_1 = require("./debug");
|
|
53
53
|
// Run a snippet directly or through the caller's runJs implementation.
|
|
@@ -120,3 +120,4 @@ function runUserJsAndGetRaw(data, code, ctx) {
|
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
+
exports.runUserJsAndGetRaw = runUserJsAndGetRaw;
|
package/lib/types.d.ts
CHANGED
package/lib/xml.d.ts
CHANGED
package/lib/xml.js
CHANGED
|
@@ -3,8 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.parseXml = void 0;
|
|
7
|
-
exports.buildXml = buildXml;
|
|
6
|
+
exports.buildXml = exports.parseXml = void 0;
|
|
8
7
|
var sax_1 = __importDefault(require("sax"));
|
|
9
8
|
var debug_1 = require("./debug");
|
|
10
9
|
var parseXml = function (templateXml) {
|
|
@@ -90,6 +89,7 @@ function buildXml(node, options, indent, firstRun) {
|
|
|
90
89
|
}
|
|
91
90
|
return Buffer.concat(xmlBuffers);
|
|
92
91
|
}
|
|
92
|
+
exports.buildXml = buildXml;
|
|
93
93
|
var sanitizeText = function (str, options) {
|
|
94
94
|
var out = '';
|
|
95
95
|
var segments = str.split(options.literalXmlDelimiter);
|
package/package.json
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "office-templates",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Template-based docx and pptx report creation",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"types": "lib/index.d.ts",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"keywords": [
|
|
9
|
-
"docx",
|
|
10
|
-
"pptx",
|
|
11
|
-
"powerpoint",
|
|
12
|
-
"office",
|
|
13
|
-
"word",
|
|
14
|
-
"ms-word",
|
|
15
|
-
"report",
|
|
16
|
-
"template"
|
|
17
|
-
],
|
|
18
|
-
"homepage": "https://github.com/tentone/office-templates#readme",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/tentone/office-templates/issues"
|
|
21
|
-
},
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/tentone/office-templates.git"
|
|
25
|
-
},
|
|
26
|
-
"scripts": {
|
|
27
|
-
"prepare": "npm run compile",
|
|
28
|
-
"compile": "rimraf ./lib && tsc && npm run rollup",
|
|
29
|
-
"rollup": "rollup -c",
|
|
30
|
-
"pub": "npm run compile && npm publish --access public .",
|
|
31
|
-
"jest": "jest --watch --coverage",
|
|
32
|
-
"test": "npm run lint && npm run testCovFull",
|
|
33
|
-
"testCovFull": "npm run testCovPrepare && npm run testDev && npm run testCovReport",
|
|
34
|
-
"testCovPrepare": "npm run testCovClean && mkdir .nyc_tmp",
|
|
35
|
-
"testDev": "npm run testCovClean && NODE_ENV=development jest --coverage && mv .nyc_output/coverage-final.json .nyc_tmp/coverage-dev.json && rm -rf .nyc_output",
|
|
36
|
-
"testCovReport": "npm run testCovClean && cp -r .nyc_tmp .nyc_output && nyc report --reporter=html --reporter=lcov --reporter=text",
|
|
37
|
-
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
38
|
-
"lint-fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
39
|
-
"testCovClean": "rm -rf ./coverage .nyc_output .nyc_tmp"
|
|
40
|
-
},
|
|
41
|
-
"engines": {
|
|
42
|
-
"node": ">=6"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"jszip": "~3.10.2",
|
|
46
|
-
"sax": "~1.3.0"
|
|
47
|
-
},
|
|
48
|
-
"devDependencies": {
|
|
49
|
-
"@rollup/plugin-commonjs": "~23.0.0",
|
|
50
|
-
"@rollup/plugin-node-resolve": "~15.0.0",
|
|
51
|
-
"@rollup/plugin-replace": "~5.0.0",
|
|
52
|
-
"@types/jest": "~29.5.0",
|
|
53
|
-
"@types/node": "~26.6.6",
|
|
54
|
-
"@types/qrcode": "~1.5.0",
|
|
55
|
-
"@types/sax": "~1.2.7",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "~6.5.0",
|
|
57
|
-
"@typescript-eslint/parser": "~6.5.0",
|
|
58
|
-
"buffer": "6.0.3",
|
|
59
|
-
"coveralls": "~3.0.13",
|
|
60
|
-
"esbuild": "~0.25.0",
|
|
61
|
-
"eslint": "~8.37.0",
|
|
62
|
-
"eslint-config-prettier": "~8.8.0",
|
|
63
|
-
"eslint-plugin-import": "~2.27.5",
|
|
64
|
-
"eslint-plugin-jest": "~27.2.1",
|
|
65
|
-
"eslint-plugin-prettier": "~4.2.1",
|
|
66
|
-
"events": "3.3.0",
|
|
67
|
-
"jest": "~29.5.0",
|
|
68
|
-
"mockdate": "~3.0.2",
|
|
69
|
-
"nyc": "~15.0.1",
|
|
70
|
-
"prettier": "~2.8.7",
|
|
71
|
-
"qrcode": "~1.5.1",
|
|
72
|
-
"rimraf": "~3.0.2",
|
|
73
|
-
"rollup": "~3.29.5",
|
|
74
|
-
"rollup-plugin-dts": "~5.3.0",
|
|
75
|
-
"rollup-plugin-esbuild": "4.10.2",
|
|
76
|
-
"stream-browserify": "~3.0.0",
|
|
77
|
-
"ts-jest": "~29.1.0",
|
|
78
|
-
"typescript": "~5.6.2",
|
|
79
|
-
"util": "~0.12.5"
|
|
80
|
-
},
|
|
81
|
-
"jest": {
|
|
82
|
-
"transform": {
|
|
83
|
-
".+\\.tsx?$": "ts-jest"
|
|
84
|
-
},
|
|
85
|
-
"testTimeout": 10000,
|
|
86
|
-
"testRegex": "src/.*__tests__/.*\\.(test|spec)\\.(ts|tsx)$",
|
|
87
|
-
"coverageDirectory": ".nyc_output",
|
|
88
|
-
"coverageReporters": [
|
|
89
|
-
"json",
|
|
90
|
-
"text",
|
|
91
|
-
"html"
|
|
92
|
-
],
|
|
93
|
-
"collectCoverageFrom": [
|
|
94
|
-
"src/**/*.ts",
|
|
95
|
-
"!src/debug.ts",
|
|
96
|
-
"!test/**",
|
|
97
|
-
"!**/node_modules/**",
|
|
98
|
-
"!**/__tests__/**",
|
|
99
|
-
"!**/__mocks__/**"
|
|
100
|
-
]
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "office-templates",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Template-based docx and pptx report creation",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"docx",
|
|
10
|
+
"pptx",
|
|
11
|
+
"powerpoint",
|
|
12
|
+
"office",
|
|
13
|
+
"word",
|
|
14
|
+
"ms-word",
|
|
15
|
+
"report",
|
|
16
|
+
"template"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/tentone/office-templates#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/tentone/office-templates/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/tentone/office-templates.git"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"prepare": "npm run compile",
|
|
28
|
+
"compile": "rimraf ./lib && tsc && npm run rollup",
|
|
29
|
+
"rollup": "rollup -c",
|
|
30
|
+
"pub": "npm run compile && npm publish --access public .",
|
|
31
|
+
"jest": "jest --watch --coverage",
|
|
32
|
+
"test": "npm run lint && npm run testCovFull",
|
|
33
|
+
"testCovFull": "npm run testCovPrepare && npm run testDev && npm run testCovReport",
|
|
34
|
+
"testCovPrepare": "npm run testCovClean && mkdir .nyc_tmp",
|
|
35
|
+
"testDev": "npm run testCovClean && NODE_ENV=development jest --coverage && mv .nyc_output/coverage-final.json .nyc_tmp/coverage-dev.json && rm -rf .nyc_output",
|
|
36
|
+
"testCovReport": "npm run testCovClean && cp -r .nyc_tmp .nyc_output && nyc report --reporter=html --reporter=lcov --reporter=text",
|
|
37
|
+
"lint": "eslint \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
38
|
+
"lint-fix": "eslint --fix \"src/**/*.{js,jsx,ts,tsx}\"",
|
|
39
|
+
"testCovClean": "rm -rf ./coverage .nyc_output .nyc_tmp"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=6"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"jszip": "~3.10.2",
|
|
46
|
+
"sax": "~1.3.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@rollup/plugin-commonjs": "~23.0.0",
|
|
50
|
+
"@rollup/plugin-node-resolve": "~15.0.0",
|
|
51
|
+
"@rollup/plugin-replace": "~5.0.0",
|
|
52
|
+
"@types/jest": "~29.5.0",
|
|
53
|
+
"@types/node": "~26.6.6",
|
|
54
|
+
"@types/qrcode": "~1.5.0",
|
|
55
|
+
"@types/sax": "~1.2.7",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "~6.5.0",
|
|
57
|
+
"@typescript-eslint/parser": "~6.5.0",
|
|
58
|
+
"buffer": "6.0.3",
|
|
59
|
+
"coveralls": "~3.0.13",
|
|
60
|
+
"esbuild": "~0.25.0",
|
|
61
|
+
"eslint": "~8.37.0",
|
|
62
|
+
"eslint-config-prettier": "~8.8.0",
|
|
63
|
+
"eslint-plugin-import": "~2.27.5",
|
|
64
|
+
"eslint-plugin-jest": "~27.2.1",
|
|
65
|
+
"eslint-plugin-prettier": "~4.2.1",
|
|
66
|
+
"events": "3.3.0",
|
|
67
|
+
"jest": "~29.5.0",
|
|
68
|
+
"mockdate": "~3.0.2",
|
|
69
|
+
"nyc": "~15.0.1",
|
|
70
|
+
"prettier": "~2.8.7",
|
|
71
|
+
"qrcode": "~1.5.1",
|
|
72
|
+
"rimraf": "~3.0.2",
|
|
73
|
+
"rollup": "~3.29.5",
|
|
74
|
+
"rollup-plugin-dts": "~5.3.0",
|
|
75
|
+
"rollup-plugin-esbuild": "4.10.2",
|
|
76
|
+
"stream-browserify": "~3.0.0",
|
|
77
|
+
"ts-jest": "~29.1.0",
|
|
78
|
+
"typescript": "~5.6.2",
|
|
79
|
+
"util": "~0.12.5"
|
|
80
|
+
},
|
|
81
|
+
"jest": {
|
|
82
|
+
"transform": {
|
|
83
|
+
".+\\.tsx?$": "ts-jest"
|
|
84
|
+
},
|
|
85
|
+
"testTimeout": 10000,
|
|
86
|
+
"testRegex": "src/.*__tests__/.*\\.(test|spec)\\.(ts|tsx)$",
|
|
87
|
+
"coverageDirectory": ".nyc_output",
|
|
88
|
+
"coverageReporters": [
|
|
89
|
+
"json",
|
|
90
|
+
"text",
|
|
91
|
+
"html"
|
|
92
|
+
],
|
|
93
|
+
"collectCoverageFrom": [
|
|
94
|
+
"src/**/*.ts",
|
|
95
|
+
"!src/debug.ts",
|
|
96
|
+
"!test/**",
|
|
97
|
+
"!**/node_modules/**",
|
|
98
|
+
"!**/__tests__/**",
|
|
99
|
+
"!**/__mocks__/**"
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
}
|
package/rollup.config.mjs
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import replace from '@rollup/plugin-replace'
|
|
2
|
-
import esbuild from 'rollup-plugin-esbuild'
|
|
3
|
-
import node from '@rollup/plugin-node-resolve'
|
|
4
|
-
import commonjs from '@rollup/plugin-commonjs'
|
|
5
|
-
import dts from 'rollup-plugin-dts'
|
|
6
|
-
import { defineConfig } from 'rollup'
|
|
7
|
-
|
|
8
|
-
export default defineConfig([{
|
|
9
|
-
input: './src/browser.ts',
|
|
10
|
-
output: { file: './lib/browser.js', format: 'es', exports: 'named', sourcemap: true },
|
|
11
|
-
plugins: [
|
|
12
|
-
node({
|
|
13
|
-
preferBuiltins: false
|
|
14
|
-
}),
|
|
15
|
-
commonjs(),
|
|
16
|
-
// Set some node specific globals
|
|
17
|
-
replace({
|
|
18
|
-
preventAssignment: true,
|
|
19
|
-
values: {
|
|
20
|
-
'process.env.NODE_DEBUG': false,
|
|
21
|
-
'process.pid': 42,
|
|
22
|
-
'process.nextTick': 'setTimeout',
|
|
23
|
-
'process.stdout': 'null',
|
|
24
|
-
'process.stderr': 'null',
|
|
25
|
-
'process.env.READABLE_STREAM': 'false',
|
|
26
|
-
'process.browser': 'true',
|
|
27
|
-
'process.env.NODE_ENV': '"production"',
|
|
28
|
-
// Replace the guard without rewriting module names such as process-template.
|
|
29
|
-
'typeof process': '"undefined"'
|
|
30
|
-
}
|
|
31
|
-
}),
|
|
32
|
-
esbuild({
|
|
33
|
-
target: 'es2017',
|
|
34
|
-
minify: true
|
|
35
|
-
}),
|
|
36
|
-
// Map modules to polyfill
|
|
37
|
-
{
|
|
38
|
-
name: 'module-map',
|
|
39
|
-
resolveId(id, importer, options) {
|
|
40
|
-
if (id === 'stream') {
|
|
41
|
-
return this.resolve('stream-browserify', importer, options)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
}, {
|
|
47
|
-
input: './lib/index.d.ts',
|
|
48
|
-
output: { file: './lib/bundled.d.ts', format: 'es' },
|
|
49
|
-
plugins: [
|
|
50
|
-
dts({ respectExternal: true }),
|
|
51
|
-
{
|
|
52
|
-
renderChunk(code) {
|
|
53
|
-
return 'type Buffer = ArrayBufferLike;\n'+ code.split('\n').slice(1).join('\n')
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
],
|
|
57
|
-
external: [
|
|
58
|
-
// To prevent warning. If `import ... from 'stream'` exists in bundled.d.ts this build has to be changed to remove it.
|
|
59
|
-
'stream'
|
|
60
|
-
]
|
|
61
|
-
}])
|
|
1
|
+
import replace from '@rollup/plugin-replace'
|
|
2
|
+
import esbuild from 'rollup-plugin-esbuild'
|
|
3
|
+
import node from '@rollup/plugin-node-resolve'
|
|
4
|
+
import commonjs from '@rollup/plugin-commonjs'
|
|
5
|
+
import dts from 'rollup-plugin-dts'
|
|
6
|
+
import { defineConfig } from 'rollup'
|
|
7
|
+
|
|
8
|
+
export default defineConfig([{
|
|
9
|
+
input: './src/browser.ts',
|
|
10
|
+
output: { file: './lib/browser.js', format: 'es', exports: 'named', sourcemap: true },
|
|
11
|
+
plugins: [
|
|
12
|
+
node({
|
|
13
|
+
preferBuiltins: false
|
|
14
|
+
}),
|
|
15
|
+
commonjs(),
|
|
16
|
+
// Set some node specific globals
|
|
17
|
+
replace({
|
|
18
|
+
preventAssignment: true,
|
|
19
|
+
values: {
|
|
20
|
+
'process.env.NODE_DEBUG': false,
|
|
21
|
+
'process.pid': 42,
|
|
22
|
+
'process.nextTick': 'setTimeout',
|
|
23
|
+
'process.stdout': 'null',
|
|
24
|
+
'process.stderr': 'null',
|
|
25
|
+
'process.env.READABLE_STREAM': 'false',
|
|
26
|
+
'process.browser': 'true',
|
|
27
|
+
'process.env.NODE_ENV': '"production"',
|
|
28
|
+
// Replace the guard without rewriting module names such as process-template.
|
|
29
|
+
'typeof process': '"undefined"'
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
esbuild({
|
|
33
|
+
target: 'es2017',
|
|
34
|
+
minify: true
|
|
35
|
+
}),
|
|
36
|
+
// Map modules to polyfill
|
|
37
|
+
{
|
|
38
|
+
name: 'module-map',
|
|
39
|
+
resolveId(id, importer, options) {
|
|
40
|
+
if (id === 'stream') {
|
|
41
|
+
return this.resolve('stream-browserify', importer, options)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}, {
|
|
47
|
+
input: './lib/index.d.ts',
|
|
48
|
+
output: { file: './lib/bundled.d.ts', format: 'es' },
|
|
49
|
+
plugins: [
|
|
50
|
+
dts({ respectExternal: true }),
|
|
51
|
+
{
|
|
52
|
+
renderChunk(code) {
|
|
53
|
+
return 'type Buffer = ArrayBufferLike;\n'+ code.split('\n').slice(1).join('\n')
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
external: [
|
|
58
|
+
// To prevent warning. If `import ... from 'stream'` exists in bundled.d.ts this build has to be changed to remove it.
|
|
59
|
+
'stream'
|
|
60
|
+
]
|
|
61
|
+
}])
|