@cparra/apexdocs 2.25.0-alpha.4 → 2.25.0-alpha.5

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.
Files changed (189) hide show
  1. package/dist/cli/generate.js +2745 -39
  2. package/dist/defaults-DUwru49Q.js +12 -0
  3. package/dist/defaults-SH0Rsi5E.js +11 -0
  4. package/dist/index.d.ts +62 -2
  5. package/dist/index.js +36 -1
  6. package/examples/plain-markdown/docs/Miscellaneous/ns.BaseClass.md +1 -1
  7. package/examples/plain-markdown/docs/Miscellaneous/ns.MultiInheritanceClass.md +1 -1
  8. package/examples/plain-markdown/docs/Miscellaneous/ns.ParentInterface.md +1 -1
  9. package/examples/plain-markdown/docs/Miscellaneous/ns.ReferencedEnum.md +1 -1
  10. package/examples/plain-markdown/docs/Miscellaneous/ns.SampleException.md +1 -1
  11. package/examples/plain-markdown/docs/Miscellaneous/ns.SampleInterface.md +1 -1
  12. package/examples/plain-markdown/docs/Miscellaneous/ns.Url.md +1 -1
  13. package/examples/plain-markdown/docs/Sample-Enums/ns.SampleEnum.md +1 -1
  14. package/examples/plain-markdown/docs/SampleGroup/ns.SampleClass.md +1 -1
  15. package/examples/plain-markdown/docs/index.md +1 -1
  16. package/examples/plain-markdown/package.json +3 -4
  17. package/examples/vitepress/.forceignore +12 -0
  18. package/examples/vitepress/apexdocs.config.ts +108 -0
  19. package/examples/vitepress/config/project-scratch-def.json +13 -0
  20. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js +259 -0
  21. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
  22. package/examples/vitepress/docs/.vitepress/cache/deps/_metadata.json +40 -0
  23. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js +11474 -0
  24. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js.map +7 -0
  25. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js +9172 -0
  26. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js.map +7 -0
  27. package/examples/vitepress/docs/.vitepress/cache/deps/package.json +3 -0
  28. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4339 -0
  29. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  30. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +567 -0
  31. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  32. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js +323 -0
  33. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js.map +7 -0
  34. package/examples/vitepress/docs/.vitepress/config.mts +21 -0
  35. package/examples/vitepress/docs/.vitepress/sidebar.json +119 -0
  36. package/examples/vitepress/docs/Miscellaneous/apexdocs.BaseClass.md +20 -0
  37. package/examples/vitepress/docs/Miscellaneous/apexdocs.MultiInheritanceClass.md +78 -0
  38. package/examples/vitepress/docs/Miscellaneous/apexdocs.ParentInterface.md +19 -0
  39. package/examples/vitepress/docs/Miscellaneous/apexdocs.ReferencedEnum.md +15 -0
  40. package/examples/vitepress/docs/Miscellaneous/apexdocs.SampleException.md +28 -0
  41. package/examples/vitepress/docs/Miscellaneous/apexdocs.SampleInterface.md +122 -0
  42. package/examples/vitepress/docs/Miscellaneous/apexdocs.Url.md +318 -0
  43. package/examples/vitepress/docs/Sample-Enums/apexdocs.SampleEnum.md +41 -0
  44. package/examples/vitepress/docs/SampleGroup/apexdocs.SampleClass.md +178 -0
  45. package/examples/vitepress/docs/api-examples.md +49 -0
  46. package/examples/vitepress/docs/index-frontmatter.md +16 -0
  47. package/examples/vitepress/docs/index.md +127 -0
  48. package/examples/vitepress/docs/markdown-examples.md +85 -0
  49. package/examples/vitepress/force-app/main/default/classes/BaseClass.cls +3 -0
  50. package/examples/vitepress/force-app/main/default/classes/MultiInheritanceClass.cls +1 -0
  51. package/examples/vitepress/force-app/main/default/classes/ParentInterface.cls +3 -0
  52. package/examples/vitepress/force-app/main/default/classes/ReferencedEnum.cls +5 -0
  53. package/examples/vitepress/force-app/main/default/classes/SampleClass.cls +72 -0
  54. package/examples/vitepress/force-app/main/default/classes/SampleEnum.cls +30 -0
  55. package/examples/vitepress/force-app/main/default/classes/SampleException.cls +17 -0
  56. package/examples/vitepress/force-app/main/default/classes/SampleInterface.cls +46 -0
  57. package/examples/vitepress/force-app/main/default/classes/Url.cls +195 -0
  58. package/examples/vitepress/package-lock.json +2574 -0
  59. package/examples/vitepress/package.json +18 -0
  60. package/examples/vitepress/sfdx-project.json +12 -0
  61. package/jest.config.js +1 -0
  62. package/package.json +10 -6
  63. package/src/application/Apexdocs.ts +16 -104
  64. package/src/application/__tests__/apex-file-reader.spec.ts +104 -0
  65. package/src/application/apex-file-reader.ts +42 -0
  66. package/src/application/file-writer.ts +25 -0
  67. package/src/application/generators/markdown.ts +53 -0
  68. package/src/application/generators/openapi.ts +56 -0
  69. package/src/cli/args.ts +17 -112
  70. package/src/cli/commands/markdown.ts +58 -0
  71. package/src/cli/generate.ts +7 -5
  72. package/src/{model/__tests__ → core/__test__}/manifest.spec.ts +1 -1
  73. package/src/core/manifest.ts +57 -51
  74. package/src/{__spec__/core → core/markdown/__test__}/expect-extensions.ts +5 -5
  75. package/src/core/markdown/__test__/generating-class-docs.spec.ts +727 -0
  76. package/src/{__spec__/core → core/markdown/__test__}/generating-enum-docs.spec.ts +82 -59
  77. package/src/{__spec__/core → core/markdown/__test__}/generating-interface-docs.spec.ts +94 -75
  78. package/src/core/markdown/__test__/generating-reference-guide.spec.ts +184 -0
  79. package/src/core/{__test__ → markdown/__test__}/inheritance-chain.test.ts +2 -2
  80. package/src/core/markdown/__test__/test-helpers.ts +22 -0
  81. package/src/core/{adapters → markdown/adapters}/__tests__/interface-adapter.spec.ts +38 -8
  82. package/src/core/{adapters → markdown/adapters}/apex-types.ts +7 -4
  83. package/src/core/{adapters → markdown/adapters}/inline.ts +1 -1
  84. package/src/core/markdown/adapters/renderable-bundle.ts +144 -0
  85. package/src/core/markdown/adapters/renderable-to-page-data.ts +92 -0
  86. package/src/core/{adapters → markdown/adapters}/types.d.ts +16 -2
  87. package/src/core/markdown/generate-docs.ts +158 -0
  88. package/src/core/markdown/reflection/error-handling.ts +37 -0
  89. package/src/core/markdown/reflection/filter-scope.ts +13 -0
  90. package/src/core/markdown/reflection/inheritance-chain-expanion.ts +22 -0
  91. package/src/core/markdown/reflection/inherited-member-expansion.ts +105 -0
  92. package/src/core/markdown/reflection/reflect-source.ts +41 -0
  93. package/src/core/markdown/reflection/sort-members.ts +59 -0
  94. package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/class-template.ts +2 -0
  95. package/src/core/markdown/templates/hookable.ts +7 -0
  96. package/src/core/{template.ts → markdown/templates/template.ts} +12 -12
  97. package/src/core/markdown/utils.ts +3 -0
  98. package/src/{transpiler → core}/openapi/__tests__/open-api-docs-processor.spec.ts +1 -1
  99. package/src/{model → core/openapi}/apex-type-wrappers/__tests__/ClassMirrorWrapper.spec.ts +3 -3
  100. package/src/core/openapi/file-container.ts +13 -0
  101. package/src/{service → core/openapi}/manifest-factory.ts +3 -3
  102. package/src/{transpiler → core}/openapi/open-api-docs-processor.ts +9 -10
  103. package/src/core/openapi/openapi-type-file.ts +14 -0
  104. package/src/{service → core/openapi}/parser.ts +8 -8
  105. package/src/{transpiler → core}/openapi/parsers/Builder.ts +2 -2
  106. package/src/{transpiler → core}/openapi/parsers/MethodParser.ts +5 -5
  107. package/src/{transpiler → core}/openapi/parsers/ParameterObjectBuilder.ts +2 -2
  108. package/src/{transpiler → core}/openapi/parsers/ReferenceBuilder.ts +3 -3
  109. package/src/{transpiler → core}/openapi/parsers/RequestBodyBuilder.ts +2 -2
  110. package/src/{transpiler → core}/openapi/parsers/ResponsesBuilder.ts +2 -2
  111. package/src/{transpiler → core}/openapi/parsers/__tests__/MethodParser.spec.ts +1 -1
  112. package/src/{transpiler → core}/openapi/parsers/__tests__/ParameterObjectBuilder.spec.ts +2 -2
  113. package/src/{transpiler → core}/openapi/parsers/__tests__/ReferenceBuilder.spec.ts +2 -2
  114. package/src/{transpiler → core}/openapi/parsers/__tests__/RequestBodyBuilder.spec.ts +2 -2
  115. package/src/{transpiler → core}/openapi/parsers/__tests__/ResponsesBuilder.spec.ts +1 -1
  116. package/src/{transpiler → core/openapi}/transpiler.ts +2 -6
  117. package/src/{model → core/openapi}/types-repository.ts +0 -9
  118. package/src/core/parse-apex-metadata.ts +14 -0
  119. package/src/core/settings.ts +56 -0
  120. package/src/core/shared/types.d.ts +92 -0
  121. package/src/core/shared/utils.ts +5 -0
  122. package/src/defaults.ts +8 -0
  123. package/src/index.ts +34 -2
  124. package/src/test-helpers/InterfaceMirrorBuilder.ts +0 -5
  125. package/src/test-helpers/SettingsBuilder.ts +1 -3
  126. package/src/util/logger.ts +2 -2
  127. package/src/util/string-utils.ts +0 -4
  128. package/tsconfig.json +5 -1
  129. package/apexdocs.config.ts +0 -13
  130. package/examples/plain-markdown/template.md +0 -3
  131. package/src/__spec__/core/generating-class-docs.spec.ts +0 -531
  132. package/src/__spec__/core/generating-reference-guide.spec.ts +0 -164
  133. package/src/__spec__/core/test-helpers.ts +0 -9
  134. package/src/application/generators/generate-markdown-files.ts +0 -53
  135. package/src/core/apex-bundle.ts +0 -3
  136. package/src/core/generate-docs.ts +0 -432
  137. package/src/model/markdown-file.ts +0 -122
  138. package/src/model/markdown-generation-util/doc-comment-annotation-util.ts +0 -50
  139. package/src/model/markdown-generation-util/field-declaration-util.ts +0 -71
  140. package/src/model/markdown-generation-util/index.ts +0 -3
  141. package/src/model/markdown-generation-util/method-declaration-util.ts +0 -166
  142. package/src/model/markdown-generation-util/type-declaration-util.ts +0 -91
  143. package/src/model/markdown-home-file.ts +0 -58
  144. package/src/model/markdown-type-file.ts +0 -169
  145. package/src/model/openapi/openapi-type-file.ts +0 -14
  146. package/src/model/outputFile.ts +0 -20
  147. package/src/service/__tests__/apex-file-reader.spec.ts +0 -93
  148. package/src/service/apex-file-reader.ts +0 -47
  149. package/src/service/file-writer.ts +0 -34
  150. package/src/service/metadata-processor.ts +0 -16
  151. package/src/service/state.ts +0 -24
  152. package/src/service/walkers/class-walker.ts +0 -30
  153. package/src/service/walkers/enum-walker.ts +0 -7
  154. package/src/service/walkers/interface-walker.ts +0 -12
  155. package/src/service/walkers/walker-factory.ts +0 -19
  156. package/src/service/walkers/walker.ts +0 -42
  157. package/src/settings.ts +0 -143
  158. package/src/transpiler/factory.ts +0 -31
  159. package/src/transpiler/file-container.ts +0 -13
  160. package/src/transpiler/generator-choices.ts +0 -1
  161. package/src/transpiler/markdown/class-file-generatorHelper.ts +0 -61
  162. package/src/transpiler/markdown/docsify/docsify-docs-processor.ts +0 -12
  163. package/src/transpiler/markdown/jekyll/jekyll-docsProcessor.ts +0 -50
  164. package/src/transpiler/markdown/markdown-transpiler-base.ts +0 -28
  165. package/src/transpiler/processor-type-transpiler.ts +0 -18
  166. /package/src/{service → application}/file-system.ts +0 -0
  167. /package/src/core/{adapters → markdown/adapters}/__tests__/documentables.spec.ts +0 -0
  168. /package/src/core/{adapters → markdown/adapters}/__tests__/references.spec.ts +0 -0
  169. /package/src/core/{adapters → markdown/adapters}/documentables.ts +0 -0
  170. /package/src/core/{adapters → markdown/adapters}/fields-and-properties.ts +0 -0
  171. /package/src/core/{adapters → markdown/adapters}/methods-and-constructors.ts +0 -0
  172. /package/src/core/{adapters → markdown/adapters}/type-utils.ts +0 -0
  173. /package/src/core/{inheritance-chain.ts → markdown/reflection/inheritance-chain.ts} +0 -0
  174. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/constructors-partial-template.ts +0 -0
  175. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/documentable-partial-template.ts +0 -0
  176. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/enum-template.ts +0 -0
  177. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/fieldsPartialTemplate.ts +0 -0
  178. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/grouped-members-partial-template.ts +0 -0
  179. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/interface-template.ts +0 -0
  180. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/methods-partial-template.ts +0 -0
  181. /package/src/core/{templates → markdown/templates}/reference-guide.ts +0 -0
  182. /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/type-doc-partial.ts +0 -0
  183. /package/src/{service → core/openapi}/__tests__/manifest-factory.spec.ts +0 -0
  184. /package/src/{model → core}/openapi/__tests__/open-api.spec.ts +0 -0
  185. /package/src/{model → core}/openapi/apex-doc-types.ts +0 -0
  186. /package/src/{model → core/openapi}/apex-type-wrappers/ClassMirrorWrapper.ts +0 -0
  187. /package/src/{model → core/openapi}/apex-type-wrappers/MethodMirrorWrapper.ts +0 -0
  188. /package/src/{model → core}/openapi/open-api-types.ts +0 -0
  189. /package/src/{model → core}/openapi/open-api.ts +0 -0
