@json-to-office/jto 0.6.0 → 0.7.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/dist/cli.js +29 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.js +28 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -8,6 +8,18 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
// src/format-adapter.ts
|
|
9
9
|
import * as path from "path";
|
|
10
10
|
import * as fs from "fs";
|
|
11
|
+
function buildServicesFromEnv() {
|
|
12
|
+
const serverUrl = process.env.HIGHCHARTS_SERVER_URL;
|
|
13
|
+
const apiKey = process.env.HIGHCHARTS_API_KEY;
|
|
14
|
+
const apiKeyHeader = process.env.HIGHCHARTS_API_KEY_HEADER ?? "x-api-key";
|
|
15
|
+
if (!serverUrl && !apiKey) return void 0;
|
|
16
|
+
return {
|
|
17
|
+
highcharts: {
|
|
18
|
+
serverUrl,
|
|
19
|
+
...apiKey && { headers: { [apiKeyHeader]: apiKey } }
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
11
23
|
var DocxFormatAdapter = class {
|
|
12
24
|
name = "docx";
|
|
13
25
|
extension = ".docx";
|
|
@@ -17,21 +29,25 @@ var DocxFormatAdapter = class {
|
|
|
17
29
|
const core = await import("@json-to-office/core-docx");
|
|
18
30
|
const docDefinition = typeof json === "string" ? JSON.parse(json) : json;
|
|
19
31
|
const customThemes = await this.loadCustomThemes(options);
|
|
32
|
+
const services = buildServicesFromEnv();
|
|
20
33
|
return await core.generateBufferFromJson(docDefinition, {
|
|
21
|
-
customThemes
|
|
34
|
+
customThemes,
|
|
35
|
+
services
|
|
22
36
|
});
|
|
23
37
|
}
|
|
24
38
|
async createGenerator(plugins, options) {
|
|
25
39
|
const core = await import("@json-to-office/core-docx");
|
|
26
40
|
const hasPlugins = plugins.length > 0;
|
|
27
41
|
const pluginNames = plugins.map((p) => p.name);
|
|
42
|
+
const services = buildServicesFromEnv();
|
|
28
43
|
if (!hasPlugins) {
|
|
29
44
|
return {
|
|
30
45
|
generateBuffer: async (document) => {
|
|
31
46
|
const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
|
|
32
47
|
const customThemes2 = await this.loadCustomThemes(options);
|
|
33
48
|
return await core.generateBufferFromJson(docDefinition, {
|
|
34
|
-
customThemes: customThemes2
|
|
49
|
+
customThemes: customThemes2,
|
|
50
|
+
services
|
|
35
51
|
});
|
|
36
52
|
},
|
|
37
53
|
hasPlugins: false,
|
|
@@ -43,7 +59,8 @@ var DocxFormatAdapter = class {
|
|
|
43
59
|
let generator = core.createDocumentGenerator({
|
|
44
60
|
theme,
|
|
45
61
|
customThemes,
|
|
46
|
-
debug: process.env.DEBUG === "true"
|
|
62
|
+
debug: process.env.DEBUG === "true",
|
|
63
|
+
services
|
|
47
64
|
});
|
|
48
65
|
for (const plugin of plugins) {
|
|
49
66
|
generator = generator.addComponent(plugin);
|
|
@@ -228,21 +245,25 @@ var PptxFormatAdapter = class {
|
|
|
228
245
|
const core = await import("@json-to-office/core-pptx");
|
|
229
246
|
const docDefinition = typeof json === "string" ? JSON.parse(json) : json;
|
|
230
247
|
const customThemes = await this.loadCustomThemes(options);
|
|
248
|
+
const services = buildServicesFromEnv();
|
|
231
249
|
return await core.generateBufferFromJson(docDefinition, {
|
|
232
|
-
customThemes
|
|
250
|
+
customThemes,
|
|
251
|
+
services
|
|
233
252
|
});
|
|
234
253
|
}
|
|
235
254
|
async createGenerator(plugins, options) {
|
|
236
255
|
const core = await import("@json-to-office/core-pptx");
|
|
237
256
|
const hasPlugins = plugins.length > 0;
|
|
238
257
|
const pluginNames = plugins.map((p) => p.name);
|
|
258
|
+
const services = buildServicesFromEnv();
|
|
239
259
|
if (!hasPlugins) {
|
|
240
260
|
return {
|
|
241
261
|
generateBuffer: async (document) => {
|
|
242
262
|
const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
|
|
243
263
|
const customThemes2 = await this.loadCustomThemes(options);
|
|
244
264
|
return await core.generateBufferFromJson(docDefinition, {
|
|
245
|
-
customThemes: customThemes2
|
|
265
|
+
customThemes: customThemes2,
|
|
266
|
+
services
|
|
246
267
|
});
|
|
247
268
|
},
|
|
248
269
|
hasPlugins: false,
|
|
@@ -254,7 +275,8 @@ var PptxFormatAdapter = class {
|
|
|
254
275
|
let generator = core.createPresentationGenerator({
|
|
255
276
|
theme,
|
|
256
277
|
customThemes,
|
|
257
|
-
debug: process.env.DEBUG === "true"
|
|
278
|
+
debug: process.env.DEBUG === "true",
|
|
279
|
+
services
|
|
258
280
|
});
|
|
259
281
|
for (const plugin of plugins) {
|
|
260
282
|
generator = generator.addComponent(plugin);
|