@cparra/apexdocs 2.25.0-alpha.8 → 2.25.0-alpha.9
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/generate.js +153 -165
- package/dist/index.d.ts +51 -13
- package/examples/plain-markdown/docs/index.md +25 -33
- package/examples/plain-markdown/docs/{Miscellaneous/ns.BaseClass.md → miscellaneous/BaseClass.md} +1 -1
- package/examples/plain-markdown/docs/{Miscellaneous/ns.MultiInheritanceClass.md → miscellaneous/MultiInheritanceClass.md} +5 -6
- package/examples/plain-markdown/docs/{Miscellaneous/ns.SampleException.md → miscellaneous/SampleException.md} +3 -4
- package/examples/plain-markdown/docs/{Miscellaneous/ns.SampleInterface.md → miscellaneous/SampleInterface.md} +22 -29
- package/examples/plain-markdown/docs/{Miscellaneous/ns.Url.md → miscellaneous/Url.md} +32 -43
- package/examples/plain-markdown/docs/sample-enums/SampleEnum.md +36 -0
- package/examples/plain-markdown/docs/{SampleGroup/ns.SampleClass.md → samplegroup/SampleClass.md} +8 -11
- package/examples/vitepress/apexdocs.config.ts +1 -3
- package/examples/vitepress/docs/.vitepress/sidebar.json +18 -18
- package/examples/vitepress/docs/index.md +10 -10
- package/examples/vitepress/docs/{Miscellaneous/apexdocs.BaseClass.md → miscellaneous/BaseClass.md} +1 -1
- package/examples/vitepress/docs/{Miscellaneous/apexdocs.MultiInheritanceClass.md → miscellaneous/MultiInheritanceClass.md} +2 -2
- package/examples/vitepress/docs/{Miscellaneous/apexdocs.SampleException.md → miscellaneous/SampleException.md} +1 -1
- package/examples/vitepress/docs/{Miscellaneous/apexdocs.SampleInterface.md → miscellaneous/SampleInterface.md} +6 -6
- package/examples/vitepress/docs/{Miscellaneous/apexdocs.Url.md → miscellaneous/Url.md} +3 -3
- package/examples/vitepress/docs/{Sample-Enums/apexdocs.SampleEnum.md → sample-enums/SampleEnum.md} +3 -3
- package/examples/vitepress/docs/{SampleGroup/apexdocs.SampleClass.md → samplegroup/SampleClass.md} +4 -4
- package/package.json +1 -1
- package/src/application/apex-file-reader.ts +3 -3
- package/src/application/file-writer.ts +5 -9
- package/src/application/generators/markdown.ts +9 -4
- package/src/application/generators/openapi.ts +4 -4
- package/src/core/markdown/__test__/generating-class-docs.spec.ts +5 -3
- package/src/core/markdown/__test__/generating-enum-docs.spec.ts +3 -3
- package/src/core/markdown/__test__/generating-interface-docs.spec.ts +5 -3
- package/src/core/markdown/__test__/generating-reference-guide.spec.ts +3 -7
- package/src/core/markdown/__test__/test-helpers.ts +3 -3
- package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +40 -5
- package/src/core/markdown/adapters/apex-types.ts +3 -2
- package/src/core/markdown/adapters/reference-guide.ts +35 -0
- package/src/core/markdown/adapters/renderable-bundle.ts +43 -119
- package/src/core/markdown/adapters/renderable-to-page-data.ts +12 -15
- package/src/core/markdown/adapters/types.d.ts +4 -6
- package/src/core/markdown/generate-docs.ts +99 -42
- package/src/core/markdown/reflection/inheritance-chain-expanion.ts +1 -1
- package/src/core/markdown/reflection/reflect-source.ts +8 -4
- package/src/core/openapi/manifest-factory.ts +2 -2
- package/src/core/openapi/openapi-type-file.ts +1 -3
- package/src/core/openapi/parser.ts +4 -4
- package/src/core/shared/types.d.ts +52 -14
- package/src/index.ts +2 -1
- package/examples/plain-markdown/docs/Sample-Enums/ns.SampleEnum.md +0 -38
- /package/examples/plain-markdown/docs/{Miscellaneous/ns.ParentInterface.md → miscellaneous/ParentInterface.md} +0 -0
- /package/examples/plain-markdown/docs/{Miscellaneous/ns.ReferencedEnum.md → miscellaneous/ReferencedEnum.md} +0 -0
- /package/examples/vitepress/docs/{Miscellaneous/apexdocs.ParentInterface.md → miscellaneous/ParentInterface.md} +0 -0
- /package/examples/vitepress/docs/{Miscellaneous/apexdocs.ReferencedEnum.md → miscellaneous/ReferencedEnum.md} +0 -0
package/dist/cli/generate.js
CHANGED
|
@@ -9,6 +9,7 @@ var apexReflection = require('@cparra/apex-reflection');
|
|
|
9
9
|
var O = require('fp-ts/Option');
|
|
10
10
|
var fastXmlParser = require('fast-xml-parser');
|
|
11
11
|
var Handlebars = require('handlebars');
|
|
12
|
+
var defaults = require('../defaults-DUwru49Q.js');
|
|
12
13
|
var fs = require('fs');
|
|
13
14
|
var path = require('path');
|
|
14
15
|
var chalk = require('chalk');
|
|
@@ -16,7 +17,6 @@ var logUpdate = require('log-update');
|
|
|
16
17
|
var cosmiconfig = require('cosmiconfig');
|
|
17
18
|
var yargs = require('yargs');
|
|
18
19
|
var cosmiconfigTypescriptLoader = require('cosmiconfig-typescript-loader');
|
|
19
|
-
var defaults = require('../defaults-DUwru49Q.js');
|
|
20
20
|
|
|
21
21
|
function _interopNamespaceDefault(e) {
|
|
22
22
|
var n = Object.create(null);
|
|
@@ -425,7 +425,7 @@ function typeToRenderable(parsedFile, linkGenerator, config) {
|
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
return __spreadProps$d(__spreadValues$d({}, getRenderable()), {
|
|
428
|
-
filePath: parsedFile.filePath,
|
|
428
|
+
filePath: parsedFile.source.filePath,
|
|
429
429
|
namespace: config.namespace
|
|
430
430
|
});
|
|
431
431
|
}
|
|
@@ -569,116 +569,53 @@ function singleGroup(headingLevel, groupName, adapter, members, linkGenerator) {
|
|
|
569
569
|
};
|
|
570
570
|
}
|
|
571
571
|
|
|
572
|
-
function parsedFilesToRenderableBundle(config, parsedFiles) {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
);
|
|
585
|
-
},
|
|
586
|
-
config
|
|
587
|
-
);
|
|
588
|
-
acc.renderables.push(renderable);
|
|
589
|
-
const descriptionLines = (_a = parsedFile.type.docComment) == null ? void 0 : _a.descriptionLines;
|
|
590
|
-
const reference = {
|
|
591
|
-
typeName: parsedFile.type.name,
|
|
592
|
-
directory: getDirectoryFromRoot(config, parsedFile.type),
|
|
593
|
-
title: getLinkFromRoot(config, parsedFile.type),
|
|
594
|
-
description: adaptDescribable(
|
|
595
|
-
descriptionLines,
|
|
596
|
-
(referenceName) => getPossibleLinkFromRoot(
|
|
597
|
-
config,
|
|
598
|
-
referenceName,
|
|
599
|
-
findType(
|
|
600
|
-
parsedFiles.map((file) => file.type),
|
|
601
|
-
referenceName
|
|
602
|
-
)
|
|
603
|
-
)
|
|
604
|
-
).description
|
|
605
|
-
};
|
|
606
|
-
const group = getTypeGroup(parsedFile.type, config);
|
|
607
|
-
if (!acc.references[group]) {
|
|
608
|
-
acc.references[group] = [];
|
|
609
|
-
}
|
|
610
|
-
acc.references[group].push(reference);
|
|
572
|
+
function parsedFilesToRenderableBundle(config, parsedFiles, references) {
|
|
573
|
+
const referenceFinder = apply(linkGenerator, references);
|
|
574
|
+
function toReferenceGuide(parsedFiles2) {
|
|
575
|
+
return parsedFiles2.reduce(
|
|
576
|
+
addToReferenceGuide(referenceFinder, config, references),
|
|
577
|
+
{}
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
function toRenderables(parsedFiles2) {
|
|
581
|
+
return parsedFiles2.reduce((acc, parsedFile) => {
|
|
582
|
+
const renderable = typeToRenderable(parsedFile, referenceFinder, config);
|
|
583
|
+
acc.push(renderable);
|
|
611
584
|
return acc;
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
references: {},
|
|
615
|
-
renderables: []
|
|
616
|
-
}
|
|
617
|
-
);
|
|
618
|
-
}
|
|
619
|
-
function linkFromTypeNameGenerator(typeBeingDocumented, repository, referenceName, config) {
|
|
620
|
-
const type = findType(repository, referenceName);
|
|
621
|
-
if (!type) {
|
|
622
|
-
return referenceName;
|
|
585
|
+
}, []);
|
|
623
586
|
}
|
|
624
|
-
const [fullClassName, fileLink] = getFileLinkTuple(typeBeingDocumented, type, config);
|
|
625
587
|
return {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
url: fileLink
|
|
588
|
+
referencesByGroup: toReferenceGuide(parsedFiles),
|
|
589
|
+
renderables: toRenderables(parsedFiles)
|
|
629
590
|
};
|
|
630
591
|
}
|
|
631
|
-
function
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
592
|
+
function addToReferenceGuide(findLinkFromHome, config, references) {
|
|
593
|
+
return (acc, parsedFile) => {
|
|
594
|
+
var _a, _b;
|
|
595
|
+
const group = getTypeGroup$1(parsedFile.type, config);
|
|
596
|
+
if (!acc[group]) {
|
|
597
|
+
acc[group] = [];
|
|
598
|
+
}
|
|
599
|
+
acc[group].push({
|
|
600
|
+
reference: references[parsedFile.type.name],
|
|
601
|
+
title: findLinkFromHome(parsedFile.type.name),
|
|
602
|
+
description: (_b = adaptDescribable((_a = parsedFile.type.docComment) == null ? void 0 : _a.descriptionLines, findLinkFromHome).description) != null ? _b : null
|
|
603
|
+
});
|
|
604
|
+
return acc;
|
|
641
605
|
};
|
|
642
606
|
}
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
}
|
|
652
|
-
function getFileLinkTuple(typeBeingDocumented, referencedType, config) {
|
|
653
|
-
const namespacePrefix = config.namespace ? `${config.namespace}.` : "";
|
|
654
|
-
const directoryRoot = `${getDirectoryRoot(typeBeingDocumented, referencedType, config)}`;
|
|
655
|
-
const fullClassName = `${namespacePrefix}${referencedType.name}`;
|
|
656
|
-
return [fullClassName, `${directoryRoot}${fullClassName}.md`];
|
|
657
|
-
}
|
|
658
|
-
function getDirectoryRoot(typeBeingDocumented, referencedType, config) {
|
|
659
|
-
if (getTypeGroup(typeBeingDocumented, config) === getTypeGroup(referencedType, config)) {
|
|
660
|
-
return "./";
|
|
661
|
-
} else {
|
|
662
|
-
return `../${getSanitizedGroup(referencedType, config)}/`;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
function getTypeGroup(type, config) {
|
|
607
|
+
const linkGenerator = (references, referenceName) => {
|
|
608
|
+
const reference = references[referenceName];
|
|
609
|
+
return reference ? (
|
|
610
|
+
// Starting the path with a "/" will ensure the link will always be relative to the root of the site.
|
|
611
|
+
{ __type: "link", title: reference.displayName, url: `/${reference.pathFromRoot}` }
|
|
612
|
+
) : referenceName;
|
|
613
|
+
};
|
|
614
|
+
function getTypeGroup$1(type, config) {
|
|
666
615
|
var _a, _b;
|
|
667
616
|
const groupAnnotation = (_a = type.docComment) == null ? void 0 : _a.annotations.find((annotation) => annotation.name.toLowerCase() === "group");
|
|
668
617
|
return (_b = groupAnnotation == null ? void 0 : groupAnnotation.body) != null ? _b : config.defaultGroupName;
|
|
669
618
|
}
|
|
670
|
-
function getSanitizedGroup(classModel, config) {
|
|
671
|
-
return getTypeGroup(classModel, config).replace(/ /g, "-").replace(".", "");
|
|
672
|
-
}
|
|
673
|
-
function getLinkFromRoot(config, type) {
|
|
674
|
-
const namespacePrefix = config.namespace ? `${config.namespace}.` : "";
|
|
675
|
-
const title = `${namespacePrefix}${type.name}`;
|
|
676
|
-
return {
|
|
677
|
-
__type: "link",
|
|
678
|
-
title,
|
|
679
|
-
url: `${getDirectoryFromRoot(config, type)}/${title}.md`
|
|
680
|
-
};
|
|
681
|
-
}
|
|
682
619
|
|
|
683
620
|
function parseApexMetadata(input) {
|
|
684
621
|
var _a;
|
|
@@ -730,7 +667,11 @@ function reflectSourceBody(apexBundle) {
|
|
|
730
667
|
const { filePath, content: input, metadataContent: metadata } = apexBundle;
|
|
731
668
|
const result = apexReflection.reflect(input);
|
|
732
669
|
return result.error ? E__namespace.left(new ReflectionError(filePath, result.error.message)) : E__namespace.right({
|
|
733
|
-
|
|
670
|
+
source: {
|
|
671
|
+
filePath,
|
|
672
|
+
name: result.typeMirror.name,
|
|
673
|
+
type: result.typeMirror.type_name
|
|
674
|
+
},
|
|
734
675
|
type: addFileMetadataToTypeAnnotation(result.typeMirror, metadata)
|
|
735
676
|
});
|
|
736
677
|
}
|
|
@@ -1249,15 +1190,15 @@ const link = (source) => {
|
|
|
1249
1190
|
}
|
|
1250
1191
|
};
|
|
1251
1192
|
|
|
1252
|
-
const convertToDocumentationBundle = (referenceGuideTemplate, {
|
|
1193
|
+
const convertToDocumentationBundle = (referenceGuideTemplate, { referencesByGroup, renderables }) => ({
|
|
1253
1194
|
referenceGuide: {
|
|
1254
|
-
directory: "",
|
|
1255
1195
|
frontmatter: null,
|
|
1256
|
-
content: referencesToReferenceGuideContent(
|
|
1257
|
-
|
|
1258
|
-
fileName: "index"
|
|
1196
|
+
content: referencesToReferenceGuideContent(referencesByGroup, referenceGuideTemplate),
|
|
1197
|
+
filePath: "index.md"
|
|
1259
1198
|
},
|
|
1260
|
-
docs: renderables.map(
|
|
1199
|
+
docs: renderables.map(
|
|
1200
|
+
(renderable) => renderableToPageData(Object.values(referencesByGroup).flat(), renderable)
|
|
1201
|
+
)
|
|
1261
1202
|
});
|
|
1262
1203
|
function referencesToReferenceGuideContent(references, template) {
|
|
1263
1204
|
function alphabetizeReferences(references2) {
|
|
@@ -1279,21 +1220,18 @@ function renderableToPageData(referenceGuideReference, renderable) {
|
|
|
1279
1220
|
function buildDocOutput(renderable2, docContents) {
|
|
1280
1221
|
var _a;
|
|
1281
1222
|
const reference = referenceGuideReference.find(
|
|
1282
|
-
(ref) => ref.
|
|
1223
|
+
(ref) => ref.reference.source.name.toLowerCase() === renderable2.name.toLowerCase()
|
|
1283
1224
|
);
|
|
1284
|
-
const namespacePrefix = renderable2.namespace ? `${renderable2.namespace}.` : "";
|
|
1285
1225
|
return {
|
|
1286
1226
|
source: {
|
|
1287
1227
|
filePath: renderable2.filePath,
|
|
1288
1228
|
name: renderable2.name,
|
|
1289
1229
|
type: renderable2.type
|
|
1290
1230
|
},
|
|
1291
|
-
|
|
1292
|
-
fileExtension: "md",
|
|
1293
|
-
directory: `${reference == null ? void 0 : reference.directory}`,
|
|
1231
|
+
filePath: reference.reference.pathFromRoot,
|
|
1294
1232
|
frontmatter: null,
|
|
1295
1233
|
content: docContents,
|
|
1296
|
-
group: (_a = renderable2.doc.group) != null ? _a :
|
|
1234
|
+
group: (_a = renderable2.doc.group) != null ? _a : defaults.defaults.defaultGroupName
|
|
1297
1235
|
};
|
|
1298
1236
|
}
|
|
1299
1237
|
return _function.pipe(renderable, resolveApexTypeTemplate, compile, (docContents) => buildDocOutput(renderable, docContents));
|
|
@@ -1501,6 +1439,28 @@ function isSkip(value) {
|
|
|
1501
1439
|
return Object.prototype.hasOwnProperty.call(value, "_tag") && value._tag === "Skip";
|
|
1502
1440
|
}
|
|
1503
1441
|
|
|
1442
|
+
function parsedFilesToReferenceGuide(config, parsedFiles) {
|
|
1443
|
+
return parsedFiles.reduce((acc, parsedFile) => {
|
|
1444
|
+
acc[parsedFile.type.name] = parsedFileToDocPageReference(config, parsedFile);
|
|
1445
|
+
return acc;
|
|
1446
|
+
}, {});
|
|
1447
|
+
}
|
|
1448
|
+
function parsedFileToDocPageReference(config, parsedFile) {
|
|
1449
|
+
return {
|
|
1450
|
+
source: parsedFile.source,
|
|
1451
|
+
displayName: parsedFile.type.name,
|
|
1452
|
+
pathFromRoot: `${slugify(getTypeGroup(parsedFile.type, config))}/${parsedFile.type.name}.md`
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
function getTypeGroup(type, config) {
|
|
1456
|
+
var _a, _b;
|
|
1457
|
+
const groupAnnotation = (_a = type.docComment) == null ? void 0 : _a.annotations.find((annotation) => annotation.name.toLowerCase() === "group");
|
|
1458
|
+
return (_b = groupAnnotation == null ? void 0 : groupAnnotation.body) != null ? _b : config.defaultGroupName;
|
|
1459
|
+
}
|
|
1460
|
+
function slugify(text) {
|
|
1461
|
+
return text.toLowerCase().replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1504
1464
|
var __defProp$7 = Object.defineProperty;
|
|
1505
1465
|
var __defProps$7 = Object.defineProperties;
|
|
1506
1466
|
var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
|
|
@@ -1548,6 +1508,7 @@ class HookError {
|
|
|
1548
1508
|
}
|
|
1549
1509
|
function generateDocs(apexBundles, config) {
|
|
1550
1510
|
const filterOutOfScope = apply(filterScope, config.scope);
|
|
1511
|
+
const convertToReferences = apply(parsedFilesToReferenceGuide, config);
|
|
1551
1512
|
const convertToRenderableBundle = apply(parsedFilesToRenderableBundle, config);
|
|
1552
1513
|
const convertToDocumentationBundleForTemplate = apply(convertToDocumentationBundle, config.referenceGuideTemplate);
|
|
1553
1514
|
const sortTypeMembers = apply(sortMembers, config.sortMembersAlphabetically);
|
|
@@ -1559,52 +1520,50 @@ function generateDocs(apexBundles, config) {
|
|
|
1559
1520
|
E__namespace.map(addInheritedMembersToTypes),
|
|
1560
1521
|
E__namespace.map(addInheritanceChainToTypes),
|
|
1561
1522
|
E__namespace.map(sortTypeMembers),
|
|
1562
|
-
E__namespace.
|
|
1563
|
-
E__namespace.
|
|
1523
|
+
E__namespace.bindTo("parsedFiles"),
|
|
1524
|
+
E__namespace.bind("references", ({ parsedFiles }) => E__namespace.right(convertToReferences(parsedFiles))),
|
|
1564
1525
|
TE__namespace.fromEither,
|
|
1565
|
-
TE__namespace.flatMap(
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
),
|
|
1571
|
-
TE__namespace.map((bundle) => ({
|
|
1572
|
-
referenceGuide: isSkip(bundle.referenceGuide) ? bundle.referenceGuide : __spreadProps$7(__spreadValues$7({}, bundle.referenceGuide), {
|
|
1573
|
-
content: Template.getInstance().compile({
|
|
1574
|
-
source: {
|
|
1575
|
-
frontmatter: toFrontmatterString(bundle.referenceGuide.frontmatter),
|
|
1576
|
-
content: bundle.referenceGuide.content
|
|
1577
|
-
},
|
|
1578
|
-
template: hookableTemplate
|
|
1579
|
-
})
|
|
1580
|
-
}),
|
|
1581
|
-
docs: bundle.docs.map((doc) => __spreadProps$7(__spreadValues$7({}, doc), {
|
|
1582
|
-
content: Template.getInstance().compile({
|
|
1583
|
-
source: {
|
|
1584
|
-
frontmatter: toFrontmatterString(doc.frontmatter),
|
|
1585
|
-
content: doc.content
|
|
1586
|
-
},
|
|
1587
|
-
template: hookableTemplate
|
|
1588
|
-
})
|
|
1589
|
-
}))
|
|
1590
|
-
}))
|
|
1526
|
+
TE__namespace.flatMap(({ parsedFiles, references }) => transformReferenceHook(config)({ references, parsedFiles })),
|
|
1527
|
+
TE__namespace.map(({ parsedFiles, references }) => convertToRenderableBundle(parsedFiles, references)),
|
|
1528
|
+
TE__namespace.map(convertToDocumentationBundleForTemplate),
|
|
1529
|
+
TE__namespace.flatMap(transformDocumentationBundleHook(config)),
|
|
1530
|
+
TE__namespace.map(postHookCompile)
|
|
1591
1531
|
);
|
|
1592
1532
|
}
|
|
1593
|
-
function
|
|
1594
|
-
|
|
1595
|
-
return
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1533
|
+
function transformReferenceHook(config) {
|
|
1534
|
+
function _execute(references, parsedFiles, transformReference) {
|
|
1535
|
+
return __async$2(this, null, function* () {
|
|
1536
|
+
return {
|
|
1537
|
+
references: yield execTransformReferenceHook(Object.values(references), transformReference),
|
|
1538
|
+
parsedFiles
|
|
1539
|
+
};
|
|
1540
|
+
});
|
|
1599
1541
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1542
|
+
return ({ references, parsedFiles }) => TE__namespace.tryCatch(
|
|
1543
|
+
() => _execute(references, parsedFiles, config.transformReference),
|
|
1544
|
+
(error) => new HookError(error)
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1547
|
+
function transformDocumentationBundleHook(config) {
|
|
1548
|
+
return (bundle) => TE__namespace.tryCatch(
|
|
1549
|
+
() => documentationBundleHook(bundle, config),
|
|
1550
|
+
(error) => new HookError(error)
|
|
1551
|
+
);
|
|
1604
1552
|
}
|
|
1605
1553
|
function passThroughHook(value) {
|
|
1606
1554
|
return value;
|
|
1607
1555
|
}
|
|
1556
|
+
const execTransformReferenceHook = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (references, hook = passThroughHook) {
|
|
1557
|
+
const hooked = references.map((reference) => __async$2(void 0, null, function* () {
|
|
1558
|
+
const hookedResult = yield hook(reference);
|
|
1559
|
+
return __spreadValues$7(__spreadValues$7({}, reference), hookedResult);
|
|
1560
|
+
}));
|
|
1561
|
+
const awaited = yield Promise.all(hooked);
|
|
1562
|
+
return awaited.reduce((acc, reference) => {
|
|
1563
|
+
acc[reference.source.name] = reference;
|
|
1564
|
+
return acc;
|
|
1565
|
+
}, {});
|
|
1566
|
+
});
|
|
1608
1567
|
const documentationBundleHook = (bundle, config) => __async$2(void 0, null, function* () {
|
|
1609
1568
|
return {
|
|
1610
1569
|
referenceGuide: yield transformReferenceGuide(bundle.referenceGuide, config.transformReferenceGuide),
|
|
@@ -1625,6 +1584,40 @@ const transformDocs = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (d
|
|
|
1625
1584
|
const transformDocPage = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (doc, hook = passThroughHook) {
|
|
1626
1585
|
return __spreadValues$7(__spreadValues$7({}, doc), yield hook(doc));
|
|
1627
1586
|
});
|
|
1587
|
+
function postHookCompile(bundle) {
|
|
1588
|
+
return {
|
|
1589
|
+
referenceGuide: isSkip(bundle.referenceGuide) ? bundle.referenceGuide : __spreadProps$7(__spreadValues$7({}, bundle.referenceGuide), {
|
|
1590
|
+
content: Template.getInstance().compile({
|
|
1591
|
+
source: {
|
|
1592
|
+
frontmatter: toFrontmatterString(bundle.referenceGuide.frontmatter),
|
|
1593
|
+
content: bundle.referenceGuide.content
|
|
1594
|
+
},
|
|
1595
|
+
template: hookableTemplate
|
|
1596
|
+
})
|
|
1597
|
+
}),
|
|
1598
|
+
docs: bundle.docs.map((doc) => __spreadProps$7(__spreadValues$7({}, doc), {
|
|
1599
|
+
content: Template.getInstance().compile({
|
|
1600
|
+
source: {
|
|
1601
|
+
frontmatter: toFrontmatterString(doc.frontmatter),
|
|
1602
|
+
content: doc.content
|
|
1603
|
+
},
|
|
1604
|
+
template: hookableTemplate
|
|
1605
|
+
})
|
|
1606
|
+
}))
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
function toFrontmatterString(frontmatter) {
|
|
1610
|
+
if (typeof frontmatter === "string") {
|
|
1611
|
+
return frontmatter;
|
|
1612
|
+
}
|
|
1613
|
+
if (!frontmatter) {
|
|
1614
|
+
return "";
|
|
1615
|
+
}
|
|
1616
|
+
const yamlString = yaml.dump(frontmatter);
|
|
1617
|
+
return `---
|
|
1618
|
+
${yamlString}---
|
|
1619
|
+
`;
|
|
1620
|
+
}
|
|
1628
1621
|
|
|
1629
1622
|
var __defProp$6 = Object.defineProperty;
|
|
1630
1623
|
var __defProps$6 = Object.defineProperties;
|
|
@@ -1648,18 +1641,15 @@ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
|
1648
1641
|
class FileWriter {
|
|
1649
1642
|
static write(files, outputDir, onWriteCallback) {
|
|
1650
1643
|
files.forEach((file) => {
|
|
1651
|
-
const
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
const filePath = path__namespace.join(resolvedFile.directory, `${resolvedFile.fileName}.${resolvedFile.fileExtension}`);
|
|
1656
|
-
fs__namespace.writeFileSync(filePath, resolvedFile.content, "utf8");
|
|
1657
|
-
onWriteCallback(resolvedFile);
|
|
1644
|
+
const { filePath, content } = this.getTargetLocation(file, outputDir);
|
|
1645
|
+
fs__namespace.mkdirSync(path__namespace.dirname(filePath), { recursive: true });
|
|
1646
|
+
fs__namespace.writeFileSync(filePath, content, "utf8");
|
|
1647
|
+
onWriteCallback(file);
|
|
1658
1648
|
});
|
|
1659
1649
|
}
|
|
1660
1650
|
static getTargetLocation(file, outputDir) {
|
|
1661
1651
|
return __spreadProps$6(__spreadValues$6({}, file), {
|
|
1662
|
-
|
|
1652
|
+
filePath: path__namespace.join(outputDir, file.filePath)
|
|
1663
1653
|
});
|
|
1664
1654
|
}
|
|
1665
1655
|
}
|
|
@@ -1775,7 +1765,7 @@ function writeFilesToSystem(files, outputDir) {
|
|
|
1775
1765
|
[files.referenceGuide, ...files.docs].filter((file) => !isSkip(file)),
|
|
1776
1766
|
outputDir,
|
|
1777
1767
|
(file) => {
|
|
1778
|
-
Logger.logSingle(`${file.
|
|
1768
|
+
Logger.logSingle(`${file.filePath} processed.`, false, "green", false);
|
|
1779
1769
|
}
|
|
1780
1770
|
);
|
|
1781
1771
|
}
|
|
@@ -2660,9 +2650,7 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
|
2660
2650
|
function createOpenApiFile(fileName, openApiModel) {
|
|
2661
2651
|
const content = JSON.stringify(__spreadProps$1(__spreadValues$1({}, openApiModel), { namespace: void 0 }), null, 2);
|
|
2662
2652
|
return {
|
|
2663
|
-
|
|
2664
|
-
fileName,
|
|
2665
|
-
directory: "",
|
|
2653
|
+
filePath: "",
|
|
2666
2654
|
content,
|
|
2667
2655
|
frontmatter: null,
|
|
2668
2656
|
group: null
|
|
@@ -2735,7 +2723,7 @@ function openApi(fileBodies, config) {
|
|
|
2735
2723
|
Transpiler.generate(filteredTypes, processor);
|
|
2736
2724
|
const generatedFiles = processor.fileBuilder().files();
|
|
2737
2725
|
FileWriter.write(generatedFiles, config.targetDir, (file) => {
|
|
2738
|
-
Logger.logSingle(`${file.
|
|
2726
|
+
Logger.logSingle(`${file.filePath} processed.`, false, "green", false);
|
|
2739
2727
|
});
|
|
2740
2728
|
ErrorLogger.logErrors(filteredTypes);
|
|
2741
2729
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { SetOptional } from 'type-fest';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The configurable hooks that can be used to modify the output of the generator.
|
|
5
|
+
*/
|
|
3
6
|
type ConfigurableHooks = {
|
|
4
7
|
transformReferenceGuide: TransformReferenceGuide;
|
|
5
8
|
transformDocs: TransformDocs;
|
|
6
9
|
transformDocPage: TransformDocPage;
|
|
10
|
+
transformReference: TransformReference;
|
|
7
11
|
};
|
|
8
12
|
|
|
9
13
|
type UserDefinedMarkdownConfig = {
|
|
@@ -17,46 +21,80 @@ type UserDefinedMarkdownConfig = {
|
|
|
17
21
|
includeMetadata: boolean;
|
|
18
22
|
} & Partial<ConfigurableHooks>;
|
|
19
23
|
|
|
24
|
+
type SourceFileMetadata = {
|
|
25
|
+
filePath: string;
|
|
26
|
+
name: string;
|
|
27
|
+
type: 'interface' | 'class' | 'enum';
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type DocPageReference = {
|
|
31
|
+
source: SourceFileMetadata;
|
|
32
|
+
// The name under which the type should be displayed in the documentation.
|
|
33
|
+
// By default, this will match the source.name, but it can be configured by the user.
|
|
34
|
+
displayName: string;
|
|
35
|
+
// The location of the file relative to the root of the documentation.
|
|
36
|
+
pathFromRoot: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
20
39
|
type Frontmatter = string | Record<string, unknown> | null;
|
|
21
40
|
|
|
22
41
|
type ReferenceGuidePageData = {
|
|
23
|
-
directory: string;
|
|
24
42
|
frontmatter: Frontmatter;
|
|
25
43
|
content: string;
|
|
26
|
-
|
|
27
|
-
fileName: string;
|
|
44
|
+
filePath: string;
|
|
28
45
|
};
|
|
29
46
|
|
|
30
47
|
type DocPageData = {
|
|
31
|
-
source:
|
|
32
|
-
filePath: string;
|
|
33
|
-
name: string;
|
|
34
|
-
type: 'interface' | 'class' | 'enum';
|
|
35
|
-
};
|
|
48
|
+
source: SourceFileMetadata;
|
|
36
49
|
group: string | null;
|
|
37
|
-
|
|
38
|
-
fileExtension: string;
|
|
39
|
-
directory: string;
|
|
50
|
+
filePath: string;
|
|
40
51
|
frontmatter: Frontmatter;
|
|
41
52
|
content: string;
|
|
42
53
|
};
|
|
43
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Represents a file to be skipped.
|
|
57
|
+
*/
|
|
44
58
|
type Skip = {
|
|
45
59
|
readonly _tag: 'Skip';
|
|
46
60
|
};
|
|
47
61
|
|
|
48
62
|
// Configurable Hooks
|
|
49
63
|
|
|
64
|
+
type ConfigurableDocPageReference = Omit<DocPageReference, 'source'>;
|
|
65
|
+
|
|
66
|
+
type ConfigurableDocPageData = Omit<DocPageData, 'source' | 'filePath'>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Allows changing where the files are written to.
|
|
70
|
+
*/
|
|
71
|
+
type TransformReference = (
|
|
72
|
+
reference: DocPageReference,
|
|
73
|
+
) => Partial<ConfigurableDocPageReference> | Promise<ConfigurableDocPageReference>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Allows changing the frontmatter and content of the reference guide, or even if creating a reference
|
|
77
|
+
* guide will be skipped altogether.
|
|
78
|
+
*/
|
|
50
79
|
type TransformReferenceGuide = (
|
|
51
80
|
referenceGuide: ReferenceGuidePageData,
|
|
52
81
|
) => Partial<ReferenceGuidePageData> | Skip | Promise<Partial<ReferenceGuidePageData> | Skip>;
|
|
53
82
|
|
|
83
|
+
/**
|
|
84
|
+
* The main purpose if for allowing for doc pages to be skipped, but it can also be used to change the frontmatter
|
|
85
|
+
* and content of the doc pages.
|
|
86
|
+
*/
|
|
54
87
|
type TransformDocs = (docs: DocPageData[]) => DocPageData[] | Promise<DocPageData[]>;
|
|
55
88
|
|
|
56
|
-
|
|
89
|
+
/**
|
|
90
|
+
* Allows changing the frontmatter and content of the doc pages.
|
|
91
|
+
*/
|
|
92
|
+
type TransformDocPage = (
|
|
93
|
+
doc: DocPageData,
|
|
94
|
+
) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>;
|
|
57
95
|
|
|
58
96
|
type ConfigurableMarkdownConfig = Omit<SetOptional<UserDefinedMarkdownConfig, 'targetDir' | 'scope' | 'defaultGroupName' | 'includeMetadata' | 'sortMembersAlphabetically'>, 'targetGenerator'>;
|
|
59
97
|
declare function defineMarkdownConfig(config: ConfigurableMarkdownConfig): UserDefinedMarkdownConfig;
|
|
60
98
|
declare function skip(): Skip;
|
|
61
99
|
|
|
62
|
-
export { type ConfigurableHooks, type DocPageData, type ReferenceGuidePageData, defineMarkdownConfig, skip };
|
|
100
|
+
export { type ConfigurableHooks, type DocPageData, type DocPageReference, type ReferenceGuidePageData, defineMarkdownConfig, skip };
|