@cparra/apexdocs 3.0.0-alpha.9 → 3.0.0-beta.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 +294 -204
- package/examples/open-api/config/project-scratch-def.json +13 -0
- package/examples/open-api/docs/openapi.json +582 -0
- package/examples/{force-app → open-api/force-app}/main/default/classes/SampleClass.cls +1 -0
- package/examples/open-api/package-lock.json +724 -0
- package/examples/open-api/package.json +20 -0
- package/examples/open-api/sfdx-project.json +12 -0
- package/package.json +1 -1
- package/src/application/Apexdocs.ts +39 -7
- package/src/application/__tests__/apex-file-reader.spec.ts +0 -17
- package/src/application/file-writer.ts +37 -15
- package/src/application/generators/markdown.ts +10 -39
- package/src/application/generators/openapi.ts +22 -6
- package/src/cli/args.ts +4 -1
- package/src/cli/commands/openapi.ts +36 -0
- package/src/core/markdown/adapters/documentables.ts +0 -1
- package/src/core/markdown/generate-docs.ts +2 -5
- package/src/core/markdown/reflection/reflect-source.ts +51 -50
- package/src/core/openApiSettings.ts +41 -0
- package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +2 -2
- package/src/core/openapi/open-api-docs-processor.ts +8 -4
- package/src/core/openapi/open-api.ts +5 -1
- package/src/core/openapi/openapi-type-file.ts +1 -1
- package/src/core/openapi/parser.ts +1 -15
- package/src/core/openapi/transpiler.ts +0 -5
- package/src/core/parse-apex-metadata.ts +21 -5
- package/src/core/shared/types.d.ts +4 -1
- package/src/test-helpers/SettingsBuilder.ts +2 -6
- package/examples/force-app/main/default/classes/AnotherInterface.cls +0 -16
- package/examples/force-app/main/default/classes/EscapedAnnotations.cls +0 -5
- package/examples/force-app/main/default/classes/GrandparentClass.cls +0 -5
- package/examples/force-app/main/default/classes/GroupedClass.cls +0 -8
- package/examples/force-app/main/default/classes/InterfaceWithInheritance.cls +0 -1
- package/examples/force-app/main/default/classes/MemberGrouping.cls +0 -17
- package/examples/force-app/main/default/classes/ParentClass.cls +0 -16
- package/examples/force-app/main/default/classes/SampleClass.cls-meta.xml +0 -5
- package/examples/force-app/main/default/classes/SampleClassWithoutModifier.cls +0 -9
- package/examples/force-app/main/default/classes/SampleInterface.cls +0 -16
- package/src/core/settings.ts +0 -56
- /package/examples/{force-app → open-api/force-app}/main/default/classes/ChildClass.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResource.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceToSkip.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceWithInnerClass.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference1.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference2.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference3.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference4.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference5.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference6.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference7.cls +0 -0
package/dist/cli/generate.js
CHANGED
|
@@ -5,6 +5,7 @@ var _function = require('fp-ts/function');
|
|
|
5
5
|
var TE = require('fp-ts/TaskEither');
|
|
6
6
|
var yaml = require('js-yaml');
|
|
7
7
|
var path = require('path');
|
|
8
|
+
var E = require('fp-ts/Either');
|
|
8
9
|
var T = require('fp-ts/Task');
|
|
9
10
|
var A = require('fp-ts/lib/Array');
|
|
10
11
|
var apexReflection = require('@cparra/apex-reflection');
|
|
@@ -13,6 +14,7 @@ var fastXmlParser = require('fast-xml-parser');
|
|
|
13
14
|
var Handlebars = require('handlebars');
|
|
14
15
|
var defaults = require('../defaults-DGKfeZq-.js');
|
|
15
16
|
var fs = require('fs');
|
|
17
|
+
var TE$1 = require('fp-ts/lib/TaskEither');
|
|
16
18
|
var chalk = require('chalk');
|
|
17
19
|
var cosmiconfig = require('cosmiconfig');
|
|
18
20
|
var yargs = require('yargs');
|
|
@@ -38,10 +40,12 @@ function _interopNamespaceDefault(e) {
|
|
|
38
40
|
var TE__namespace = /*#__PURE__*/_interopNamespaceDefault(TE);
|
|
39
41
|
var yaml__namespace = /*#__PURE__*/_interopNamespaceDefault(yaml);
|
|
40
42
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
43
|
+
var E__namespace = /*#__PURE__*/_interopNamespaceDefault(E);
|
|
41
44
|
var T__namespace = /*#__PURE__*/_interopNamespaceDefault(T);
|
|
42
45
|
var A__namespace = /*#__PURE__*/_interopNamespaceDefault(A);
|
|
43
46
|
var O__namespace = /*#__PURE__*/_interopNamespaceDefault(O);
|
|
44
47
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
48
|
+
var TE__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(TE$1);
|
|
45
49
|
var yargs__namespace = /*#__PURE__*/_interopNamespaceDefault(yargs);
|
|
46
50
|
|
|
47
51
|
function apply(fn, ...front) {
|
|
@@ -663,12 +667,16 @@ function getTypeGroup$1(type, config) {
|
|
|
663
667
|
}
|
|
664
668
|
|
|
665
669
|
function parseApexMetadata(input) {
|
|
666
|
-
|
|
670
|
+
return _function.pipe(input, parse, E__namespace.map(toMap));
|
|
671
|
+
}
|
|
672
|
+
function parse(input) {
|
|
673
|
+
return E__namespace.tryCatch(() => new fastXmlParser.XMLParser().parse(input), E__namespace.toError);
|
|
674
|
+
}
|
|
675
|
+
function toMap(metadata) {
|
|
667
676
|
const map = /* @__PURE__ */ new Map();
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
map.set("status", xml.ApexClass.status);
|
|
677
|
+
map.set("apiVersion", String(metadata.ApexClass.apiVersion));
|
|
678
|
+
if (metadata.ApexClass.status) {
|
|
679
|
+
map.set("status", String(metadata.ApexClass.status));
|
|
672
680
|
}
|
|
673
681
|
return map;
|
|
674
682
|
}
|
|
@@ -692,7 +700,7 @@ var __spreadValues$d = (a, b) => {
|
|
|
692
700
|
return a;
|
|
693
701
|
};
|
|
694
702
|
var __spreadProps$d = (a, b) => __defProps$d(a, __getOwnPropDescs$d(b));
|
|
695
|
-
var __async$
|
|
703
|
+
var __async$6 = (__this, __arguments, generator) => {
|
|
696
704
|
return new Promise((resolve, reject) => {
|
|
697
705
|
var fulfilled = (value) => {
|
|
698
706
|
try {
|
|
@@ -725,7 +733,7 @@ class ReflectionError {
|
|
|
725
733
|
}
|
|
726
734
|
}
|
|
727
735
|
function reflectAsync(rawSource) {
|
|
728
|
-
return __async$
|
|
736
|
+
return __async$6(this, null, function* () {
|
|
729
737
|
return new Promise((resolve, reject) => {
|
|
730
738
|
const result = apexReflection.reflect(rawSource);
|
|
731
739
|
if (result.typeMirror) {
|
|
@@ -738,17 +746,17 @@ function reflectAsync(rawSource) {
|
|
|
738
746
|
});
|
|
739
747
|
});
|
|
740
748
|
}
|
|
741
|
-
function
|
|
749
|
+
function reflectBundles(apexBundles) {
|
|
742
750
|
const semiGroupReflectionError = {
|
|
743
751
|
concat: (x, y) => new ReflectionErrors([...x.errors, ...y.errors])
|
|
744
752
|
};
|
|
745
753
|
const Ap = TE__namespace.getApplicativeTaskValidation(T__namespace.ApplyPar, semiGroupReflectionError);
|
|
746
|
-
return _function.pipe(apexBundles, A__namespace.traverse(Ap)(
|
|
754
|
+
return _function.pipe(apexBundles, A__namespace.traverse(Ap)(reflectBundle));
|
|
747
755
|
}
|
|
748
|
-
function
|
|
756
|
+
function reflectBundle(apexBundle) {
|
|
749
757
|
const convertToParsedFile = apply(toParsedFile, apexBundle.filePath);
|
|
750
758
|
const withMetadata = apply(addMetadata, apexBundle.metadataContent);
|
|
751
|
-
return _function.pipe(apexBundle, reflectAsTask, TE__namespace.map(convertToParsedFile), TE__namespace.
|
|
759
|
+
return _function.pipe(apexBundle, reflectAsTask, TE__namespace.map(convertToParsedFile), TE__namespace.flatMap(withMetadata));
|
|
752
760
|
}
|
|
753
761
|
function reflectAsTask(apexBundle) {
|
|
754
762
|
return TE__namespace.tryCatch(
|
|
@@ -767,28 +775,45 @@ function toParsedFile(filePath, typeMirror) {
|
|
|
767
775
|
};
|
|
768
776
|
}
|
|
769
777
|
function addMetadata(rawMetadataContent, parsedFile) {
|
|
770
|
-
return
|
|
771
|
-
|
|
772
|
-
|
|
778
|
+
return TE__namespace.fromEither(
|
|
779
|
+
_function.pipe(
|
|
780
|
+
parsedFile.type,
|
|
781
|
+
(type) => addFileMetadataToTypeAnnotation(type, rawMetadataContent),
|
|
782
|
+
E__namespace.map((type) => __spreadProps$d(__spreadValues$d({}, parsedFile), { type })),
|
|
783
|
+
E__namespace.mapLeft((error) => errorToReflectionErrors(error, parsedFile.source.filePath))
|
|
784
|
+
)
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
function errorToReflectionErrors(error, filePath) {
|
|
788
|
+
return new ReflectionErrors([new ReflectionError(filePath, error.message)]);
|
|
773
789
|
}
|
|
774
790
|
function addFileMetadataToTypeAnnotation(type, metadata) {
|
|
791
|
+
const concatAnnotationToType = apply(concatAnnotations, type);
|
|
775
792
|
return _function.pipe(
|
|
776
793
|
O__namespace.fromNullable(metadata),
|
|
777
|
-
O__namespace.map(
|
|
778
|
-
|
|
779
|
-
metadataParams.forEach((value, key) => {
|
|
780
|
-
const declaration = `${key}: ${value}`;
|
|
781
|
-
type.annotations.push({
|
|
782
|
-
rawDeclaration: declaration,
|
|
783
|
-
name: declaration,
|
|
784
|
-
type: declaration
|
|
785
|
-
});
|
|
786
|
-
});
|
|
787
|
-
return type;
|
|
788
|
-
}),
|
|
789
|
-
O__namespace.getOrElse(() => type)
|
|
794
|
+
O__namespace.map(concatAnnotationToType),
|
|
795
|
+
O__namespace.getOrElse(() => E__namespace.right(type))
|
|
790
796
|
);
|
|
791
797
|
}
|
|
798
|
+
function concatAnnotations(type, metadataInput) {
|
|
799
|
+
return _function.pipe(
|
|
800
|
+
metadataInput,
|
|
801
|
+
parseApexMetadata,
|
|
802
|
+
E__namespace.map((metadataMap) => __spreadProps$d(__spreadValues$d({}, type), {
|
|
803
|
+
annotations: [...type.annotations, ...mapToAnnotations(metadataMap)]
|
|
804
|
+
}))
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
function mapToAnnotations(metadata) {
|
|
808
|
+
return Array.from(metadata.entries()).map(([key, value]) => {
|
|
809
|
+
const declaration = `${key}: ${value}`;
|
|
810
|
+
return {
|
|
811
|
+
name: declaration,
|
|
812
|
+
type: declaration,
|
|
813
|
+
rawDeclaration: declaration
|
|
814
|
+
};
|
|
815
|
+
});
|
|
816
|
+
}
|
|
792
817
|
|
|
793
818
|
function createInheritanceChain(repository, classMirror) {
|
|
794
819
|
return _function.pipe(
|
|
@@ -1578,7 +1603,7 @@ var __spreadValues$7 = (a, b) => {
|
|
|
1578
1603
|
return a;
|
|
1579
1604
|
};
|
|
1580
1605
|
var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
|
|
1581
|
-
var __async$
|
|
1606
|
+
var __async$5 = (__this, __arguments, generator) => {
|
|
1582
1607
|
return new Promise((resolve, reject) => {
|
|
1583
1608
|
var fulfilled = (value) => {
|
|
1584
1609
|
try {
|
|
@@ -1612,8 +1637,7 @@ function generateDocs(apexBundles, config) {
|
|
|
1612
1637
|
const sortTypeMembers = apply(sortMembers, config.sortMembersAlphabetically);
|
|
1613
1638
|
return _function.pipe(
|
|
1614
1639
|
apexBundles,
|
|
1615
|
-
|
|
1616
|
-
//checkForReflectionErrors,
|
|
1640
|
+
reflectBundles,
|
|
1617
1641
|
TE__namespace.map(filterOutOfScope),
|
|
1618
1642
|
TE__namespace.map(addInheritedMembersToTypes),
|
|
1619
1643
|
TE__namespace.map(addInheritanceChainToTypes),
|
|
@@ -1629,7 +1653,7 @@ function generateDocs(apexBundles, config) {
|
|
|
1629
1653
|
}
|
|
1630
1654
|
function transformReferenceHook(config) {
|
|
1631
1655
|
function _execute(references, parsedFiles, transformReference) {
|
|
1632
|
-
return __async$
|
|
1656
|
+
return __async$5(this, null, function* () {
|
|
1633
1657
|
return {
|
|
1634
1658
|
references: yield execTransformReferenceHook(Object.values(references), transformReference),
|
|
1635
1659
|
parsedFiles
|
|
@@ -1650,8 +1674,8 @@ function transformDocumentationBundleHook(config) {
|
|
|
1650
1674
|
function passThroughHook(value) {
|
|
1651
1675
|
return value;
|
|
1652
1676
|
}
|
|
1653
|
-
const execTransformReferenceHook = (_0, ..._1) => __async$
|
|
1654
|
-
const hooked = references.map((reference) => __async$
|
|
1677
|
+
const execTransformReferenceHook = (_0, ..._1) => __async$5(void 0, [_0, ..._1], function* (references, hook = passThroughHook) {
|
|
1678
|
+
const hooked = references.map((reference) => __async$5(void 0, null, function* () {
|
|
1655
1679
|
const hookedResult = yield hook(reference);
|
|
1656
1680
|
return __spreadValues$7(__spreadValues$7({}, reference), hookedResult);
|
|
1657
1681
|
}));
|
|
@@ -1661,24 +1685,24 @@ const execTransformReferenceHook = (_0, ..._1) => __async$4(void 0, [_0, ..._1],
|
|
|
1661
1685
|
return acc;
|
|
1662
1686
|
}, {});
|
|
1663
1687
|
});
|
|
1664
|
-
const documentationBundleHook = (bundle, config) => __async$
|
|
1688
|
+
const documentationBundleHook = (bundle, config) => __async$5(void 0, null, function* () {
|
|
1665
1689
|
return {
|
|
1666
1690
|
referenceGuide: yield transformReferenceGuide(bundle.referenceGuide, config.transformReferenceGuide),
|
|
1667
1691
|
docs: yield transformDocs(bundle.docs, config.transformDocs, config.transformDocPage)
|
|
1668
1692
|
};
|
|
1669
1693
|
});
|
|
1670
|
-
const transformReferenceGuide = (_0, ..._1) => __async$
|
|
1694
|
+
const transformReferenceGuide = (_0, ..._1) => __async$5(void 0, [_0, ..._1], function* (referenceGuide, hook = passThroughHook) {
|
|
1671
1695
|
const result = yield hook(referenceGuide);
|
|
1672
1696
|
if (isSkip(result)) {
|
|
1673
1697
|
return result;
|
|
1674
1698
|
}
|
|
1675
1699
|
return __spreadValues$7(__spreadValues$7({}, referenceGuide), yield hook(referenceGuide));
|
|
1676
1700
|
});
|
|
1677
|
-
const transformDocs = (_0, ..._1) => __async$
|
|
1701
|
+
const transformDocs = (_0, ..._1) => __async$5(void 0, [_0, ..._1], function* (docs, transformDocsHook = passThroughHook, transformDocPageHook = passThroughHook) {
|
|
1678
1702
|
const transformed = yield transformDocsHook(docs);
|
|
1679
1703
|
return Promise.all(transformed.map((doc) => transformDocPage(doc, transformDocPageHook)));
|
|
1680
1704
|
});
|
|
1681
|
-
const transformDocPage = (_0, ..._1) => __async$
|
|
1705
|
+
const transformDocPage = (_0, ..._1) => __async$5(void 0, [_0, ..._1], function* (doc, hook = passThroughHook) {
|
|
1682
1706
|
return __spreadValues$7(__spreadValues$7({}, doc), yield hook(doc));
|
|
1683
1707
|
});
|
|
1684
1708
|
function postHookCompile(bundle) {
|
|
@@ -1716,6 +1740,21 @@ ${yamlString}---
|
|
|
1716
1740
|
`;
|
|
1717
1741
|
}
|
|
1718
1742
|
|
|
1743
|
+
const referenceGuideTemplate = `
|
|
1744
|
+
# Apex Reference Guide
|
|
1745
|
+
|
|
1746
|
+
{{#each this}}
|
|
1747
|
+
## {{@key}}
|
|
1748
|
+
|
|
1749
|
+
{{#each this}}
|
|
1750
|
+
### {{link title}}
|
|
1751
|
+
|
|
1752
|
+
{{{renderContent description}}}
|
|
1753
|
+
|
|
1754
|
+
{{/each}}
|
|
1755
|
+
{{/each}}
|
|
1756
|
+
`.trim();
|
|
1757
|
+
|
|
1719
1758
|
var __defProp$6 = Object.defineProperty;
|
|
1720
1759
|
var __defProps$6 = Object.defineProperties;
|
|
1721
1760
|
var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
|
|
@@ -1735,73 +1774,30 @@ var __spreadValues$6 = (a, b) => {
|
|
|
1735
1774
|
return a;
|
|
1736
1775
|
};
|
|
1737
1776
|
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
|
-
static getTargetLocation(file, outputDir) {
|
|
1748
|
-
return __spreadProps$6(__spreadValues$6({}, file), {
|
|
1749
|
-
outputDocPath: path__namespace.join(outputDir, file.outputDocPath)
|
|
1750
|
-
});
|
|
1751
|
-
}
|
|
1777
|
+
const mkdir = TE__namespace$1.taskify(fs__namespace.mkdir);
|
|
1778
|
+
const writeFile = TE__namespace$1.taskify(fs__namespace.writeFile);
|
|
1779
|
+
function writeFiles(files, outputDir, onWriteCallback) {
|
|
1780
|
+
return _function.pipe(
|
|
1781
|
+
files,
|
|
1782
|
+
TE__namespace$1.traverseArray((file) => writeSingle(file, outputDir, onWriteCallback))
|
|
1783
|
+
);
|
|
1752
1784
|
}
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
* @param message The error message to log.
|
|
1769
|
-
* @param args Optional arguments.
|
|
1770
|
-
*/
|
|
1771
|
-
static error(message, ...args) {
|
|
1772
|
-
this.logSingle(message, "red");
|
|
1773
|
-
args.forEach(() => {
|
|
1774
|
-
this.logSingle(message, "red");
|
|
1775
|
-
});
|
|
1776
|
-
}
|
|
1777
|
-
static logSingle(text, color = "green") {
|
|
1778
|
-
if (this.currentFrame > 9) {
|
|
1779
|
-
this.currentFrame = 0;
|
|
1780
|
-
}
|
|
1781
|
-
const logMessage = `${this.getChalkFn(color)((/* @__PURE__ */ new Date()).toLocaleString() + ": ")}${text}
|
|
1782
|
-
`;
|
|
1783
|
-
process.stdout.write(logMessage);
|
|
1784
|
-
}
|
|
1785
|
-
static getChalkFn(color) {
|
|
1786
|
-
return color === "green" ? chalk.green : chalk.red;
|
|
1787
|
-
}
|
|
1785
|
+
function writeSingle(file, outputDir, onWriteCallback) {
|
|
1786
|
+
const ensureDirectoryExists = ({ outputDocPath }) => mkdir(path__namespace.dirname(outputDocPath), { recursive: true });
|
|
1787
|
+
const writeContents = (file2) => writeFile(file2.outputDocPath, file2.content, "utf8");
|
|
1788
|
+
return _function.pipe(
|
|
1789
|
+
resolveTargetLocation(file, outputDir),
|
|
1790
|
+
(file2) => TE__namespace$1.right(file2),
|
|
1791
|
+
TE__namespace$1.tapIO(ensureDirectoryExists),
|
|
1792
|
+
TE__namespace$1.flatMap(writeContents),
|
|
1793
|
+
TE__namespace$1.map(() => onWriteCallback == null ? void 0 : onWriteCallback(file))
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
function resolveTargetLocation(file, outputDir) {
|
|
1797
|
+
return __spreadProps$6(__spreadValues$6({}, file), {
|
|
1798
|
+
outputDocPath: path__namespace.join(outputDir, file.outputDocPath)
|
|
1799
|
+
});
|
|
1788
1800
|
}
|
|
1789
|
-
Logger.currentFrame = 0;
|
|
1790
|
-
|
|
1791
|
-
const referenceGuideTemplate = `
|
|
1792
|
-
# Apex Reference Guide
|
|
1793
|
-
|
|
1794
|
-
{{#each this}}
|
|
1795
|
-
## {{@key}}
|
|
1796
|
-
|
|
1797
|
-
{{#each this}}
|
|
1798
|
-
### {{link title}}
|
|
1799
|
-
|
|
1800
|
-
{{{renderContent description}}}
|
|
1801
|
-
|
|
1802
|
-
{{/each}}
|
|
1803
|
-
{{/each}}
|
|
1804
|
-
`.trim();
|
|
1805
1801
|
|
|
1806
1802
|
var __defProp$5 = Object.defineProperty;
|
|
1807
1803
|
var __defProps$5 = Object.defineProperties;
|
|
@@ -1832,25 +1828,8 @@ class FileWritingError {
|
|
|
1832
1828
|
function generate(bundles, config) {
|
|
1833
1829
|
return _function.pipe(
|
|
1834
1830
|
generateDocumentationBundle(bundles, config),
|
|
1835
|
-
TE__namespace.flatMap((files) => writeFilesToSystem(files, config.targetDir))
|
|
1836
|
-
|
|
1837
|
-
if (error._tag === "HookError") {
|
|
1838
|
-
Logger.error("Error(s) occurred while processing hooks. Please review the following issues:");
|
|
1839
|
-
Logger.error(error.error);
|
|
1840
|
-
return;
|
|
1841
|
-
}
|
|
1842
|
-
if (error._tag === "FileWritingError") {
|
|
1843
|
-
Logger.error(error.message);
|
|
1844
|
-
Logger.error(error.error);
|
|
1845
|
-
return;
|
|
1846
|
-
}
|
|
1847
|
-
const errorMessages = [
|
|
1848
|
-
"Error(s) occurred while parsing files. Please review the following issues:",
|
|
1849
|
-
...error.errors.map(formatReflectionError)
|
|
1850
|
-
].join("\n");
|
|
1851
|
-
Logger.error(errorMessages);
|
|
1852
|
-
})
|
|
1853
|
-
)();
|
|
1831
|
+
TE__namespace.flatMap((files) => writeFilesToSystem(files, config.targetDir))
|
|
1832
|
+
);
|
|
1854
1833
|
}
|
|
1855
1834
|
function generateDocumentationBundle(bundles, config) {
|
|
1856
1835
|
return generateDocs(bundles, __spreadProps$5(__spreadValues$5({}, config), {
|
|
@@ -1858,26 +1837,56 @@ function generateDocumentationBundle(bundles, config) {
|
|
|
1858
1837
|
}));
|
|
1859
1838
|
}
|
|
1860
1839
|
function writeFilesToSystem(files, outputDir) {
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
return TE__namespace.left(new FileWritingError("An error occurred while writing files to the system.", error));
|
|
1869
|
-
}
|
|
1870
|
-
}
|
|
1871
|
-
function formatReflectionError(error) {
|
|
1872
|
-
return `Source file: ${error.file}
|
|
1873
|
-
${error.message}
|
|
1874
|
-
`;
|
|
1840
|
+
return _function.pipe(
|
|
1841
|
+
[files.referenceGuide, ...files.docs].filter((file) => !isSkip(file)),
|
|
1842
|
+
(files2) => writeFiles(files2, outputDir),
|
|
1843
|
+
TE__namespace.mapLeft((error) => {
|
|
1844
|
+
return new FileWritingError("An error occurred while writing files to the system.", error);
|
|
1845
|
+
})
|
|
1846
|
+
);
|
|
1875
1847
|
}
|
|
1876
1848
|
|
|
1877
1849
|
function createManifest(typeParser, reflect) {
|
|
1878
1850
|
return new Manifest(typeParser.parse(reflect));
|
|
1879
1851
|
}
|
|
1880
1852
|
|
|
1853
|
+
class Logger {
|
|
1854
|
+
/**
|
|
1855
|
+
* Logs a message with optional arguments.
|
|
1856
|
+
* @param message The message to log.
|
|
1857
|
+
* @param args Optional arguments.
|
|
1858
|
+
*/
|
|
1859
|
+
static log(message, ...args) {
|
|
1860
|
+
this.logSingle(message);
|
|
1861
|
+
args.forEach((arg) => {
|
|
1862
|
+
this.logSingle(arg);
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* Logs an error message with optional arguments.
|
|
1867
|
+
* @param message The error message to log.
|
|
1868
|
+
* @param args Optional arguments.
|
|
1869
|
+
*/
|
|
1870
|
+
static error(message, ...args) {
|
|
1871
|
+
this.logSingle(message, "red");
|
|
1872
|
+
args.forEach(() => {
|
|
1873
|
+
this.logSingle(message, "red");
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
static logSingle(text, color = "green") {
|
|
1877
|
+
if (this.currentFrame > 9) {
|
|
1878
|
+
this.currentFrame = 0;
|
|
1879
|
+
}
|
|
1880
|
+
const logMessage = `${this.getChalkFn(color)((/* @__PURE__ */ new Date()).toLocaleString() + ": ")}${text}
|
|
1881
|
+
`;
|
|
1882
|
+
process.stdout.write(logMessage);
|
|
1883
|
+
}
|
|
1884
|
+
static getChalkFn(color) {
|
|
1885
|
+
return color === "green" ? chalk.green : chalk.red;
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
Logger.currentFrame = 0;
|
|
1889
|
+
|
|
1881
1890
|
var __defProp$4 = Object.defineProperty;
|
|
1882
1891
|
var __defProps$4 = Object.defineProperties;
|
|
1883
1892
|
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
@@ -1904,20 +1913,7 @@ class RawBodyParser {
|
|
|
1904
1913
|
parse(reflect) {
|
|
1905
1914
|
const types = this.typeBundles.map((currentBundle) => {
|
|
1906
1915
|
Logger.log(`Parsing file: ${currentBundle.filePath}`);
|
|
1907
|
-
|
|
1908
|
-
if (!!result.typeMirror && !!currentBundle.metadataContent) {
|
|
1909
|
-
const metadataParams = parseApexMetadata(currentBundle.metadataContent);
|
|
1910
|
-
metadataParams.forEach((value, key) => {
|
|
1911
|
-
var _a;
|
|
1912
|
-
const declaration = `${key}: ${value}`;
|
|
1913
|
-
(_a = result.typeMirror) == null ? void 0 : _a.annotations.push({
|
|
1914
|
-
rawDeclaration: declaration,
|
|
1915
|
-
name: declaration,
|
|
1916
|
-
type: declaration
|
|
1917
|
-
});
|
|
1918
|
-
});
|
|
1919
|
-
}
|
|
1920
|
-
return result;
|
|
1916
|
+
return reflect(currentBundle);
|
|
1921
1917
|
}).filter((reflectionResult) => {
|
|
1922
1918
|
return reflectionResult.typeMirror;
|
|
1923
1919
|
}).map((reflectionResult) => reflectionResult.typeMirror);
|
|
@@ -2055,39 +2051,6 @@ class TypesRepository {
|
|
|
2055
2051
|
}
|
|
2056
2052
|
}
|
|
2057
2053
|
|
|
2058
|
-
class Settings {
|
|
2059
|
-
constructor(config) {
|
|
2060
|
-
this.config = config;
|
|
2061
|
-
}
|
|
2062
|
-
static build(config) {
|
|
2063
|
-
Settings.instance = new Settings(config);
|
|
2064
|
-
}
|
|
2065
|
-
static getInstance() {
|
|
2066
|
-
if (!Settings.instance) {
|
|
2067
|
-
throw new Error("Settings has not been initialized");
|
|
2068
|
-
}
|
|
2069
|
-
return Settings.instance;
|
|
2070
|
-
}
|
|
2071
|
-
get scope() {
|
|
2072
|
-
return this.config.scope;
|
|
2073
|
-
}
|
|
2074
|
-
get targetGenerator() {
|
|
2075
|
-
return this.config.targetGenerator;
|
|
2076
|
-
}
|
|
2077
|
-
get indexOnly() {
|
|
2078
|
-
return this.config.indexOnly;
|
|
2079
|
-
}
|
|
2080
|
-
getOpenApiTitle() {
|
|
2081
|
-
return this.config.openApiTitle;
|
|
2082
|
-
}
|
|
2083
|
-
getNamespace() {
|
|
2084
|
-
return this.config.namespace;
|
|
2085
|
-
}
|
|
2086
|
-
openApiFileName() {
|
|
2087
|
-
return this.config.openApiFileName;
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
|
|
2091
2054
|
class Transpiler {
|
|
2092
2055
|
static generate(types, processor) {
|
|
2093
2056
|
var _a;
|
|
@@ -2096,9 +2059,6 @@ class Transpiler {
|
|
|
2096
2059
|
if (apexTypeA.name > apexTypeB.name) return 1;
|
|
2097
2060
|
return 0;
|
|
2098
2061
|
});
|
|
2099
|
-
if (Settings.getInstance().indexOnly) {
|
|
2100
|
-
return;
|
|
2101
|
-
}
|
|
2102
2062
|
sortedTypes.forEach((currentType) => {
|
|
2103
2063
|
processor.onProcess(currentType);
|
|
2104
2064
|
});
|
|
@@ -2234,6 +2194,33 @@ class OpenApi {
|
|
|
2234
2194
|
}
|
|
2235
2195
|
}
|
|
2236
2196
|
|
|
2197
|
+
class OpenApiSettings {
|
|
2198
|
+
constructor(config) {
|
|
2199
|
+
this.config = config;
|
|
2200
|
+
}
|
|
2201
|
+
static build(config) {
|
|
2202
|
+
OpenApiSettings.instance = new OpenApiSettings(config);
|
|
2203
|
+
}
|
|
2204
|
+
static getInstance() {
|
|
2205
|
+
if (!OpenApiSettings.instance) {
|
|
2206
|
+
throw new Error("Settings has not been initialized");
|
|
2207
|
+
}
|
|
2208
|
+
return OpenApiSettings.instance;
|
|
2209
|
+
}
|
|
2210
|
+
getOpenApiTitle() {
|
|
2211
|
+
return this.config.openApiTitle;
|
|
2212
|
+
}
|
|
2213
|
+
getNamespace() {
|
|
2214
|
+
return this.config.namespace;
|
|
2215
|
+
}
|
|
2216
|
+
openApiFileName() {
|
|
2217
|
+
return this.config.openApiFileName;
|
|
2218
|
+
}
|
|
2219
|
+
getVersion() {
|
|
2220
|
+
return this.config.version;
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2237
2224
|
class ClassMirrorWrapper {
|
|
2238
2225
|
constructor(classMirror) {
|
|
2239
2226
|
this.classMirror = classMirror;
|
|
@@ -2749,7 +2736,7 @@ var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
|
2749
2736
|
function createOpenApiFile(fileName, openApiModel) {
|
|
2750
2737
|
const content = JSON.stringify(__spreadProps$1(__spreadValues$1({}, openApiModel), { namespace: void 0 }), null, 2);
|
|
2751
2738
|
return {
|
|
2752
|
-
outputDocPath:
|
|
2739
|
+
outputDocPath: `${fileName}.json`,
|
|
2753
2740
|
content,
|
|
2754
2741
|
frontmatter: null,
|
|
2755
2742
|
group: null
|
|
@@ -2759,15 +2746,19 @@ function createOpenApiFile(fileName, openApiModel) {
|
|
|
2759
2746
|
class OpenApiDocsProcessor {
|
|
2760
2747
|
constructor() {
|
|
2761
2748
|
this.onAfterProcess = () => {
|
|
2762
|
-
const page = createOpenApiFile(
|
|
2749
|
+
const page = createOpenApiFile(OpenApiSettings.getInstance().openApiFileName(), this.openApiModel);
|
|
2763
2750
|
this._fileContainer.pushFile(page);
|
|
2764
2751
|
};
|
|
2765
2752
|
this._fileContainer = new FileContainer();
|
|
2766
|
-
const title =
|
|
2753
|
+
const title = OpenApiSettings.getInstance().getOpenApiTitle();
|
|
2767
2754
|
if (!title) {
|
|
2768
2755
|
throw Error("No OpenApi title was provided.");
|
|
2769
2756
|
}
|
|
2770
|
-
this.openApiModel = new OpenApi(
|
|
2757
|
+
this.openApiModel = new OpenApi(
|
|
2758
|
+
title,
|
|
2759
|
+
OpenApiSettings.getInstance().getVersion(),
|
|
2760
|
+
OpenApiSettings.getInstance().getNamespace()
|
|
2761
|
+
);
|
|
2771
2762
|
}
|
|
2772
2763
|
fileBuilder() {
|
|
2773
2764
|
return this._fileContainer;
|
|
@@ -2814,17 +2805,51 @@ class OpenApiDocsProcessor {
|
|
|
2814
2805
|
}
|
|
2815
2806
|
}
|
|
2816
2807
|
|
|
2808
|
+
var __async$4 = (__this, __arguments, generator) => {
|
|
2809
|
+
return new Promise((resolve, reject) => {
|
|
2810
|
+
var fulfilled = (value) => {
|
|
2811
|
+
try {
|
|
2812
|
+
step(generator.next(value));
|
|
2813
|
+
} catch (e) {
|
|
2814
|
+
reject(e);
|
|
2815
|
+
}
|
|
2816
|
+
};
|
|
2817
|
+
var rejected = (value) => {
|
|
2818
|
+
try {
|
|
2819
|
+
step(generator.throw(value));
|
|
2820
|
+
} catch (e) {
|
|
2821
|
+
reject(e);
|
|
2822
|
+
}
|
|
2823
|
+
};
|
|
2824
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2825
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2826
|
+
});
|
|
2827
|
+
};
|
|
2817
2828
|
function openApi(fileBodies, config) {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2829
|
+
return __async$4(this, null, function* () {
|
|
2830
|
+
OpenApiSettings.build({
|
|
2831
|
+
sourceDirectory: config.sourceDir,
|
|
2832
|
+
outputDir: config.targetDir,
|
|
2833
|
+
openApiFileName: config.fileName,
|
|
2834
|
+
openApiTitle: config.title,
|
|
2835
|
+
namespace: config.namespace,
|
|
2836
|
+
version: config.apiVersion
|
|
2837
|
+
});
|
|
2838
|
+
const manifest = createManifest(new RawBodyParser(fileBodies), reflectionWithLogger);
|
|
2839
|
+
TypesRepository.getInstance().populateAll(manifest.types);
|
|
2840
|
+
const filteredTypes = filterByScopes(manifest);
|
|
2841
|
+
const processor = new OpenApiDocsProcessor();
|
|
2842
|
+
Transpiler.generate(filteredTypes, processor);
|
|
2843
|
+
const generatedFiles = processor.fileBuilder().files();
|
|
2844
|
+
yield _function.pipe(
|
|
2845
|
+
writeFiles(generatedFiles, config.targetDir, (file) => {
|
|
2846
|
+
Logger.logSingle(`${file.outputDocPath} processed.`, "green");
|
|
2847
|
+
}),
|
|
2848
|
+
TE__namespace.map(() => Logger.logSingle("\u2714\uFE0F Documentation generated successfully!")),
|
|
2849
|
+
TE__namespace.mapError((error) => Logger.error(error))
|
|
2850
|
+
)();
|
|
2851
|
+
ErrorLogger.logErrors(filteredTypes);
|
|
2826
2852
|
});
|
|
2827
|
-
ErrorLogger.logErrors(filteredTypes);
|
|
2828
2853
|
}
|
|
2829
2854
|
function reflectionWithLogger(apexBundle) {
|
|
2830
2855
|
var _a;
|
|
@@ -3017,23 +3042,50 @@ class Apexdocs {
|
|
|
3017
3042
|
const fileBodies = yield ApexFileReader.processFiles(
|
|
3018
3043
|
new DefaultFileSystem(),
|
|
3019
3044
|
config.sourceDir,
|
|
3020
|
-
config.includeMetadata
|
|
3045
|
+
config.targetGenerator === "markdown" ? config.includeMetadata : false
|
|
3021
3046
|
);
|
|
3022
3047
|
switch (config.targetGenerator) {
|
|
3023
3048
|
case "markdown":
|
|
3024
|
-
yield
|
|
3049
|
+
yield generateMarkdownDocumentation(fileBodies, config)();
|
|
3025
3050
|
break;
|
|
3026
3051
|
case "openapi":
|
|
3027
|
-
openApi(fileBodies, config);
|
|
3052
|
+
yield openApi(fileBodies, config);
|
|
3028
3053
|
break;
|
|
3029
3054
|
}
|
|
3030
|
-
Logger.logSingle("\u2714\uFE0F Documentation generated successfully!");
|
|
3031
3055
|
} catch (error) {
|
|
3032
|
-
Logger.logSingle(
|
|
3056
|
+
Logger.logSingle(`\u274C An error occurred while generating the documentation: ${error}`, "red");
|
|
3033
3057
|
}
|
|
3034
3058
|
});
|
|
3035
3059
|
}
|
|
3036
3060
|
}
|
|
3061
|
+
function generateMarkdownDocumentation(fileBodies, config) {
|
|
3062
|
+
return _function.pipe(
|
|
3063
|
+
generate(fileBodies, config),
|
|
3064
|
+
TE__namespace.map(() => Logger.logSingle("\u2714\uFE0F Documentation generated successfully!")),
|
|
3065
|
+
TE__namespace.mapLeft((error) => {
|
|
3066
|
+
if (error._tag === "HookError") {
|
|
3067
|
+
Logger.error("Error(s) occurred while processing hooks. Please review the following issues:");
|
|
3068
|
+
Logger.error(error.error);
|
|
3069
|
+
return;
|
|
3070
|
+
}
|
|
3071
|
+
if (error._tag === "FileWritingError") {
|
|
3072
|
+
Logger.error(error.message);
|
|
3073
|
+
Logger.error(error.error);
|
|
3074
|
+
return;
|
|
3075
|
+
}
|
|
3076
|
+
const errorMessages = [
|
|
3077
|
+
"Error(s) occurred while parsing files. Please review the following issues:",
|
|
3078
|
+
...error.errors.map(formatReflectionError)
|
|
3079
|
+
].join("\n");
|
|
3080
|
+
Logger.error(errorMessages);
|
|
3081
|
+
})
|
|
3082
|
+
);
|
|
3083
|
+
}
|
|
3084
|
+
function formatReflectionError(error) {
|
|
3085
|
+
return `Source file: ${error.file}
|
|
3086
|
+
${error.message}
|
|
3087
|
+
`;
|
|
3088
|
+
}
|
|
3037
3089
|
|
|
3038
3090
|
const markdownOptions = {
|
|
3039
3091
|
sourceDir: {
|
|
@@ -3082,6 +3134,40 @@ const markdownOptions = {
|
|
|
3082
3134
|
}
|
|
3083
3135
|
};
|
|
3084
3136
|
|
|
3137
|
+
const openApiOptions = {
|
|
3138
|
+
sourceDir: {
|
|
3139
|
+
type: "string",
|
|
3140
|
+
alias: "s",
|
|
3141
|
+
demandOption: true,
|
|
3142
|
+
describe: "The directory location which contains your apex .cls classes."
|
|
3143
|
+
},
|
|
3144
|
+
targetDir: {
|
|
3145
|
+
type: "string",
|
|
3146
|
+
alias: "t",
|
|
3147
|
+
default: defaults.defaults.targetDir,
|
|
3148
|
+
describe: "The directory location where the OpenApi file will be generated."
|
|
3149
|
+
},
|
|
3150
|
+
fileName: {
|
|
3151
|
+
type: "string",
|
|
3152
|
+
default: "openapi",
|
|
3153
|
+
describe: "The name of the OpenApi file to be generated."
|
|
3154
|
+
},
|
|
3155
|
+
namespace: {
|
|
3156
|
+
type: "string",
|
|
3157
|
+
describe: "The package namespace, if any. This will be added to the API file Server Url."
|
|
3158
|
+
},
|
|
3159
|
+
title: {
|
|
3160
|
+
type: "string",
|
|
3161
|
+
default: "Apex REST API",
|
|
3162
|
+
describe: "The title of the OpenApi file."
|
|
3163
|
+
},
|
|
3164
|
+
apiVersion: {
|
|
3165
|
+
type: "string",
|
|
3166
|
+
default: "1.0.0",
|
|
3167
|
+
describe: "The version of the OpenApi file."
|
|
3168
|
+
}
|
|
3169
|
+
};
|
|
3170
|
+
|
|
3085
3171
|
var __defProp = Object.defineProperty;
|
|
3086
3172
|
var __defProps = Object.defineProperties;
|
|
3087
3173
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -3133,7 +3219,11 @@ function _extractYargs(config) {
|
|
|
3133
3219
|
"markdown",
|
|
3134
3220
|
"Generate documentation from Apex classes as a Markdown site.",
|
|
3135
3221
|
(yargs2) => yargs2.options(markdownOptions)
|
|
3136
|
-
).command(
|
|
3222
|
+
).command(
|
|
3223
|
+
"openapi",
|
|
3224
|
+
"Generate an OpenApi REST specification from Apex classes.",
|
|
3225
|
+
() => yargs__namespace.options(openApiOptions)
|
|
3226
|
+
).demandCommand().parseSync();
|
|
3137
3227
|
}
|
|
3138
3228
|
function extractArgs() {
|
|
3139
3229
|
return __async(this, null, function* () {
|