@@ -1,71 +0,0 @@
1
- import { MarkdownFile } from '../markdown-file';
2
- import { FieldMirrorWithInheritance, FieldOrProperty, PropertyMirrorWithInheritance } from '../../core/adapters/types';
3
-
4
- export function declareField(
5
- markdownFile: MarkdownFile,
6
- fields: FieldMirrorWithInheritance[] | PropertyMirrorWithInheritance[],
7
- startingHeadingLevel: number,
8
- grouped = false,
9
- ) {
10
- markdownFile.addBlankLine();
11
- fields.forEach((propertyModel) => {
12
- addFieldSection(markdownFile, propertyModel, startingHeadingLevel, grouped);
13
- });
14
-
15
- markdownFile.addHorizontalRule();
16
- }
17
-
18
- function addFieldSection(
19
- markdownFile: MarkdownFile,
20
- mirrorModel: FieldOrProperty,
21
- startingHeadingLevel: number,
22
- grouped: boolean,
23
- ) {
24
- if (!grouped) {
25
- markdownFile.addTitle(
26
- `\`${mirrorModel.access_modifier} ${mirrorModel.name}\` → \`${mirrorModel.typeReference.rawDeclaration}\``,
27
- startingHeadingLevel + 2,
28
- );
29
- markdownFile.addBlankLine();
30
- if (mirrorModel.inherited) {
31
- markdownFile.addText('*Inherited*');
32
- }
33
-
34
- mirrorModel.annotations.forEach((annotation) => {
35
- markdownFile.addText(`\`${annotation.type.toUpperCase()}\` `);
36
- });
37
-
38
- if (mirrorModel.docComment?.description) {
39
- markdownFile.addBlankLine();
40
- markdownFile.addText(mirrorModel.docComment.description);
41
- }
42
- markdownFile.addBlankLine();
43
- } else {
44
- let annotations = '';
45
- const hasAnnotations = !!mirrorModel.annotations.length;
46
- if (hasAnnotations) {
47
- annotations += ' [';
48
- }
49
- mirrorModel.annotations.forEach((annotation) => {
50
- annotations += `\`${annotation.type.toUpperCase()}\` `;
51
- });
52
- if (hasAnnotations) {
53
- annotations += ']';
54
- }
55
-
56
- // If grouped we want to display these as a list
57
- let description = '';
58
- if (mirrorModel.docComment?.description) {
59
- description = ` - ${mirrorModel.docComment?.description}`;
60
- }
61
-
62
- let listItemText = `\`${mirrorModel.access_modifier} ${mirrorModel.name}\` → \`${mirrorModel.typeReference.rawDeclaration}\``;
63
- if (mirrorModel.inherited) {
64
- listItemText += '(*Inherited*)';
65
- }
66
- listItemText += `${annotations} ${description}`;
67
-
68
- markdownFile.addListItem(listItemText);
69
- markdownFile.addBlankLine();
70
- }
71
- }
@@ -1,3 +0,0 @@
1
- export * from './type-declaration-util';
2
- export * from './method-declaration-util';
3
- export * from './field-declaration-util';
@@ -1,166 +0,0 @@
1
- import { ConstructorMirror, DocComment } from '@cparra/apex-reflection';
2
- import { MarkdownFile } from '../markdown-file';
3
- import { ParameterMirror } from '@cparra/apex-reflection';
4
- import { addCustomDocCommentAnnotations, addMermaid } from './doc-comment-annotation-util';
5
- import { MethodMirrorWithInheritance } from '../../core/adapters/types';
6
-
7
- export function declareMethod(
8
- markdownFile: MarkdownFile,
9
- methods: ConstructorMirror[] | MethodMirrorWithInheritance[],
10
- startingHeadingLevel: number,
11
- className = '',
12
- ): void {
13
- methods.forEach((currentMethod) => {
14
- const signatureName = isMethod(currentMethod)
15
- ? `${(currentMethod as MethodMirrorWithInheritance).typeReference.rawDeclaration} ${
16
- (currentMethod as MethodMirrorWithInheritance).name
17
- }`
18
- : className;
19
-
20
- markdownFile.addTitle(
21
- `\`${buildSignature(currentMethod.access_modifier, signatureName, currentMethod)}\``,
22
- startingHeadingLevel + 2,
23
- );
24
-
25
- // Inheritance tag
26
- if (isMethod(currentMethod)) {
27
- const asMethodMirror = currentMethod as MethodMirrorWithInheritance;
28
- if (asMethodMirror.inherited) {
29
- markdownFile.addBlankLine();
30
- markdownFile.addText('*Inherited*');
31
- markdownFile.addBlankLine();
32
- }
33
- }
34
-
35
- currentMethod.annotations.forEach((annotation) => {
36
- markdownFile.addBlankLine();
37
- markdownFile.addText(`\`${annotation.type.toUpperCase()}\``);
38
- });
39
-
40
- if (currentMethod.docComment?.description) {
41
- markdownFile.addBlankLine();
42
- markdownFile.addText(currentMethod.docComment.description);
43
- markdownFile.addBlankLine();
44
- }
45
-
46
- if (currentMethod.parameters.length) {
47
- addParameters(markdownFile, currentMethod, startingHeadingLevel);
48
- }
49
-
50
- if (isMethod(currentMethod)) {
51
- addReturns(markdownFile, currentMethod as MethodMirrorWithInheritance, startingHeadingLevel);
52
- }
53
-
54
- addThrowsBlock(markdownFile, currentMethod, startingHeadingLevel);
55
-
56
- addCustomDocCommentAnnotations(markdownFile, currentMethod);
57
-
58
- addMermaid(markdownFile, currentMethod);
59
-
60
- if (currentMethod.docComment?.exampleAnnotation) {
61
- addExample(markdownFile, currentMethod, startingHeadingLevel);
62
- }
63
- });
64
-
65
- markdownFile.addHorizontalRule();
66
- }
67
-
68
- type ParameterAware = {
69
- parameters: ParameterMirror[];
70
- };
71
-
72
- type DocCommentAware = {
73
- docComment?: DocComment;
74
- };
75
-
76
- function buildSignature(accessModifier: string, name: string, parameterAware: ParameterAware): string {
77
- let signature = `${name}(`;
78
- if (isMethod(parameterAware) && (parameterAware as MethodMirrorWithInheritance).memberModifiers.length) {
79
- signature =
80
- accessModifier +
81
- ' ' +
82
- (parameterAware as MethodMirrorWithInheritance).memberModifiers.join(' ') +
83
- ' ' +
84
- signature;
85
- } else {
86
- signature = accessModifier + ' ' + signature;
87
- }
88
- const signatureParameters = parameterAware.parameters.map(
89
- (param) => `${param.typeReference.rawDeclaration} ${param.name}`,
90
- );
91
- signature += signatureParameters.join(', ');
92
- return `${signature})`;
93
- }
94
-
95
- function addParameters(
96
- markdownFile: MarkdownFile,
97
- methodModel: MethodMirrorWithInheritance | ConstructorMirror,
98
- startingHeadingLevel: number,
99
- ) {
100
- if (!methodModel.docComment?.paramAnnotations.length) {
101
- // If there are no parameters defined in the docs then we don't want to display this section
102
- return;
103
- }
104
-
105
- markdownFile.addTitle('Parameters', startingHeadingLevel + 3);
106
- markdownFile.initializeTable('Param', 'Description');
107
-
108
- methodModel.docComment?.paramAnnotations.forEach((paramAnnotation) => {
109
- const paramName = paramAnnotation.paramName;
110
- const paramDescription = paramAnnotation.bodyLines.join(' ');
111
- markdownFile.addTableRow(`\`${paramName}\``, paramDescription);
112
- });
113
-
114
- markdownFile.addBlankLine();
115
- }
116
-
117
- function addReturns(
118
- markdownFile: MarkdownFile,
119
- methodModel: MethodMirrorWithInheritance,
120
- startingHeadingLevel: number,
121
- ) {
122
- if (!methodModel.docComment?.returnAnnotation) {
123
- return;
124
- }
125
-
126
- markdownFile.addTitle('Returns', startingHeadingLevel + 3);
127
- markdownFile.initializeTable('Type', 'Description');
128
- markdownFile.addTableRow(
129
- `\`${methodModel.typeReference.rawDeclaration}\``,
130
- methodModel.docComment?.returnAnnotation.bodyLines.join(' '),
131
- );
132
- markdownFile.addBlankLine();
133
- }
134
-
135
- function addThrowsBlock(markdownFile: MarkdownFile, docCommentAware: DocCommentAware, startingHeadingLevel: number) {
136
- if (!docCommentAware.docComment?.throwsAnnotations.length) {
137
- return;
138
- }
139
- markdownFile.addTitle('Throws', startingHeadingLevel + 3);
140
- markdownFile.initializeTable('Exception', 'Description');
141
-
142
- docCommentAware.docComment?.throwsAnnotations.forEach((annotation) => {
143
- const exceptionName = annotation.exceptionName;
144
- const exceptionDescription = annotation.bodyLines.join(' ');
145
-
146
- markdownFile.addTableRow(`\`${exceptionName}\``, exceptionDescription);
147
- });
148
-
149
- markdownFile.addBlankLine();
150
- }
151
-
152
- function addExample(markdownFile: MarkdownFile, docCommentAware: DocCommentAware, startingHeadingLevel: number) {
153
- markdownFile.addTitle('Example', startingHeadingLevel + 3);
154
- markdownFile.startCodeBlock();
155
- docCommentAware.docComment?.exampleAnnotation.bodyLines.forEach((line) => {
156
- markdownFile.addText(line);
157
- });
158
- markdownFile.endCodeBlock();
159
- markdownFile.addBlankLine();
160
- }
161
-
162
- function isMethod(
163
- method: MethodMirrorWithInheritance | ConstructorMirror | ParameterAware,
164
- ): method is MethodMirrorWithInheritance {
165
- return (method as MethodMirrorWithInheritance).typeReference !== undefined;
166
- }
@@ -1,91 +0,0 @@
1
- import { MarkdownFile } from '../markdown-file';
2
- import { addCustomDocCommentAnnotations, addMermaid } from './doc-comment-annotation-util';
3
- import { Annotation, ClassMirror, InterfaceMirror, Type } from '@cparra/apex-reflection';
4
- import { TypesRepository } from '../types-repository';
5
-
6
- export function declareType(markdownFile: MarkdownFile, typeMirror: Type): void {
7
- typeMirror.annotations.forEach((currentAnnotation: Annotation) => {
8
- markdownFile.addBlankLine();
9
- markdownFile.addText(`\`${currentAnnotation.type.toUpperCase()}\``);
10
- });
11
-
12
- if (typeMirror.docComment?.descriptionLines) {
13
- markdownFile.addBlankLine();
14
- for (const currentLine of typeMirror.docComment.descriptionLines) {
15
- markdownFile.addText(currentLine);
16
- }
17
- markdownFile.addBlankLine();
18
- }
19
-
20
- if (typeMirror.type_name === 'class') {
21
- addInheritanceSectionForClass(typeMirror, markdownFile);
22
- }
23
-
24
- if (typeMirror.type_name === 'interface') {
25
- addInheritanceSectionForInterface(typeMirror, markdownFile);
26
- }
27
-
28
- addCustomDocCommentAnnotations(markdownFile, typeMirror);
29
-
30
- addMermaid(markdownFile, typeMirror);
31
- }
32
-
33
- function addInheritanceSectionForClass(typeMirror: Type, markdownFile: MarkdownFile) {
34
- const typeAsClass = typeMirror as ClassMirror;
35
- if (typeAsClass.extended_class) {
36
- markdownFile.addBlankLine();
37
- markdownFile.addText('**Inheritance**');
38
- markdownFile.addBlankLine();
39
- addParent(markdownFile, typeAsClass);
40
- markdownFile.addText(typeMirror.name);
41
- markdownFile.addBlankLine();
42
- }
43
-
44
- if (typeAsClass.implemented_interfaces.length) {
45
- markdownFile.addBlankLine();
46
- markdownFile.addText('**Implemented types**');
47
- markdownFile.addBlankLine();
48
- for (let i = 0; i < typeAsClass.implemented_interfaces.length; i++) {
49
- const currentName = typeAsClass.implemented_interfaces[i];
50
- markdownFile.addLink(currentName);
51
- if (i < typeAsClass.implemented_interfaces.length - 1) {
52
- markdownFile.addText(', ');
53
- }
54
- }
55
- markdownFile.addBlankLine();
56
- }
57
- }
58
-
59
- function addInheritanceSectionForInterface(typeMirror: Type, markdownFile: MarkdownFile) {
60
- const typeAsInterface = typeMirror as InterfaceMirror;
61
- if (typeAsInterface.extended_interfaces.length) {
62
- markdownFile.addBlankLine();
63
- markdownFile.addText('**Extended types**');
64
- markdownFile.addBlankLine();
65
- for (let i = 0; i < typeAsInterface.extended_interfaces.length; i++) {
66
- const currentName = typeAsInterface.extended_interfaces[i];
67
- markdownFile.addLink(currentName);
68
- if (i < typeAsInterface.extended_interfaces.length - 1) {
69
- markdownFile.addText(', ');
70
- }
71
- }
72
- }
73
- }
74
-
75
- function addParent(markdownFile: MarkdownFile, classMirror: ClassMirror) {
76
- if (!classMirror.extended_class) {
77
- return;
78
- }
79
-
80
- const parentType = TypesRepository.getInstance().getFromScopedByName(classMirror.extended_class);
81
- if (!parentType) {
82
- return;
83
- }
84
-
85
- if (parentType.type_name === 'class') {
86
- addParent(markdownFile, parentType as ClassMirror);
87
- }
88
-
89
- markdownFile.addLink(parentType.name);
90
- markdownFile.addText(' > ');
91
- }
@@ -1,58 +0,0 @@
1
- import { Type } from '@cparra/apex-reflection';
2
- import ClassFileGeneratorHelper from '../transpiler/markdown/class-file-generatorHelper';
3
- import { MarkdownFile } from './markdown-file';
4
- import { truncate } from '../util/string-utils';
5
- import { Settings } from '../settings';
6
-
7
- export class MarkdownHomeFile extends MarkdownFile {
8
- constructor(public fileName: string, public types: Type[], headerContent?: string) {
9
- super(fileName, '');
10
- if (headerContent) {
11
- this.addText(headerContent);
12
- }
13
- this.addTitle(Settings.getInstance().getTitle());
14
- this.addTypeEntries(types);
15
- }
16
-
17
- private addTypeEntries(types: Type[]) {
18
- const groupedClasses: Map<string, Type[]> = this.group(types);
19
- groupedClasses.forEach((value: Type[], key: string) => {
20
- this.addTitle(key, 2);
21
- value.forEach((typeMirror) => {
22
- this.addTypeEntry(typeMirror);
23
- });
24
- });
25
- }
26
-
27
- private addTypeEntry(typeMirror: Type) {
28
- this.addBlankLine();
29
- this.addTitle(ClassFileGeneratorHelper.getFileLink(typeMirror), 3);
30
- this.addBlankLine();
31
-
32
- if (typeMirror.docComment?.descriptionLines) {
33
- const description = typeMirror.docComment.descriptionLines.reduce(
34
- (previous, current) => previous + current + '\n',
35
- '',
36
- );
37
- this.addText(truncate(description, 300));
38
- this.addBlankLine();
39
- }
40
- }
41
-
42
- private group(classes: Type[]): Map<string, Type[]> {
43
- return classes.reduce((groups, currentClass) => {
44
- const key = this.getClassGroup(currentClass);
45
- const group: Type[] = groups.get(key) || [];
46
- group.push(currentClass);
47
- groups.set(key, group);
48
- return groups;
49
- }, new Map());
50
- }
51
-
52
- private getClassGroup(classModel: Type): string {
53
- return (
54
- classModel.docComment?.annotations.find((annotation) => annotation.name === 'group')?.body ??
55
- Settings.getInstance().getDefaultGroupName()
56
- );
57
- }
58
- }
@@ -1,169 +0,0 @@
1
- import {
2
- ClassMirror,
3
- ConstructorMirror,
4
- EnumMirror,
5
- InterfaceMirror,
6
- MethodMirror,
7
- Type,
8
- } from '@cparra/apex-reflection';
9
- import { WalkerFactory } from '../service/walkers/walker-factory';
10
- import { WalkerListener } from '../service/walkers/walker';
11
- import { MarkdownFile } from './markdown-file';
12
- import { declareType, declareMethod, declareField } from './markdown-generation-util';
13
- import ClassFileGeneratorHelper from '../transpiler/markdown/class-file-generatorHelper';
14
- import { Settings } from '../settings';
15
- import {
16
- FieldMirrorWithInheritance,
17
- MethodMirrorWithInheritance,
18
- PropertyMirrorWithInheritance
19
- } from '../core/adapters/types';
20
-
21
- interface GroupAware {
22
- group?: string;
23
- groupDescription?: string;
24
- }
25
-
26
- interface GroupMap {
27
- [key: string]: GroupAware[];
28
- }
29
-
30
- export class MarkdownTypeFile extends MarkdownFile implements WalkerListener {
31
- constructor(private type: Type, private headingLevel: number = 1, headerContent?: string, private isInner = false) {
32
- super(
33
- `${Settings.getInstance().getNamespacePrefix()}${type.name}`,
34
- ClassFileGeneratorHelper.getSanitizedGroup(type),
35
- );
36
- if (headerContent) {
37
- this.addText(headerContent);
38
- }
39
- const walker = WalkerFactory.get(type);
40
- walker.walk(this);
41
- }
42
-
43
- public onTypeDeclaration(typeMirror: Type): void {
44
- let fullTypeName;
45
- if (this.isInner) {
46
- fullTypeName = typeMirror.name;
47
- } else {
48
- // If we are dealing with a class, we want to check if it has a class
49
- // modifier and add it to the name.
50
- if (this.isClass(typeMirror) && typeMirror.classModifier) {
51
- fullTypeName = `${typeMirror.classModifier} ${Settings.getInstance().getNamespacePrefix()}${typeMirror.name}`;
52
- } else {
53
- fullTypeName = `${Settings.getInstance().getNamespacePrefix()}${typeMirror.name}`;
54
- }
55
- }
56
- this.addTitle(fullTypeName, this.headingLevel);
57
- declareType(this, typeMirror);
58
- }
59
-
60
- private isClass(typeMirror: Type): typeMirror is ClassMirror {
61
- return typeMirror.type_name === 'class';
62
- }
63
-
64
- public onConstructorDeclaration(className: string, constructors: ConstructorMirror[]): void {
65
- this.addTitle('Constructors', this.headingLevel + 1);
66
- this.declareMethodWithGroupings(constructors, className);
67
- }
68
-
69
- public onFieldsDeclaration(fields: FieldMirrorWithInheritance[]): void {
70
- this.addTitle('Fields', this.headingLevel + 1);
71
- this.declareFieldOrProperty(fields);
72
- }
73
-
74
- public onPropertiesDeclaration(properties: PropertyMirrorWithInheritance[]): void {
75
- this.addTitle('Properties', this.headingLevel + 1);
76
- this.declareFieldOrProperty(properties);
77
- }
78
-
79
- public onMethodsDeclaration(methods: MethodMirror[]): void {
80
- this.addTitle('Methods', this.headingLevel + 1);
81
- this.declareMethodWithGroupings(methods);
82
- }
83
-
84
- public onInnerEnumsDeclaration(enums: EnumMirror[]): void {
85
- this.addInnerTypes('Enums', enums);
86
- }
87
-
88
- public onInnerClassesDeclaration(classes: ClassMirror[]): void {
89
- this.addInnerTypes('Classes', classes);
90
- }
91
-
92
- public onInnerInterfacesDeclaration(interfaces: InterfaceMirror[]): void {
93
- this.addInnerTypes('Interfaces', interfaces, false);
94
- }
95
-
96
- private addInnerTypes(title: string, types: Type[], addSeparator = true) {
97
- this.addTitle(title, this.headingLevel + 1);
98
- types.forEach((currentType) => {
99
- const innerFile = new MarkdownTypeFile(currentType, this.headingLevel + 2, undefined, true);
100
- this.addText(innerFile._contents);
101
- });
102
- if (addSeparator) {
103
- this.addHorizontalRule();
104
- }
105
- }
106
-
107
- private hasGroupings(groupAware: GroupAware[]): boolean {
108
- return !!groupAware.find((current) => !!current.group);
109
- }
110
-
111
- private declareMethodWithGroupings(
112
- methods: ConstructorMirror[] | MethodMirrorWithInheritance[],
113
- className = '',
114
- ): void {
115
- const hasGroupings = this.hasGroupings(methods);
116
- if (!hasGroupings) {
117
- declareMethod(this, methods, this.headingLevel, className);
118
- } else {
119
- const groupedConstructors = this.group(methods);
120
- for (const key in groupedConstructors) {
121
- // For the group description, we can take the first one, since they all have the same description.
122
- this.startGroup(key, groupedConstructors[key][0].groupDescription);
123
- const constructorsForGroup = groupedConstructors[key] as (ConstructorMirror | MethodMirrorWithInheritance)[];
124
- declareMethod(this, constructorsForGroup, this.headingLevel, className);
125
- this.endGroup();
126
- }
127
- }
128
- }
129
-
130
- private declareFieldOrProperty(
131
- fieldsOrProperties: FieldMirrorWithInheritance[] | PropertyMirrorWithInheritance[],
132
- ): void {
133
- const hasGroupings = this.hasGroupings(fieldsOrProperties);
134
- if (!hasGroupings) {
135
- declareField(this, fieldsOrProperties, this.headingLevel, false);
136
- } else {
137
- const groupedFields = this.group(fieldsOrProperties);
138
- for (const key in groupedFields) {
139
- // For the group description, we can take the first one, since they all have the same description.
140
- this.startGroup(key, groupedFields[key][0].groupDescription);
141
- const fieldsForGroup = groupedFields[key] as (FieldMirrorWithInheritance | PropertyMirrorWithInheritance)[];
142
- declareField(this, fieldsForGroup, this.headingLevel, true);
143
- this.endGroup();
144
- }
145
- }
146
- }
147
-
148
- private startGroup(groupName: string, groupDescription?: string) {
149
- this.headingLevel = this.headingLevel + 2;
150
- this.addTitle(groupName, this.headingLevel);
151
- if (groupDescription) {
152
- this.addText(groupDescription);
153
- }
154
- }
155
-
156
- private endGroup() {
157
- this.headingLevel = this.headingLevel - 2;
158
- }
159
-
160
- private group(list: GroupAware[]) {
161
- return list.reduce((groups: GroupMap, item) => {
162
- const groupName: string = item.group ?? 'Other';
163
- const group: GroupAware[] = groups[groupName] || [];
164
- group.push(item);
165
- groups[groupName] = group;
166
- return groups;
167
- }, {});
168
- }
169
- }
@@ -1,14 +0,0 @@
1
- import { OutputFile } from '../outputFile';
2
- import { OpenApi } from './open-api';
3
- import { Settings } from '../../settings';
4
-
5
- export class OpenapiTypeFile extends OutputFile {
6
- constructor(public openApiModel: OpenApi) {
7
- super(Settings.getInstance().openApiFileName(), '');
8
- this.addText(JSON.stringify({ ...openApiModel, namespace: undefined }, null, 2));
9
- }
10
-
11
- fileExtension(): string {
12
- return '.json';
13
- }
14
- }
@@ -1,20 +0,0 @@
1
- export abstract class OutputFile {
2
- _contents = '';
3
-
4
- constructor(public fileName: string, public dir: string) {}
5
-
6
- abstract fileExtension(): string;
7
-
8
- get body() {
9
- return this._contents;
10
- }
11
-
12
- addText(text: string) {
13
- this._contents += text;
14
- this.addBlankLine();
15
- }
16
-
17
- addBlankLine() {
18
- this._contents += '\n';
19
- }
20
- }
@@ -1,93 +0,0 @@
1
- import { Settings, SettingsConfig } from '../../settings';
2
- import { ApexFileReader } from '../apex-file-reader';
3
-
4
- describe('File Reader', () => {
5
- beforeEach(() => {
6
- Settings.build({
7
- sourceDirectory: '',
8
- recursive: true,
9
- scope: [],
10
- outputDir: '',
11
- targetGenerator: 'jekyll',
12
- indexOnly: false,
13
- defaultGroupName: 'Misc',
14
- sanitizeHtml: true,
15
- openApiFileName: 'openapi',
16
- title: 'Classes',
17
- includeMetadata: false,
18
- linkingStrategy: 'root-relative',
19
- } as SettingsConfig);
20
- });
21
-
22
- it('returns an empty list when there are no files in the directory', () => {
23
- const result = ApexFileReader.processFiles({
24
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
25
- isDirectory(_: string): boolean {
26
- return false;
27
- },
28
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
29
- joinPath(_: string): string {
30
- return '';
31
- },
32
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
33
- readDirectory(_: string): string[] {
34
- return [];
35
- },
36
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
37
- readFile(_: string): string {
38
- return '';
39
- },
40
- exists(): boolean {
41
- return true;
42
- },
43
- });
44
- expect(result.length).toBe(0);
45
- });
46
-
47
- it('returns an empty list when there are no Apex files in the directory', () => {
48
- const result = ApexFileReader.processFiles({
49
- isDirectory(): boolean {
50
- return false;
51
- },
52
- joinPath(): string {
53
- return '';
54
- },
55
- readDirectory(): string[] {
56
- return ['SomeFile.md'];
57
- },
58
- readFile(): string {
59
- return '';
60
- },
61
- exists(): boolean {
62
- return true;
63
- },
64
- });
65
- expect(result.length).toBe(0);
66
- });
67
-
68
- it('returns the file contents for an Apex file', () => {
69
- const result = ApexFileReader.processFiles({
70
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
- isDirectory(_: string): boolean {
72
- return false;
73
- },
74
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
- joinPath(_: string): string {
76
- return '';
77
- },
78
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
79
- readDirectory(_: string): string[] {
80
- return ['SomeApexFile.cls'];
81
- },
82
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
83
- readFile(_: string): string {
84
- return 'public class MyClass{}';
85
- },
86
- exists(): boolean {
87
- return true;
88
- },
89
- });
90
- expect(result.length).toBe(1);
91
- expect(result[0].rawTypeContent).toBe('public class MyClass{}');
92
- });
93
- });