@json-to-office/jto 0.1.1 → 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/dist/cli.js +234 -49
- package/dist/cli.js.map +1 -1
- package/dist/client/assets/HomePage-BuV1dGoc.js +99 -0
- package/dist/client/assets/HomePage-BuV1dGoc.js.map +1 -0
- package/dist/client/assets/JsonEditorPage-y7DXYaWc.js +3 -0
- package/dist/client/assets/JsonEditorPage-y7DXYaWc.js.map +1 -0
- package/dist/client/assets/MonacoPluginProvider-B4-PgJ0r.js +3 -0
- package/dist/client/assets/MonacoPluginProvider-B4-PgJ0r.js.map +1 -0
- package/dist/client/assets/{button-CMkwEplC.js → button-Bf6x7Zjh.js} +2 -2
- package/dist/client/assets/{button-CMkwEplC.js.map → button-Bf6x7Zjh.js.map} +1 -1
- package/dist/client/assets/{editor-CtwF-qwA.js → editor-Bwuq290w.js} +2 -2
- package/dist/client/assets/{editor-CtwF-qwA.js.map → editor-Bwuq290w.js.map} +1 -1
- package/dist/client/assets/editor-monaco-json-BrfKPhHP.js +6 -0
- package/dist/client/assets/{editor-monaco-json-DHRbpQ-v.js.map → editor-monaco-json-BrfKPhHP.js.map} +1 -1
- package/dist/client/assets/index-Dmrqj1a7.css +1 -0
- package/dist/client/assets/index-uE8YOnrS.js +3 -0
- package/dist/client/assets/index-uE8YOnrS.js.map +1 -0
- package/dist/client/assets/preview-kcqt_5hb.js +3 -0
- package/dist/client/assets/{preview-38guLS86.js.map → preview-kcqt_5hb.js.map} +1 -1
- package/dist/client/assets/{state-vendor-CAMVKh-F.js → state-vendor-DypmJYNT.js} +2 -2
- package/dist/client/assets/{state-vendor-CAMVKh-F.js.map → state-vendor-DypmJYNT.js.map} +1 -1
- package/dist/client/assets/{ui-vendor-C6DsfOoA.js → ui-vendor-BFdEgxEg.js} +2 -2
- package/dist/client/assets/{ui-vendor-C6DsfOoA.js.map → ui-vendor-BFdEgxEg.js.map} +1 -1
- package/dist/client/index.html +3 -4
- package/dist/index.d.ts +8 -3
- package/dist/index.js +110 -19
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/client/assets/HomePage-D9PVR0H8.js +0 -99
- package/dist/client/assets/HomePage-D9PVR0H8.js.map +0 -1
- package/dist/client/assets/JsonEditorPage-bCBt1A49.js +0 -3
- package/dist/client/assets/JsonEditorPage-bCBt1A49.js.map +0 -1
- package/dist/client/assets/editor-monaco-json-DHRbpQ-v.js +0 -6
- package/dist/client/assets/index-B9dV-vCI.css +0 -1
- package/dist/client/assets/index-CGQAncgl.js +0 -3
- package/dist/client/assets/index-CGQAncgl.js.map +0 -1
- package/dist/client/assets/preview-38guLS86.js +0 -3
- package/dist/client/assets/settings-store-provider-BEzje7_o.js +0 -2
- package/dist/client/assets/settings-store-provider-BEzje7_o.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -335,10 +335,21 @@ var init_plugin_metadata = __esm({
|
|
|
335
335
|
const versionKeys = Object.keys(versions);
|
|
336
336
|
const latestVer = versionKeys.length > 0 ? latestVersion(versionKeys) : void 0;
|
|
337
337
|
const latestEntry = latestVer ? versions[latestVer] : void 0;
|
|
338
|
+
let format;
|
|
339
|
+
try {
|
|
340
|
+
const source = await fs3.readFile(filePath, "utf-8");
|
|
341
|
+
format = this.detectFormat(source);
|
|
342
|
+
} catch (err) {
|
|
343
|
+
console.warn(
|
|
344
|
+
`Failed to read plugin source for format detection: ${filePath}`,
|
|
345
|
+
err
|
|
346
|
+
);
|
|
347
|
+
}
|
|
338
348
|
const metadata = {
|
|
339
349
|
name: component.name,
|
|
340
350
|
description: latestEntry?.description,
|
|
341
351
|
version: latestVer,
|
|
352
|
+
format,
|
|
342
353
|
filePath,
|
|
343
354
|
relativePath,
|
|
344
355
|
location,
|
|
@@ -376,6 +387,27 @@ var init_plugin_metadata = __esm({
|
|
|
376
387
|
}
|
|
377
388
|
return "upstream";
|
|
378
389
|
}
|
|
390
|
+
detectFormat(source) {
|
|
391
|
+
const docxSignals = [
|
|
392
|
+
"@json-to-office/shared-docx",
|
|
393
|
+
"@json-to-office/core-docx",
|
|
394
|
+
"@json-to-office/json-to-docx",
|
|
395
|
+
"ComponentDefinition",
|
|
396
|
+
"ReportComponentDefinition"
|
|
397
|
+
];
|
|
398
|
+
const pptxSignals = [
|
|
399
|
+
"@json-to-office/shared-pptx",
|
|
400
|
+
"@json-to-office/core-pptx",
|
|
401
|
+
"@json-to-office/json-to-pptx",
|
|
402
|
+
"PptxComponentInput",
|
|
403
|
+
"PresentationComponentDefinition"
|
|
404
|
+
];
|
|
405
|
+
const hasDocx = docxSignals.some((s) => source.includes(s));
|
|
406
|
+
const hasPptx = pptxSignals.some((s) => source.includes(s));
|
|
407
|
+
if (hasDocx && !hasPptx) return "docx";
|
|
408
|
+
if (hasPptx && !hasDocx) return "pptx";
|
|
409
|
+
return void 0;
|
|
410
|
+
}
|
|
379
411
|
typeboxToJsonSchema(schema) {
|
|
380
412
|
try {
|
|
381
413
|
const jsonSchema = JSON.parse(JSON.stringify(schema));
|
|
@@ -618,10 +650,10 @@ var init_plugin_discovery = __esm({
|
|
|
618
650
|
}
|
|
619
651
|
this.metadataExtractor = new PluginMetadataExtractor(this.searchPath);
|
|
620
652
|
}
|
|
621
|
-
async discover() {
|
|
622
|
-
return this.discoverPlugins();
|
|
653
|
+
async discover(format) {
|
|
654
|
+
return this.discoverPlugins(format);
|
|
623
655
|
}
|
|
624
|
-
async discoverPlugins() {
|
|
656
|
+
async discoverPlugins(format) {
|
|
625
657
|
const startPath = this.searchPath;
|
|
626
658
|
try {
|
|
627
659
|
await this.loader.initialize();
|
|
@@ -645,6 +677,9 @@ var init_plugin_discovery = __esm({
|
|
|
645
677
|
if (locationDiff !== 0) return locationDiff;
|
|
646
678
|
return a.name.localeCompare(b.name);
|
|
647
679
|
});
|
|
680
|
+
if (format) {
|
|
681
|
+
return metadata.filter((p) => !p.format || p.format === format);
|
|
682
|
+
}
|
|
648
683
|
return metadata;
|
|
649
684
|
} finally {
|
|
650
685
|
this.loader.cleanup();
|
|
@@ -654,7 +689,10 @@ var init_plugin_discovery = __esm({
|
|
|
654
689
|
const startPath = this.searchPath;
|
|
655
690
|
const discoveryType = format === "pptx" ? "pptx-document" : "docx-document";
|
|
656
691
|
const ext = format === "pptx" ? ".pptx.json" : ".docx.json";
|
|
657
|
-
const allDocumentPaths = await this.searchDownstream(
|
|
692
|
+
const allDocumentPaths = await this.searchDownstream(
|
|
693
|
+
startPath,
|
|
694
|
+
discoveryType
|
|
695
|
+
);
|
|
658
696
|
const uniquePaths = this.scanner.deduplicatePaths(allDocumentPaths);
|
|
659
697
|
const metadata = [];
|
|
660
698
|
for (const docPath of uniquePaths) {
|
|
@@ -675,7 +713,11 @@ var init_plugin_discovery = __esm({
|
|
|
675
713
|
}
|
|
676
714
|
}
|
|
677
715
|
metadata.sort((a, b) => {
|
|
678
|
-
const locationOrder = {
|
|
716
|
+
const locationOrder = {
|
|
717
|
+
current: 0,
|
|
718
|
+
downstream: 1,
|
|
719
|
+
upstream: 2
|
|
720
|
+
};
|
|
679
721
|
const locationDiff = locationOrder[a.location] - locationOrder[b.location];
|
|
680
722
|
if (locationDiff !== 0) return locationDiff;
|
|
681
723
|
return a.name.localeCompare(b.name);
|
|
@@ -704,7 +746,11 @@ var init_plugin_discovery = __esm({
|
|
|
704
746
|
}
|
|
705
747
|
}
|
|
706
748
|
metadata.sort((a, b) => {
|
|
707
|
-
const locationOrder = {
|
|
749
|
+
const locationOrder = {
|
|
750
|
+
current: 0,
|
|
751
|
+
downstream: 1,
|
|
752
|
+
upstream: 2
|
|
753
|
+
};
|
|
708
754
|
const locationDiff = locationOrder[a.location] - locationOrder[b.location];
|
|
709
755
|
if (locationDiff !== 0) return locationDiff;
|
|
710
756
|
return a.name.localeCompare(b.name);
|
|
@@ -725,7 +771,7 @@ var init_plugin_discovery = __esm({
|
|
|
725
771
|
}
|
|
726
772
|
async discoverAll(format) {
|
|
727
773
|
const [plugins, documents, themes] = await Promise.all([
|
|
728
|
-
this.discoverPlugins(),
|
|
774
|
+
this.discoverPlugins(format),
|
|
729
775
|
this.discoverDocuments(format),
|
|
730
776
|
this.discoverThemes(format)
|
|
731
777
|
]);
|
|
@@ -821,6 +867,7 @@ var init_plugin_registry = __esm({
|
|
|
821
867
|
pluginMetadata = /* @__PURE__ */ new Map();
|
|
822
868
|
loader;
|
|
823
869
|
discoveryService;
|
|
870
|
+
_format;
|
|
824
871
|
constructor() {
|
|
825
872
|
this.loader = new PluginLoader();
|
|
826
873
|
this.discoveryService = new PluginDiscoveryService();
|
|
@@ -831,6 +878,9 @@ var init_plugin_registry = __esm({
|
|
|
831
878
|
}
|
|
832
879
|
return _PluginRegistry.instance;
|
|
833
880
|
}
|
|
881
|
+
setFormat(format) {
|
|
882
|
+
this._format = format;
|
|
883
|
+
}
|
|
834
884
|
notifyCacheInvalidation() {
|
|
835
885
|
try {
|
|
836
886
|
invalidateAllCaches();
|
|
@@ -902,7 +952,7 @@ var init_plugin_registry = __esm({
|
|
|
902
952
|
scope: dir,
|
|
903
953
|
maxDepth: 5
|
|
904
954
|
});
|
|
905
|
-
const pluginMetadata = await discovery.discover();
|
|
955
|
+
const pluginMetadata = await discovery.discover(this._format);
|
|
906
956
|
return await this.loadPluginsFromMetadata(pluginMetadata);
|
|
907
957
|
} catch (error) {
|
|
908
958
|
throw new Error(
|
|
@@ -915,7 +965,7 @@ var init_plugin_registry = __esm({
|
|
|
915
965
|
async discoverAndLoad() {
|
|
916
966
|
try {
|
|
917
967
|
await this.loader.initialize();
|
|
918
|
-
const pluginMetadata = await this.discoveryService.discover();
|
|
968
|
+
const pluginMetadata = await this.discoveryService.discover(this._format);
|
|
919
969
|
const discovered = pluginMetadata.length;
|
|
920
970
|
if (discovered === 0) {
|
|
921
971
|
return { discovered: 0, loaded: 0 };
|
|
@@ -933,7 +983,7 @@ var init_plugin_registry = __esm({
|
|
|
933
983
|
return this.pluginPaths.get(name);
|
|
934
984
|
}
|
|
935
985
|
try {
|
|
936
|
-
const pluginMetadata = await this.discoveryService.discover();
|
|
986
|
+
const pluginMetadata = await this.discoveryService.discover(this._format);
|
|
937
987
|
const metadata = pluginMetadata.find((p) => p.name === name);
|
|
938
988
|
if (metadata) return metadata.filePath;
|
|
939
989
|
} catch {
|
|
@@ -1137,6 +1187,7 @@ var init_generator = __esm({
|
|
|
1137
1187
|
init_esm_shims();
|
|
1138
1188
|
init_logger();
|
|
1139
1189
|
init_cache_events();
|
|
1190
|
+
init_plugin_registry();
|
|
1140
1191
|
GeneratorService = class {
|
|
1141
1192
|
adapter;
|
|
1142
1193
|
cacheService;
|
|
@@ -1151,7 +1202,10 @@ var init_generator = __esm({
|
|
|
1151
1202
|
const { jsonDefinition, customThemes, options } = request;
|
|
1152
1203
|
const config2 = typeof jsonDefinition === "string" ? JSON.parse(jsonDefinition) : jsonDefinition;
|
|
1153
1204
|
const bypassCache = options?.bypassCache === true;
|
|
1154
|
-
const cacheKeyData = {
|
|
1205
|
+
const cacheKeyData = {
|
|
1206
|
+
config: config2,
|
|
1207
|
+
customThemes: customThemes && Object.keys(customThemes).length > 0 ? customThemes : null
|
|
1208
|
+
};
|
|
1155
1209
|
const cacheKey = this.cacheService.generateCacheKey(cacheKeyData);
|
|
1156
1210
|
const hasDynamicContent = this.cacheService.hasDynamicContent(config2);
|
|
1157
1211
|
if (!bypassCache && !hasDynamicContent) {
|
|
@@ -1167,8 +1221,20 @@ var init_generator = __esm({
|
|
|
1167
1221
|
};
|
|
1168
1222
|
}
|
|
1169
1223
|
}
|
|
1170
|
-
logger.info(`Generating ${this.adapter.label}`, {
|
|
1171
|
-
|
|
1224
|
+
logger.info(`Generating ${this.adapter.label}`, {
|
|
1225
|
+
title: config2.metadata?.title
|
|
1226
|
+
});
|
|
1227
|
+
const registry = PluginRegistry.getInstance();
|
|
1228
|
+
let buffer;
|
|
1229
|
+
if (registry.hasPlugins()) {
|
|
1230
|
+
const plugins = registry.getPlugins();
|
|
1231
|
+
const generator = await this.adapter.createGenerator(plugins, {
|
|
1232
|
+
customThemes
|
|
1233
|
+
});
|
|
1234
|
+
buffer = await generator.generateBuffer(config2);
|
|
1235
|
+
} else {
|
|
1236
|
+
buffer = await this.adapter.generateBuffer(config2, { customThemes });
|
|
1237
|
+
}
|
|
1172
1238
|
this.cacheService.set(cacheKey, buffer, config2, {
|
|
1173
1239
|
bypassCache: bypassCache || hasDynamicContent
|
|
1174
1240
|
});
|
|
@@ -1942,22 +2008,55 @@ var init_format = __esm({
|
|
|
1942
2008
|
|
|
1943
2009
|
// src/server/routes/discovery.ts
|
|
1944
2010
|
import { Hono as Hono3 } from "hono";
|
|
2011
|
+
import { latestVersion as latestVersion2 } from "@json-to-office/shared";
|
|
1945
2012
|
function cleanupTypeBoxIds(schema) {
|
|
1946
2013
|
if (typeof schema !== "object" || schema === null) return;
|
|
1947
2014
|
if (schema.$id && /^T\d+$/.test(schema.$id)) delete schema.$id;
|
|
1948
|
-
if (schema.$ref && /^T\d+$/.test(schema.$ref))
|
|
2015
|
+
if (schema.$ref && /^T\d+$/.test(schema.$ref))
|
|
2016
|
+
schema.$ref = "#/definitions/ComponentDefinition";
|
|
1949
2017
|
if (Array.isArray(schema)) {
|
|
1950
2018
|
schema.forEach(cleanupTypeBoxIds);
|
|
1951
2019
|
return;
|
|
1952
2020
|
}
|
|
1953
2021
|
Object.keys(schema).forEach((key) => {
|
|
1954
|
-
if (typeof schema[key] === "object" && schema[key] !== null)
|
|
2022
|
+
if (typeof schema[key] === "object" && schema[key] !== null)
|
|
2023
|
+
cleanupTypeBoxIds(schema[key]);
|
|
1955
2024
|
});
|
|
1956
2025
|
}
|
|
1957
|
-
|
|
2026
|
+
function getSelectedPlugins(pluginNames) {
|
|
2027
|
+
const registry = PluginRegistry.getInstance();
|
|
2028
|
+
if (!registry.hasPlugins()) return [];
|
|
2029
|
+
const plugins = pluginNames?.length ? pluginNames.map((n) => registry.getPlugin(n)).filter(Boolean) : registry.getPlugins();
|
|
2030
|
+
return plugins.map((plugin) => {
|
|
2031
|
+
const versions = plugin.versions || {};
|
|
2032
|
+
const versionKeys = Object.keys(versions);
|
|
2033
|
+
const latest = versionKeys.length > 0 ? latestVersion2(versionKeys) : void 0;
|
|
2034
|
+
const latestEntry = latest ? versions[latest] : void 0;
|
|
2035
|
+
return { name: plugin.name, versions, versionKeys, latest, latestEntry };
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
async function generateDocumentSchema(format, pluginNames) {
|
|
2039
|
+
const selected = getSelectedPlugins(pluginNames);
|
|
1958
2040
|
if (format === "docx") {
|
|
1959
2041
|
const shared = await import("@json-to-office/shared-docx");
|
|
1960
|
-
const
|
|
2042
|
+
const customComponents = selected.filter((p) => p.latestEntry?.propsSchema).map((p) => {
|
|
2043
|
+
const info = {
|
|
2044
|
+
name: p.name,
|
|
2045
|
+
propsSchema: p.latestEntry.propsSchema,
|
|
2046
|
+
hasChildren: p.latestEntry?.hasChildren,
|
|
2047
|
+
description: p.latestEntry?.description
|
|
2048
|
+
};
|
|
2049
|
+
if (p.versionKeys.length > 1) {
|
|
2050
|
+
info.versionedProps = p.versionKeys.map((v) => ({
|
|
2051
|
+
version: v,
|
|
2052
|
+
propsSchema: p.versions[v].propsSchema,
|
|
2053
|
+
description: p.versions[v].description,
|
|
2054
|
+
hasChildren: p.versions[v].hasChildren
|
|
2055
|
+
}));
|
|
2056
|
+
}
|
|
2057
|
+
return info;
|
|
2058
|
+
});
|
|
2059
|
+
const unified = shared.generateUnifiedDocumentSchema({ customComponents });
|
|
1961
2060
|
return shared.convertToJsonSchema(unified, {
|
|
1962
2061
|
$schema: "https://json-schema.org/draft-07/schema#",
|
|
1963
2062
|
$id: "https://json-to-office.dev/schema/document/v1.0.0",
|
|
@@ -1966,7 +2065,16 @@ async function generateDocumentSchema(format) {
|
|
|
1966
2065
|
});
|
|
1967
2066
|
} else {
|
|
1968
2067
|
const shared = await import("@json-to-office/shared-pptx");
|
|
1969
|
-
const
|
|
2068
|
+
const customComponents = selected.map((p) => ({
|
|
2069
|
+
name: p.name,
|
|
2070
|
+
versions: p.versionKeys.map((v) => ({
|
|
2071
|
+
version: v,
|
|
2072
|
+
propsSchema: p.versions[v].propsSchema,
|
|
2073
|
+
hasChildren: p.versions[v].hasChildren,
|
|
2074
|
+
description: p.versions[v].description
|
|
2075
|
+
}))
|
|
2076
|
+
}));
|
|
2077
|
+
const unified = shared.generateUnifiedDocumentSchema({ customComponents });
|
|
1970
2078
|
return shared.convertToJsonSchema(unified, {
|
|
1971
2079
|
$schema: "https://json-schema.org/draft-07/schema#",
|
|
1972
2080
|
$id: "https://json-to-office.dev/schema/presentation/v1.0.0",
|
|
@@ -2016,7 +2124,7 @@ var init_discovery = __esm({
|
|
|
2016
2124
|
verbose: false
|
|
2017
2125
|
});
|
|
2018
2126
|
const [plugins, documents, themes] = await Promise.all([
|
|
2019
|
-
discovery.discoverPlugins(),
|
|
2127
|
+
discovery.discoverPlugins(format),
|
|
2020
2128
|
discovery.discoverDocuments(format),
|
|
2021
2129
|
discovery.discoverThemes(format)
|
|
2022
2130
|
]);
|
|
@@ -2039,12 +2147,13 @@ var init_discovery = __esm({
|
|
|
2039
2147
|
try {
|
|
2040
2148
|
const includeSchemas = c.req.query("schemas") === "true";
|
|
2041
2149
|
const includeExamples = c.req.query("examples") === "true";
|
|
2150
|
+
const format = Container.getAdapter().name;
|
|
2042
2151
|
const discovery = new PluginDiscoveryService({
|
|
2043
2152
|
maxDepth: 10,
|
|
2044
2153
|
includeNodeModules: false,
|
|
2045
2154
|
verbose: false
|
|
2046
2155
|
});
|
|
2047
|
-
const plugins = await discovery.discoverPlugins();
|
|
2156
|
+
const plugins = await discovery.discoverPlugins(format);
|
|
2048
2157
|
const processed = plugins.map((plugin) => {
|
|
2049
2158
|
const result = { ...plugin };
|
|
2050
2159
|
if (!includeSchemas && result.schema) {
|
|
@@ -2093,14 +2202,19 @@ var init_discovery = __esm({
|
|
|
2093
2202
|
discoveryRouter.get("/plugin/:name", async (c) => {
|
|
2094
2203
|
try {
|
|
2095
2204
|
const pluginName = c.req.param("name");
|
|
2205
|
+
const format = Container.getAdapter().name;
|
|
2096
2206
|
const discovery = new PluginDiscoveryService({
|
|
2097
2207
|
maxDepth: 10,
|
|
2098
2208
|
includeNodeModules: false,
|
|
2099
2209
|
verbose: false
|
|
2100
2210
|
});
|
|
2101
|
-
const plugins = await discovery.discoverPlugins();
|
|
2211
|
+
const plugins = await discovery.discoverPlugins(format);
|
|
2102
2212
|
const plugin = plugins.find((p) => p.name === pluginName);
|
|
2103
|
-
if (!plugin)
|
|
2213
|
+
if (!plugin)
|
|
2214
|
+
return c.json(
|
|
2215
|
+
{ success: false, error: `Plugin '${pluginName}' not found` },
|
|
2216
|
+
404
|
|
2217
|
+
);
|
|
2104
2218
|
return c.json({ success: true, data: plugin });
|
|
2105
2219
|
} catch (error) {
|
|
2106
2220
|
return c.json({ success: false, error: error.message }, 500);
|
|
@@ -2112,7 +2226,9 @@ var init_discovery = __esm({
|
|
|
2112
2226
|
return c.json({ success: false, error: "Authentication required" }, 401);
|
|
2113
2227
|
}
|
|
2114
2228
|
try {
|
|
2229
|
+
const format = Container.getAdapter().name;
|
|
2115
2230
|
const registry = PluginRegistry.getInstance();
|
|
2231
|
+
registry.setFormat(format);
|
|
2116
2232
|
const result = await registry.discoverAndLoad();
|
|
2117
2233
|
return c.json({ success: true, data: result });
|
|
2118
2234
|
} catch (error) {
|
|
@@ -2154,7 +2270,9 @@ var init_discovery = __esm({
|
|
|
2154
2270
|
discoveryRouter.get("/schemas/document", async (c) => {
|
|
2155
2271
|
try {
|
|
2156
2272
|
const adapter = Container.getAdapter();
|
|
2157
|
-
const
|
|
2273
|
+
const pluginsParam = c.req.query("plugins");
|
|
2274
|
+
const pluginNames = pluginsParam ? pluginsParam.split(",").filter(Boolean) : void 0;
|
|
2275
|
+
const schema = await generateDocumentSchema(adapter.name, pluginNames);
|
|
2158
2276
|
return c.json({ success: true, data: schema });
|
|
2159
2277
|
} catch (error) {
|
|
2160
2278
|
logger.error("Document schema generation failed", { error: error.message });
|
|
@@ -3222,7 +3340,9 @@ var DocxFormatAdapter = class {
|
|
|
3222
3340
|
const core = await import("@json-to-office/core-docx");
|
|
3223
3341
|
const docDefinition = typeof json === "string" ? JSON.parse(json) : json;
|
|
3224
3342
|
const customThemes = await this.loadCustomThemes(options);
|
|
3225
|
-
return await core.generateBufferFromJson(docDefinition, {
|
|
3343
|
+
return await core.generateBufferFromJson(docDefinition, {
|
|
3344
|
+
customThemes
|
|
3345
|
+
});
|
|
3226
3346
|
}
|
|
3227
3347
|
async createGenerator(plugins, options) {
|
|
3228
3348
|
const core = await import("@json-to-office/core-docx");
|
|
@@ -3232,16 +3352,20 @@ var DocxFormatAdapter = class {
|
|
|
3232
3352
|
return {
|
|
3233
3353
|
generateBuffer: async (document) => {
|
|
3234
3354
|
const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
|
|
3235
|
-
const
|
|
3236
|
-
return await core.generateBufferFromJson(docDefinition, {
|
|
3355
|
+
const customThemes2 = await this.loadCustomThemes(options);
|
|
3356
|
+
return await core.generateBufferFromJson(docDefinition, {
|
|
3357
|
+
customThemes: customThemes2
|
|
3358
|
+
});
|
|
3237
3359
|
},
|
|
3238
3360
|
hasPlugins: false,
|
|
3239
3361
|
pluginNames: []
|
|
3240
3362
|
};
|
|
3241
3363
|
}
|
|
3242
3364
|
const theme = await this.resolveTheme(options);
|
|
3365
|
+
const customThemes = await this.loadCustomThemes(options);
|
|
3243
3366
|
let generator = core.createDocumentGenerator({
|
|
3244
3367
|
theme,
|
|
3368
|
+
customThemes,
|
|
3245
3369
|
debug: process.env.DEBUG === "true"
|
|
3246
3370
|
});
|
|
3247
3371
|
for (const plugin of plugins) {
|
|
@@ -3427,19 +3551,52 @@ var PptxFormatAdapter = class {
|
|
|
3427
3551
|
const core = await import("@json-to-office/core-pptx");
|
|
3428
3552
|
const docDefinition = typeof json === "string" ? JSON.parse(json) : json;
|
|
3429
3553
|
const customThemes = await this.loadCustomThemes(options);
|
|
3430
|
-
return await core.generateBufferFromJson(docDefinition, {
|
|
3554
|
+
return await core.generateBufferFromJson(docDefinition, {
|
|
3555
|
+
customThemes
|
|
3556
|
+
});
|
|
3431
3557
|
}
|
|
3432
3558
|
async createGenerator(plugins, options) {
|
|
3433
3559
|
const core = await import("@json-to-office/core-pptx");
|
|
3434
3560
|
const hasPlugins = plugins.length > 0;
|
|
3435
3561
|
const pluginNames = plugins.map((p) => p.name);
|
|
3562
|
+
if (!hasPlugins) {
|
|
3563
|
+
return {
|
|
3564
|
+
generateBuffer: async (document) => {
|
|
3565
|
+
const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
|
|
3566
|
+
const customThemes2 = await this.loadCustomThemes(options);
|
|
3567
|
+
return await core.generateBufferFromJson(docDefinition, {
|
|
3568
|
+
customThemes: customThemes2
|
|
3569
|
+
});
|
|
3570
|
+
},
|
|
3571
|
+
hasPlugins: false,
|
|
3572
|
+
pluginNames: []
|
|
3573
|
+
};
|
|
3574
|
+
}
|
|
3575
|
+
const theme = await this.resolveTheme(options);
|
|
3576
|
+
const customThemes = await this.loadCustomThemes(options);
|
|
3577
|
+
let generator = core.createPresentationGenerator({
|
|
3578
|
+
theme,
|
|
3579
|
+
customThemes,
|
|
3580
|
+
debug: process.env.DEBUG === "true"
|
|
3581
|
+
});
|
|
3582
|
+
for (const plugin of plugins) {
|
|
3583
|
+
generator = generator.addComponent(plugin);
|
|
3584
|
+
}
|
|
3436
3585
|
return {
|
|
3437
3586
|
generateBuffer: async (document) => {
|
|
3438
3587
|
const docDefinition = typeof document === "string" ? JSON.parse(document) : document;
|
|
3439
|
-
const
|
|
3440
|
-
|
|
3588
|
+
const validationResult = generator.validate(docDefinition);
|
|
3589
|
+
if (!validationResult.valid) {
|
|
3590
|
+
const errors = validationResult.errors || [];
|
|
3591
|
+
throw new Error(
|
|
3592
|
+
`Presentation validation failed:
|
|
3593
|
+
${errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n")}`
|
|
3594
|
+
);
|
|
3595
|
+
}
|
|
3596
|
+
const result = await generator.generateBuffer(docDefinition);
|
|
3597
|
+
return result.buffer;
|
|
3441
3598
|
},
|
|
3442
|
-
hasPlugins,
|
|
3599
|
+
hasPlugins: true,
|
|
3443
3600
|
pluginNames
|
|
3444
3601
|
};
|
|
3445
3602
|
}
|
|
@@ -3739,8 +3896,10 @@ var PluginResolver = class {
|
|
|
3739
3896
|
discoveredPlugins = /* @__PURE__ */ new Map();
|
|
3740
3897
|
lastDiscoveryTime = 0;
|
|
3741
3898
|
CACHE_DURATION = 5 * 60 * 1e3;
|
|
3742
|
-
|
|
3899
|
+
format;
|
|
3900
|
+
constructor(format) {
|
|
3743
3901
|
this.discoveryService = new PluginDiscoveryService();
|
|
3902
|
+
this.format = format;
|
|
3744
3903
|
}
|
|
3745
3904
|
async resolve(input) {
|
|
3746
3905
|
const pathResult = await this.resolveAsPath(input);
|
|
@@ -3793,7 +3952,7 @@ ${errors.join("\n")}`);
|
|
|
3793
3952
|
}
|
|
3794
3953
|
async refreshDiscoveryCache() {
|
|
3795
3954
|
try {
|
|
3796
|
-
const plugins = await this.discoveryService.discover();
|
|
3955
|
+
const plugins = await this.discoveryService.discover(this.format);
|
|
3797
3956
|
this.discoveredPlugins.clear();
|
|
3798
3957
|
for (const plugin of plugins) {
|
|
3799
3958
|
this.discoveredPlugins.set(plugin.name, plugin);
|
|
@@ -3865,8 +4024,9 @@ ${errors.join("\n")}`);
|
|
|
3865
4024
|
};
|
|
3866
4025
|
|
|
3867
4026
|
// src/commands/shared.ts
|
|
3868
|
-
async function loadPlugins(options, config2, configService, spinner) {
|
|
4027
|
+
async function loadPlugins(options, config2, configService, spinner, format) {
|
|
3869
4028
|
const registry = PluginRegistry.getInstance();
|
|
4029
|
+
if (format) registry.setFormat(format);
|
|
3870
4030
|
if (options.plugins !== void 0) {
|
|
3871
4031
|
spinner.text = "Loading plugins...";
|
|
3872
4032
|
if (options.plugins === true) {
|
|
@@ -3888,7 +4048,7 @@ async function loadPlugins(options, config2, configService, spinner) {
|
|
|
3888
4048
|
}
|
|
3889
4049
|
} else if (config2?.plugins && config2.plugins.length > 0) {
|
|
3890
4050
|
spinner.text = "Loading configured plugins...";
|
|
3891
|
-
const resolver = new PluginResolver();
|
|
4051
|
+
const resolver = new PluginResolver(format);
|
|
3892
4052
|
const resolved = await resolver.resolveMultiple(config2.plugins);
|
|
3893
4053
|
const paths = [];
|
|
3894
4054
|
for (const [, resolvedPath] of resolved) {
|
|
@@ -3973,7 +4133,10 @@ function createGenerateCommand(adapter) {
|
|
|
3973
4133
|
return new Command("generate").description(`Generate ${adapter.label} from JSON`).argument("<input>", "Input JSON file path").option("-o, --output <path>", "Output file path").option("-t, --template <name>", "Template to use").option(
|
|
3974
4134
|
"--plugins [names-or-paths]",
|
|
3975
4135
|
"Load plugins (comma-separated names/paths, or no value for auto-discovery)"
|
|
3976
|
-
).option("--plugin-dir <dir>", "Directory to search for plugins").option("--theme <name-or-path>", "Theme name or path to theme file").option(
|
|
4136
|
+
).option("--plugin-dir <dir>", "Directory to search for plugins").option("--theme <name-or-path>", "Theme name or path to theme file").option(
|
|
4137
|
+
"--theme-path <path>",
|
|
4138
|
+
"Path to theme file (alternative to --theme)"
|
|
4139
|
+
).option("--strict", "Enable strict validation").option("--dry-run", "Preview without writing files").action(async (input, options) => {
|
|
3977
4140
|
const spinner = ora("Initializing...").start();
|
|
3978
4141
|
const startTime = performance.now();
|
|
3979
4142
|
try {
|
|
@@ -3988,13 +4151,22 @@ function createGenerateCommand(adapter) {
|
|
|
3988
4151
|
themePath: options.themePath,
|
|
3989
4152
|
validation: { strict: options.strict }
|
|
3990
4153
|
};
|
|
3991
|
-
await loadPlugins(
|
|
4154
|
+
await loadPlugins(
|
|
4155
|
+
options,
|
|
4156
|
+
config2,
|
|
4157
|
+
configService,
|
|
4158
|
+
spinner,
|
|
4159
|
+
adapter.name
|
|
4160
|
+
);
|
|
3992
4161
|
spinner.text = "Reading input file...";
|
|
3993
4162
|
const inputPath = resolve9(process.cwd(), input);
|
|
3994
4163
|
const jsonContent = readFileSync3(inputPath, "utf-8");
|
|
3995
4164
|
const documentDefinition = JSON.parse(jsonContent);
|
|
3996
4165
|
const factory = new GeneratorFactory(adapter);
|
|
3997
|
-
const outputPath = options.output ? resolve9(process.cwd(), options.output) : resolve9(
|
|
4166
|
+
const outputPath = options.output ? resolve9(process.cwd(), options.output) : resolve9(
|
|
4167
|
+
process.cwd(),
|
|
4168
|
+
basename4(input, ".json") + adapter.extension
|
|
4169
|
+
);
|
|
3998
4170
|
const pluginInfo = factory.getPluginInfo();
|
|
3999
4171
|
if (options.dryRun) {
|
|
4000
4172
|
spinner.succeed(`Dry run complete ${formatTiming(startTime)}`);
|
|
@@ -4006,7 +4178,9 @@ function createGenerateCommand(adapter) {
|
|
|
4006
4178
|
`${chalk2.cyan("Strict:")} ${mergedConfig.validation?.strict ? "yes" : "no"}`
|
|
4007
4179
|
];
|
|
4008
4180
|
if (pluginInfo.hasPlugins) {
|
|
4009
|
-
lines2.push(
|
|
4181
|
+
lines2.push(
|
|
4182
|
+
`${chalk2.cyan("Plugins:")} ${pluginInfo.count} loaded (${pluginInfo.names.join(", ")})`
|
|
4183
|
+
);
|
|
4010
4184
|
}
|
|
4011
4185
|
lines2.push(`${chalk2.cyan("Validation:")} ${chalk2.green("passed")}`);
|
|
4012
4186
|
console.log(
|
|
@@ -4038,7 +4212,9 @@ function createGenerateCommand(adapter) {
|
|
|
4038
4212
|
`${chalk2.cyan("Format:")} ${adapter.name}`
|
|
4039
4213
|
];
|
|
4040
4214
|
if (pluginInfo.hasPlugins) {
|
|
4041
|
-
lines.push(
|
|
4215
|
+
lines.push(
|
|
4216
|
+
`${chalk2.cyan("Plugins:")} ${pluginInfo.count} loaded (${pluginInfo.names.join(", ")})`
|
|
4217
|
+
);
|
|
4042
4218
|
}
|
|
4043
4219
|
console.log(
|
|
4044
4220
|
boxen(lines.join("\n"), {
|
|
@@ -4051,7 +4227,9 @@ function createGenerateCommand(adapter) {
|
|
|
4051
4227
|
);
|
|
4052
4228
|
PluginRegistry.getInstance().clear();
|
|
4053
4229
|
} catch (error) {
|
|
4054
|
-
spinner.fail(
|
|
4230
|
+
spinner.fail(
|
|
4231
|
+
`${adapter.label.charAt(0).toUpperCase() + adapter.label.slice(1)} generation failed`
|
|
4232
|
+
);
|
|
4055
4233
|
formatError(error);
|
|
4056
4234
|
PluginRegistry.getInstance().clear();
|
|
4057
4235
|
process.exit(EXIT_CODES.FAIL);
|
|
@@ -4763,17 +4941,20 @@ function createSchemasCommand(adapter) {
|
|
|
4763
4941
|
).option(
|
|
4764
4942
|
"--plugins [names-or-paths]",
|
|
4765
4943
|
"Load plugins (comma-separated names/paths, or no value for auto-discovery)"
|
|
4766
|
-
).option("--plugin-dir <dir>", "Directory to search for plugins").option("-f, --format <type>", "Output format (json or typebox)", "json").option("--theme-only", "Generate only theme schemas").option("--document-only", "Generate only document schemas").option(
|
|
4767
|
-
"--split",
|
|
4768
|
-
"Generate separate schema files for each component type"
|
|
4769
|
-
).action(async (options) => {
|
|
4944
|
+
).option("--plugin-dir <dir>", "Directory to search for plugins").option("-f, --format <type>", "Output format (json or typebox)", "json").option("--theme-only", "Generate only theme schemas").option("--document-only", "Generate only document schemas").option("--split", "Generate separate schema files for each component type").action(async (options) => {
|
|
4770
4945
|
const spinner = ora3("Initializing...").start();
|
|
4771
4946
|
const startTime = performance.now();
|
|
4772
4947
|
try {
|
|
4773
4948
|
const configService = PluginConfigService.getInstance();
|
|
4774
4949
|
const config2 = await configService.loadConfig();
|
|
4775
4950
|
if (!options.themeOnly) {
|
|
4776
|
-
await loadPlugins(
|
|
4951
|
+
await loadPlugins(
|
|
4952
|
+
options,
|
|
4953
|
+
config2,
|
|
4954
|
+
configService,
|
|
4955
|
+
spinner,
|
|
4956
|
+
adapter.name
|
|
4957
|
+
);
|
|
4777
4958
|
}
|
|
4778
4959
|
spinner.text = "Generating schemas...";
|
|
4779
4960
|
const generator = new SchemaGenerator(adapter.name);
|
|
@@ -4791,7 +4972,9 @@ function createSchemasCommand(adapter) {
|
|
|
4791
4972
|
outputDir,
|
|
4792
4973
|
generateOptions
|
|
4793
4974
|
);
|
|
4794
|
-
spinner.succeed(
|
|
4975
|
+
spinner.succeed(
|
|
4976
|
+
`Schema generation completed! ${formatTiming(startTime)}`
|
|
4977
|
+
);
|
|
4795
4978
|
const rows = [];
|
|
4796
4979
|
if (results.document) {
|
|
4797
4980
|
rows.push(["Document", shortPath(results.document)]);
|
|
@@ -5013,7 +5196,9 @@ var PluginDisplay = class {
|
|
|
5013
5196
|
// src/commands/discover.ts
|
|
5014
5197
|
init_plugin_registry();
|
|
5015
5198
|
function createDiscoverCommand(adapter) {
|
|
5016
|
-
return new Command4("discover").description(
|
|
5199
|
+
return new Command4("discover").description(
|
|
5200
|
+
`Discover json-to-${adapter.name} plugins, documents, and themes`
|
|
5201
|
+
).option("-j, --json", "Output as JSON").option("-s, --schema", "Include full schemas in output (plugins only)").option("-e, --examples", "Include usage examples (plugins only)").option(
|
|
5017
5202
|
"-t, --type <type>",
|
|
5018
5203
|
"Type to discover: plugin, document, theme, or all (default: all)",
|
|
5019
5204
|
"all"
|
|
@@ -5054,7 +5239,7 @@ function createDiscoverCommand(adapter) {
|
|
|
5054
5239
|
themes = results.themes;
|
|
5055
5240
|
totalCount = plugins.length + documents.length + themes.length;
|
|
5056
5241
|
} else if (discoverType === "plugin") {
|
|
5057
|
-
plugins = await discovery.discoverPlugins();
|
|
5242
|
+
plugins = await discovery.discoverPlugins(format);
|
|
5058
5243
|
totalCount = plugins.length;
|
|
5059
5244
|
} else if (discoverType === "document") {
|
|
5060
5245
|
documents = await discovery.discoverDocuments(format);
|
|
@@ -5592,7 +5777,7 @@ ${chalk8.cyan("Health:")} ${url}/health
|
|
|
5592
5777
|
}
|
|
5593
5778
|
|
|
5594
5779
|
// src/cli.ts
|
|
5595
|
-
var PACKAGE_VERSION = true ? "0.
|
|
5780
|
+
var PACKAGE_VERSION = true ? "0.2.0" : "dev-mode";
|
|
5596
5781
|
function registerFormatCommands(parent, adapter) {
|
|
5597
5782
|
parent.addCommand(createGenerateCommand(adapter));
|
|
5598
5783
|
parent.addCommand(createValidateCommand(adapter));
|