@cparra/apexdocs 2.25.0-alpha.8 → 3.0.0-alpha.1
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 +167 -180
- package/dist/defaults-jLXD2y8-.js +13 -0
- package/dist/index.d.ts +53 -14
- package/dist/index.js +1 -1
- package/examples/{plain-markdown → markdown}/docs/index.md +25 -33
- package/examples/{plain-markdown/docs/Miscellaneous/ns.BaseClass.md → markdown/docs/miscellaneous/BaseClass.md} +1 -1
- package/examples/{plain-markdown/docs/Miscellaneous/ns.MultiInheritanceClass.md → markdown/docs/miscellaneous/MultiInheritanceClass.md} +5 -6
- package/examples/{plain-markdown/docs/Miscellaneous/ns.SampleException.md → markdown/docs/miscellaneous/SampleException.md} +3 -4
- package/examples/{plain-markdown/docs/Miscellaneous/ns.SampleInterface.md → markdown/docs/miscellaneous/SampleInterface.md} +22 -29
- package/examples/{plain-markdown/docs/Miscellaneous/ns.Url.md → markdown/docs/miscellaneous/Url.md} +32 -43
- package/examples/markdown/docs/sample-enums/SampleEnum.md +36 -0
- package/examples/{plain-markdown/docs/SampleGroup/ns.SampleClass.md → markdown/docs/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/cli/args.ts +1 -1
- package/src/cli/commands/markdown.ts +6 -12
- package/src/cli/generate.ts +3 -3
- 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 +4 -3
- package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +41 -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 +52 -118
- 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 +100 -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 +53 -14
- package/src/defaults.ts +1 -0
- package/src/index.ts +8 -2
- package/examples/plain-markdown/docs/Sample-Enums/ns.SampleEnum.md +0 -38
- /package/examples/{plain-markdown → markdown}/.forceignore +0 -0
- /package/examples/{plain-markdown → markdown}/config/project-scratch-def.json +0 -0
- /package/examples/{plain-markdown/docs/Miscellaneous/ns.ParentInterface.md → markdown/docs/miscellaneous/ParentInterface.md} +0 -0
- /package/examples/{plain-markdown/docs/Miscellaneous/ns.ReferencedEnum.md → markdown/docs/miscellaneous/ReferencedEnum.md} +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/BaseClass.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/MultiInheritanceClass.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/ParentInterface.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/ReferencedEnum.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/SampleClass.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/SampleEnum.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/SampleException.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/SampleInterface.cls +0 -0
- /package/examples/{plain-markdown → markdown}/force-app/classes/Url.cls +0 -0
- /package/examples/{plain-markdown → markdown}/package-lock.json +0 -0
- /package/examples/{plain-markdown → markdown}/package.json +0 -0
- /package/examples/{plain-markdown → markdown}/sfdx-project.json +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
|
@@ -5,18 +5,18 @@ var _function = require('fp-ts/function');
|
|
|
5
5
|
var E = require('fp-ts/Either');
|
|
6
6
|
var TE = require('fp-ts/TaskEither');
|
|
7
7
|
var yaml = require('js-yaml');
|
|
8
|
+
var path = require('path');
|
|
8
9
|
var apexReflection = require('@cparra/apex-reflection');
|
|
9
10
|
var O = require('fp-ts/Option');
|
|
10
11
|
var fastXmlParser = require('fast-xml-parser');
|
|
11
12
|
var Handlebars = require('handlebars');
|
|
13
|
+
var defaults = require('../defaults-jLXD2y8-.js');
|
|
12
14
|
var fs = require('fs');
|
|
13
|
-
var path = require('path');
|
|
14
15
|
var chalk = require('chalk');
|
|
15
16
|
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);
|
|
@@ -38,9 +38,9 @@ function _interopNamespaceDefault(e) {
|
|
|
38
38
|
var E__namespace = /*#__PURE__*/_interopNamespaceDefault(E);
|
|
39
39
|
var TE__namespace = /*#__PURE__*/_interopNamespaceDefault(TE);
|
|
40
40
|
var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
|
|
41
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
41
42
|
var O__namespace = /*#__PURE__*/_interopNamespaceDefault(O);
|
|
42
43
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
43
|
-
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
44
44
|
var yargs__namespace = /*#__PURE__*/_interopNamespaceDefault(yargs);
|
|
45
45
|
|
|
46
46
|
function apply(fn, ...front) {
|
|
@@ -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,57 @@ 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, config.documentationRootDir);
|
|
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
|
-
|
|
653
|
-
|
|
654
|
-
|
|
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, documentationRootDir, 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
|
+
{
|
|
612
|
+
__type: "link",
|
|
613
|
+
title: reference.displayName,
|
|
614
|
+
url: path__namespace.join("/", documentationRootDir, reference.pathFromRoot)
|
|
615
|
+
}
|
|
616
|
+
) : referenceName;
|
|
617
|
+
};
|
|
618
|
+
function getTypeGroup$1(type, config) {
|
|
666
619
|
var _a, _b;
|
|
667
620
|
const groupAnnotation = (_a = type.docComment) == null ? void 0 : _a.annotations.find((annotation) => annotation.name.toLowerCase() === "group");
|
|
668
621
|
return (_b = groupAnnotation == null ? void 0 : groupAnnotation.body) != null ? _b : config.defaultGroupName;
|
|
669
622
|
}
|
|
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
623
|
|
|
683
624
|
function parseApexMetadata(input) {
|
|
684
625
|
var _a;
|
|
@@ -730,7 +671,11 @@ function reflectSourceBody(apexBundle) {
|
|
|
730
671
|
const { filePath, content: input, metadataContent: metadata } = apexBundle;
|
|
731
672
|
const result = apexReflection.reflect(input);
|
|
732
673
|
return result.error ? E__namespace.left(new ReflectionError(filePath, result.error.message)) : E__namespace.right({
|
|
733
|
-
|
|
674
|
+
source: {
|
|
675
|
+
filePath,
|
|
676
|
+
name: result.typeMirror.name,
|
|
677
|
+
type: result.typeMirror.type_name
|
|
678
|
+
},
|
|
734
679
|
type: addFileMetadataToTypeAnnotation(result.typeMirror, metadata)
|
|
735
680
|
});
|
|
736
681
|
}
|
|
@@ -1249,15 +1194,15 @@ const link = (source) => {
|
|
|
1249
1194
|
}
|
|
1250
1195
|
};
|
|
1251
1196
|
|
|
1252
|
-
const convertToDocumentationBundle = (referenceGuideTemplate, {
|
|
1197
|
+
const convertToDocumentationBundle = (referenceGuideTemplate, { referencesByGroup, renderables }) => ({
|
|
1253
1198
|
referenceGuide: {
|
|
1254
|
-
directory: "",
|
|
1255
1199
|
frontmatter: null,
|
|
1256
|
-
content: referencesToReferenceGuideContent(
|
|
1257
|
-
|
|
1258
|
-
fileName: "index"
|
|
1200
|
+
content: referencesToReferenceGuideContent(referencesByGroup, referenceGuideTemplate),
|
|
1201
|
+
filePath: "index.md"
|
|
1259
1202
|
},
|
|
1260
|
-
docs: renderables.map(
|
|
1203
|
+
docs: renderables.map(
|
|
1204
|
+
(renderable) => renderableToPageData(Object.values(referencesByGroup).flat(), renderable)
|
|
1205
|
+
)
|
|
1261
1206
|
});
|
|
1262
1207
|
function referencesToReferenceGuideContent(references, template) {
|
|
1263
1208
|
function alphabetizeReferences(references2) {
|
|
@@ -1279,21 +1224,18 @@ function renderableToPageData(referenceGuideReference, renderable) {
|
|
|
1279
1224
|
function buildDocOutput(renderable2, docContents) {
|
|
1280
1225
|
var _a;
|
|
1281
1226
|
const reference = referenceGuideReference.find(
|
|
1282
|
-
(ref) => ref.
|
|
1227
|
+
(ref) => ref.reference.source.name.toLowerCase() === renderable2.name.toLowerCase()
|
|
1283
1228
|
);
|
|
1284
|
-
const namespacePrefix = renderable2.namespace ? `${renderable2.namespace}.` : "";
|
|
1285
1229
|
return {
|
|
1286
1230
|
source: {
|
|
1287
1231
|
filePath: renderable2.filePath,
|
|
1288
1232
|
name: renderable2.name,
|
|
1289
1233
|
type: renderable2.type
|
|
1290
1234
|
},
|
|
1291
|
-
|
|
1292
|
-
fileExtension: "md",
|
|
1293
|
-
directory: `${reference == null ? void 0 : reference.directory}`,
|
|
1235
|
+
filePath: reference.reference.pathFromRoot,
|
|
1294
1236
|
frontmatter: null,
|
|
1295
1237
|
content: docContents,
|
|
1296
|
-
group: (_a = renderable2.doc.group) != null ? _a :
|
|
1238
|
+
group: (_a = renderable2.doc.group) != null ? _a : defaults.defaults.defaultGroupName
|
|
1297
1239
|
};
|
|
1298
1240
|
}
|
|
1299
1241
|
return _function.pipe(renderable, resolveApexTypeTemplate, compile, (docContents) => buildDocOutput(renderable, docContents));
|
|
@@ -1501,6 +1443,28 @@ function isSkip(value) {
|
|
|
1501
1443
|
return Object.prototype.hasOwnProperty.call(value, "_tag") && value._tag === "Skip";
|
|
1502
1444
|
}
|
|
1503
1445
|
|
|
1446
|
+
function parsedFilesToReferenceGuide(config, parsedFiles) {
|
|
1447
|
+
return parsedFiles.reduce((acc, parsedFile) => {
|
|
1448
|
+
acc[parsedFile.type.name] = parsedFileToDocPageReference(config, parsedFile);
|
|
1449
|
+
return acc;
|
|
1450
|
+
}, {});
|
|
1451
|
+
}
|
|
1452
|
+
function parsedFileToDocPageReference(config, parsedFile) {
|
|
1453
|
+
return {
|
|
1454
|
+
source: parsedFile.source,
|
|
1455
|
+
displayName: parsedFile.type.name,
|
|
1456
|
+
pathFromRoot: `${slugify(getTypeGroup(parsedFile.type, config))}/${parsedFile.type.name}.md`
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
function getTypeGroup(type, config) {
|
|
1460
|
+
var _a, _b;
|
|
1461
|
+
const groupAnnotation = (_a = type.docComment) == null ? void 0 : _a.annotations.find((annotation) => annotation.name.toLowerCase() === "group");
|
|
1462
|
+
return (_b = groupAnnotation == null ? void 0 : groupAnnotation.body) != null ? _b : config.defaultGroupName;
|
|
1463
|
+
}
|
|
1464
|
+
function slugify(text) {
|
|
1465
|
+
return text.toLowerCase().replace(/[^a-z0-9\s-]/g, "").trim().replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1504
1468
|
var __defProp$7 = Object.defineProperty;
|
|
1505
1469
|
var __defProps$7 = Object.defineProperties;
|
|
1506
1470
|
var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
|
|
@@ -1548,6 +1512,7 @@ class HookError {
|
|
|
1548
1512
|
}
|
|
1549
1513
|
function generateDocs(apexBundles, config) {
|
|
1550
1514
|
const filterOutOfScope = apply(filterScope, config.scope);
|
|
1515
|
+
const convertToReferences = apply(parsedFilesToReferenceGuide, config);
|
|
1551
1516
|
const convertToRenderableBundle = apply(parsedFilesToRenderableBundle, config);
|
|
1552
1517
|
const convertToDocumentationBundleForTemplate = apply(convertToDocumentationBundle, config.referenceGuideTemplate);
|
|
1553
1518
|
const sortTypeMembers = apply(sortMembers, config.sortMembersAlphabetically);
|
|
@@ -1559,52 +1524,50 @@ function generateDocs(apexBundles, config) {
|
|
|
1559
1524
|
E__namespace.map(addInheritedMembersToTypes),
|
|
1560
1525
|
E__namespace.map(addInheritanceChainToTypes),
|
|
1561
1526
|
E__namespace.map(sortTypeMembers),
|
|
1562
|
-
E__namespace.
|
|
1563
|
-
E__namespace.
|
|
1527
|
+
E__namespace.bindTo("parsedFiles"),
|
|
1528
|
+
E__namespace.bind("references", ({ parsedFiles }) => E__namespace.right(convertToReferences(parsedFiles))),
|
|
1564
1529
|
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
|
-
}))
|
|
1530
|
+
TE__namespace.flatMap(({ parsedFiles, references }) => transformReferenceHook(config)({ references, parsedFiles })),
|
|
1531
|
+
TE__namespace.map(({ parsedFiles, references }) => convertToRenderableBundle(parsedFiles, references)),
|
|
1532
|
+
TE__namespace.map(convertToDocumentationBundleForTemplate),
|
|
1533
|
+
TE__namespace.flatMap(transformDocumentationBundleHook(config)),
|
|
1534
|
+
TE__namespace.map(postHookCompile)
|
|
1591
1535
|
);
|
|
1592
1536
|
}
|
|
1593
|
-
function
|
|
1594
|
-
|
|
1595
|
-
return
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1537
|
+
function transformReferenceHook(config) {
|
|
1538
|
+
function _execute(references, parsedFiles, transformReference) {
|
|
1539
|
+
return __async$2(this, null, function* () {
|
|
1540
|
+
return {
|
|
1541
|
+
references: yield execTransformReferenceHook(Object.values(references), transformReference),
|
|
1542
|
+
parsedFiles
|
|
1543
|
+
};
|
|
1544
|
+
});
|
|
1599
1545
|
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1546
|
+
return ({ references, parsedFiles }) => TE__namespace.tryCatch(
|
|
1547
|
+
() => _execute(references, parsedFiles, config.transformReference),
|
|
1548
|
+
(error) => new HookError(error)
|
|
1549
|
+
);
|
|
1550
|
+
}
|
|
1551
|
+
function transformDocumentationBundleHook(config) {
|
|
1552
|
+
return (bundle) => TE__namespace.tryCatch(
|
|
1553
|
+
() => documentationBundleHook(bundle, config),
|
|
1554
|
+
(error) => new HookError(error)
|
|
1555
|
+
);
|
|
1604
1556
|
}
|
|
1605
1557
|
function passThroughHook(value) {
|
|
1606
1558
|
return value;
|
|
1607
1559
|
}
|
|
1560
|
+
const execTransformReferenceHook = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (references, hook = passThroughHook) {
|
|
1561
|
+
const hooked = references.map((reference) => __async$2(void 0, null, function* () {
|
|
1562
|
+
const hookedResult = yield hook(reference);
|
|
1563
|
+
return __spreadValues$7(__spreadValues$7({}, reference), hookedResult);
|
|
1564
|
+
}));
|
|
1565
|
+
const awaited = yield Promise.all(hooked);
|
|
1566
|
+
return awaited.reduce((acc, reference) => {
|
|
1567
|
+
acc[reference.source.name] = reference;
|
|
1568
|
+
return acc;
|
|
1569
|
+
}, {});
|
|
1570
|
+
});
|
|
1608
1571
|
const documentationBundleHook = (bundle, config) => __async$2(void 0, null, function* () {
|
|
1609
1572
|
return {
|
|
1610
1573
|
referenceGuide: yield transformReferenceGuide(bundle.referenceGuide, config.transformReferenceGuide),
|
|
@@ -1625,6 +1588,40 @@ const transformDocs = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (d
|
|
|
1625
1588
|
const transformDocPage = (_0, ..._1) => __async$2(void 0, [_0, ..._1], function* (doc, hook = passThroughHook) {
|
|
1626
1589
|
return __spreadValues$7(__spreadValues$7({}, doc), yield hook(doc));
|
|
1627
1590
|
});
|
|
1591
|
+
function postHookCompile(bundle) {
|
|
1592
|
+
return {
|
|
1593
|
+
referenceGuide: isSkip(bundle.referenceGuide) ? bundle.referenceGuide : __spreadProps$7(__spreadValues$7({}, bundle.referenceGuide), {
|
|
1594
|
+
content: Template.getInstance().compile({
|
|
1595
|
+
source: {
|
|
1596
|
+
frontmatter: toFrontmatterString(bundle.referenceGuide.frontmatter),
|
|
1597
|
+
content: bundle.referenceGuide.content
|
|
1598
|
+
},
|
|
1599
|
+
template: hookableTemplate
|
|
1600
|
+
})
|
|
1601
|
+
}),
|
|
1602
|
+
docs: bundle.docs.map((doc) => __spreadProps$7(__spreadValues$7({}, doc), {
|
|
1603
|
+
content: Template.getInstance().compile({
|
|
1604
|
+
source: {
|
|
1605
|
+
frontmatter: toFrontmatterString(doc.frontmatter),
|
|
1606
|
+
content: doc.content
|
|
1607
|
+
},
|
|
1608
|
+
template: hookableTemplate
|
|
1609
|
+
})
|
|
1610
|
+
}))
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function toFrontmatterString(frontmatter) {
|
|
1614
|
+
if (typeof frontmatter === "string") {
|
|
1615
|
+
return frontmatter;
|
|
1616
|
+
}
|
|
1617
|
+
if (!frontmatter) {
|
|
1618
|
+
return "";
|
|
1619
|
+
}
|
|
1620
|
+
const yamlString = yaml.dump(frontmatter);
|
|
1621
|
+
return `---
|
|
1622
|
+
${yamlString}---
|
|
1623
|
+
`;
|
|
1624
|
+
}
|
|
1628
1625
|
|
|
1629
1626
|
var __defProp$6 = Object.defineProperty;
|
|
1630
1627
|
var __defProps$6 = Object.defineProperties;
|
|
@@ -1648,18 +1645,15 @@ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
|
1648
1645
|
class FileWriter {
|
|
1649
1646
|
static write(files, outputDir, onWriteCallback) {
|
|
1650
1647
|
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);
|
|
1648
|
+
const { filePath, content } = this.getTargetLocation(file, outputDir);
|
|
1649
|
+
fs__namespace.mkdirSync(path__namespace.dirname(filePath), { recursive: true });
|
|
1650
|
+
fs__namespace.writeFileSync(filePath, content, "utf8");
|
|
1651
|
+
onWriteCallback(file);
|
|
1658
1652
|
});
|
|
1659
1653
|
}
|
|
1660
1654
|
static getTargetLocation(file, outputDir) {
|
|
1661
1655
|
return __spreadProps$6(__spreadValues$6({}, file), {
|
|
1662
|
-
|
|
1656
|
+
filePath: path__namespace.join(outputDir, file.filePath)
|
|
1663
1657
|
});
|
|
1664
1658
|
}
|
|
1665
1659
|
}
|
|
@@ -1775,7 +1769,7 @@ function writeFilesToSystem(files, outputDir) {
|
|
|
1775
1769
|
[files.referenceGuide, ...files.docs].filter((file) => !isSkip(file)),
|
|
1776
1770
|
outputDir,
|
|
1777
1771
|
(file) => {
|
|
1778
|
-
Logger.logSingle(`${file.
|
|
1772
|
+
Logger.logSingle(`${file.filePath} processed.`, false, "green", false);
|
|
1779
1773
|
}
|
|
1780
1774
|
);
|
|
1781
1775
|
}
|
|
@@ -2660,9 +2654,7 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
|
2660
2654
|
function createOpenApiFile(fileName, openApiModel) {
|
|
2661
2655
|
const content = JSON.stringify(__spreadProps$1(__spreadValues$1({}, openApiModel), { namespace: void 0 }), null, 2);
|
|
2662
2656
|
return {
|
|
2663
|
-
|
|
2664
|
-
fileName,
|
|
2665
|
-
directory: "",
|
|
2657
|
+
filePath: "",
|
|
2666
2658
|
content,
|
|
2667
2659
|
frontmatter: null,
|
|
2668
2660
|
group: null
|
|
@@ -2735,7 +2727,7 @@ function openApi(fileBodies, config) {
|
|
|
2735
2727
|
Transpiler.generate(filteredTypes, processor);
|
|
2736
2728
|
const generatedFiles = processor.fileBuilder().files();
|
|
2737
2729
|
FileWriter.write(generatedFiles, config.targetDir, (file) => {
|
|
2738
|
-
Logger.logSingle(`${file.
|
|
2730
|
+
Logger.logSingle(`${file.filePath} processed.`, false, "green", false);
|
|
2739
2731
|
});
|
|
2740
2732
|
ErrorLogger.logErrors(filteredTypes);
|
|
2741
2733
|
}
|
|
@@ -2871,27 +2863,17 @@ const markdownOptions = {
|
|
|
2871
2863
|
array: true,
|
|
2872
2864
|
alias: "p",
|
|
2873
2865
|
default: defaults.defaults.scope,
|
|
2874
|
-
describe: "A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled.
|
|
2866
|
+
describe: "A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. Annotations are supported and should be passed lowercased and without the @ symbol, e.g. namespaceaccessible auraenabled."
|
|
2875
2867
|
},
|
|
2876
2868
|
defaultGroupName: {
|
|
2877
2869
|
type: "string",
|
|
2878
2870
|
default: defaults.defaults.defaultGroupName,
|
|
2879
2871
|
describe: "Defines the @group name to be used when a file does not specify it."
|
|
2880
2872
|
},
|
|
2881
|
-
openApiTitle: {
|
|
2882
|
-
type: "string",
|
|
2883
|
-
default: "Apex REST Api",
|
|
2884
|
-
describe: 'If using "openapi" as the target generator, this allows you to specify the OpenApi title value.'
|
|
2885
|
-
},
|
|
2886
2873
|
namespace: {
|
|
2887
2874
|
type: "string",
|
|
2888
2875
|
describe: "The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url."
|
|
2889
2876
|
},
|
|
2890
|
-
openApiFileName: {
|
|
2891
|
-
type: "string",
|
|
2892
|
-
describe: 'If using "openapi" as the target generator, this allows you to specify the name of the output file.',
|
|
2893
|
-
default: "openapi"
|
|
2894
|
-
},
|
|
2895
2877
|
sortMembersAlphabetically: {
|
|
2896
2878
|
type: "boolean",
|
|
2897
2879
|
describe: "Whether to sort members alphabetically.",
|
|
@@ -2901,6 +2883,11 @@ const markdownOptions = {
|
|
|
2901
2883
|
type: "boolean",
|
|
2902
2884
|
describe: "Whether to include the file's meta.xml information: Whether it is active and and the API version",
|
|
2903
2885
|
default: defaults.defaults.includeMetadata
|
|
2886
|
+
},
|
|
2887
|
+
documentationRootDir: {
|
|
2888
|
+
type: "string",
|
|
2889
|
+
describe: "The root directory of the documentation. This is used to generate the correct relative paths.",
|
|
2890
|
+
default: defaults.defaults.documentationRootDir
|
|
2904
2891
|
}
|
|
2905
2892
|
};
|
|
2906
2893
|
|
|
@@ -2967,10 +2954,10 @@ function extractArgs() {
|
|
|
2967
2954
|
}
|
|
2968
2955
|
|
|
2969
2956
|
function main() {
|
|
2970
|
-
function
|
|
2957
|
+
function catchError(error) {
|
|
2971
2958
|
console.error(error);
|
|
2972
2959
|
process.exit(1);
|
|
2973
2960
|
}
|
|
2974
|
-
extractArgs().then((config) => Apexdocs.generate(config).catch(
|
|
2961
|
+
extractArgs().then((config) => Apexdocs.generate(config).catch(catchError)).catch(catchError);
|
|
2975
2962
|
}
|
|
2976
2963
|
main();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const defaults = {
|
|
4
|
+
targetGenerator: "markdown",
|
|
5
|
+
targetDir: "./docs/",
|
|
6
|
+
scope: ["global"],
|
|
7
|
+
defaultGroupName: "Miscellaneous",
|
|
8
|
+
includeMetadata: false,
|
|
9
|
+
sortMembersAlphabetically: false,
|
|
10
|
+
documentationRootDir: ""
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.defaults = defaults;
|
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 = {
|
|
@@ -15,48 +19,83 @@ type UserDefinedMarkdownConfig = {
|
|
|
15
19
|
namespace?: string;
|
|
16
20
|
sortMembersAlphabetically: boolean;
|
|
17
21
|
includeMetadata: boolean;
|
|
22
|
+
documentationRootDir: string;
|
|
18
23
|
} & Partial<ConfigurableHooks>;
|
|
19
24
|
|
|
25
|
+
type SourceFileMetadata = {
|
|
26
|
+
filePath: string;
|
|
27
|
+
name: string;
|
|
28
|
+
type: 'interface' | 'class' | 'enum';
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type DocPageReference = {
|
|
32
|
+
source: SourceFileMetadata;
|
|
33
|
+
// The name under which the type should be displayed in the documentation.
|
|
34
|
+
// By default, this will match the source.name, but it can be configured by the user.
|
|
35
|
+
displayName: string;
|
|
36
|
+
// The location of the file relative to the root of the documentation.
|
|
37
|
+
pathFromRoot: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
20
40
|
type Frontmatter = string | Record<string, unknown> | null;
|
|
21
41
|
|
|
22
42
|
type ReferenceGuidePageData = {
|
|
23
|
-
directory: string;
|
|
24
43
|
frontmatter: Frontmatter;
|
|
25
44
|
content: string;
|
|
26
|
-
|
|
27
|
-
fileName: string;
|
|
45
|
+
filePath: string;
|
|
28
46
|
};
|
|
29
47
|
|
|
30
48
|
type DocPageData = {
|
|
31
|
-
source:
|
|
32
|
-
filePath: string;
|
|
33
|
-
name: string;
|
|
34
|
-
type: 'interface' | 'class' | 'enum';
|
|
35
|
-
};
|
|
49
|
+
source: SourceFileMetadata;
|
|
36
50
|
group: string | null;
|
|
37
|
-
|
|
38
|
-
fileExtension: string;
|
|
39
|
-
directory: string;
|
|
51
|
+
filePath: string;
|
|
40
52
|
frontmatter: Frontmatter;
|
|
41
53
|
content: string;
|
|
42
54
|
};
|
|
43
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Represents a file to be skipped.
|
|
58
|
+
*/
|
|
44
59
|
type Skip = {
|
|
45
60
|
readonly _tag: 'Skip';
|
|
46
61
|
};
|
|
47
62
|
|
|
48
63
|
// Configurable Hooks
|
|
49
64
|
|
|
65
|
+
type ConfigurableDocPageReference = Omit<DocPageReference, 'source'>;
|
|
66
|
+
|
|
67
|
+
type ConfigurableDocPageData = Omit<DocPageData, 'source' | 'filePath'>;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Allows changing where the files are written to.
|
|
71
|
+
*/
|
|
72
|
+
type TransformReference = (
|
|
73
|
+
reference: DocPageReference,
|
|
74
|
+
) => Partial<ConfigurableDocPageReference> | Promise<ConfigurableDocPageReference>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Allows changing the frontmatter and content of the reference guide, or even if creating a reference
|
|
78
|
+
* guide will be skipped altogether.
|
|
79
|
+
*/
|
|
50
80
|
type TransformReferenceGuide = (
|
|
51
81
|
referenceGuide: ReferenceGuidePageData,
|
|
52
82
|
) => Partial<ReferenceGuidePageData> | Skip | Promise<Partial<ReferenceGuidePageData> | Skip>;
|
|
53
83
|
|
|
84
|
+
/**
|
|
85
|
+
* The main purpose if for allowing for doc pages to be skipped, but it can also be used to change the frontmatter
|
|
86
|
+
* and content of the doc pages.
|
|
87
|
+
*/
|
|
54
88
|
type TransformDocs = (docs: DocPageData[]) => DocPageData[] | Promise<DocPageData[]>;
|
|
55
89
|
|
|
56
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Allows changing the frontmatter and content of the doc pages.
|
|
92
|
+
*/
|
|
93
|
+
type TransformDocPage = (
|
|
94
|
+
doc: DocPageData,
|
|
95
|
+
) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>;
|
|
57
96
|
|
|
58
|
-
type ConfigurableMarkdownConfig = Omit<SetOptional<UserDefinedMarkdownConfig, 'targetDir' | 'scope' | 'defaultGroupName' | 'includeMetadata' | 'sortMembersAlphabetically'>, 'targetGenerator'>;
|
|
97
|
+
type ConfigurableMarkdownConfig = Omit<SetOptional<UserDefinedMarkdownConfig, 'targetDir' | 'scope' | 'defaultGroupName' | 'includeMetadata' | 'sortMembersAlphabetically' | 'documentationRootDir'>, 'targetGenerator'>;
|
|
59
98
|
declare function defineMarkdownConfig(config: ConfigurableMarkdownConfig): UserDefinedMarkdownConfig;
|
|
60
99
|
declare function skip(): Skip;
|
|
61
100
|
|
|
62
|
-
export { type ConfigurableHooks, type DocPageData, type ReferenceGuidePageData, defineMarkdownConfig, skip };
|
|
101
|
+
export { type ConfigurableHooks, type DocPageData, type DocPageReference, type ReferenceGuidePageData, defineMarkdownConfig, skip };
|