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

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 +11 -10
  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,47 +0,0 @@
1
- import { Settings } from '../settings';
2
- import { FileSystem } from './file-system';
3
- import ApexBundle from '../core/apex-bundle';
4
-
5
- const APEX_FILE_EXTENSION = '.cls';
6
-
7
- /**
8
- * Reads from .cls files and returns their raw body.
9
- */
10
- export class ApexFileReader {
11
- /**
12
- * Reads from .cls files and returns their raw body.
13
- */
14
- static processFiles(fileSystem: FileSystem, rootPath: string = this.sourceDirectory): ApexBundle[] {
15
- let bundles: ApexBundle[] = [];
16
-
17
- const directoryContents = fileSystem.readDirectory(rootPath);
18
- directoryContents.forEach((currentFilePath) => {
19
- const currentPath = fileSystem.joinPath(rootPath, currentFilePath);
20
- if (fileSystem.isDirectory(currentPath)) {
21
- bundles = bundles.concat(this.processFiles(fileSystem, currentPath));
22
- }
23
-
24
- if (!this.isApexFile(currentFilePath)) {
25
- return;
26
- }
27
-
28
- const rawApexFile = fileSystem.readFile(currentPath);
29
- const metadataPath = fileSystem.joinPath(rootPath, `${currentFilePath}-meta.xml`);
30
- let rawMetadataFile = null;
31
- if (Settings.getInstance().includeMetadata()) {
32
- rawMetadataFile = fileSystem.exists(metadataPath) ? fileSystem.readFile(metadataPath) : null;
33
- }
34
-
35
- bundles.push(new ApexBundle(currentFilePath, rawApexFile, rawMetadataFile));
36
- });
37
- return bundles;
38
- }
39
-
40
- private static isApexFile(currentFile: string): boolean {
41
- return currentFile.endsWith(APEX_FILE_EXTENSION);
42
- }
43
-
44
- private static get sourceDirectory() {
45
- return Settings.getInstance().sourceDirectory;
46
- }
47
- }
@@ -1,34 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { OutputFile } from '../model/outputFile';
4
- import { OnBeforeFileWrite, Settings, TargetFile } from '../settings';
5
-
6
- export class FileWriter {
7
- static write(files: OutputFile[], onWriteCallback: (file: TargetFile) => void) {
8
- const onBeforeFileWrite: OnBeforeFileWrite = (file: TargetFile) => Settings.getInstance().onBeforeFileWrite(file);
9
- files.forEach((file) => {
10
- const resolvedFile = this.getTargetLocation(file, onBeforeFileWrite);
11
- const fullDir = path.join(resolvedFile.dir.baseDir, resolvedFile.dir.fileDir);
12
- if (!fs.existsSync(fullDir)) {
13
- fs.mkdirSync(fullDir, { recursive: true });
14
- }
15
-
16
- const filePath = path.join(fullDir, `${resolvedFile.name}${resolvedFile.extension}`);
17
- fs.writeFileSync(filePath, file.body, 'utf8');
18
- onWriteCallback(resolvedFile);
19
- });
20
- }
21
-
22
- private static getTargetLocation(file: OutputFile, onBeforeFileWrite: OnBeforeFileWrite): TargetFile {
23
- const targetFile: TargetFile = {
24
- name: file.fileName,
25
- extension: file.fileExtension(),
26
- dir: {
27
- baseDir: Settings.getInstance().outputDir,
28
- fileDir: file.dir,
29
- },
30
- };
31
-
32
- return onBeforeFileWrite(targetFile);
33
- }
34
- }
@@ -1,16 +0,0 @@
1
- import { XMLParser } from 'fast-xml-parser';
2
-
3
- export default class MetadataProcessor {
4
- public static process(input: string) {
5
- const map = new Map<string, string>();
6
- const xml = new XMLParser().parse(input);
7
-
8
- map.set('apiVersion', xml.ApexClass.apiVersion ?? '');
9
-
10
- if (xml.ApexClass.status) {
11
- map.set('status', xml.ApexClass.status);
12
- }
13
-
14
- return map;
15
- }
16
- }
@@ -1,24 +0,0 @@
1
- import { Type } from '@cparra/apex-reflection';
2
-
3
- export default class State {
4
- private static instance: State;
5
- private typeBeingProcessed?: Type;
6
-
7
- // eslint-disable-next-line @typescript-eslint/no-empty-function
8
- private constructor() {}
9
-
10
- public static getInstance(): State {
11
- if (!State.instance) {
12
- State.instance = new State();
13
- }
14
- return State.instance;
15
- }
16
-
17
- public setTypeBeingProcessed(typeToSet: Type): void {
18
- this.typeBeingProcessed = typeToSet;
19
- }
20
-
21
- public getTypeBeingProcessed(): Type | undefined {
22
- return this.typeBeingProcessed;
23
- }
24
- }
@@ -1,30 +0,0 @@
1
- import { Walker, WalkerListener } from './walker';
2
- import { ClassMirror } from '@cparra/apex-reflection';
3
-
4
- export class ClassWalker extends Walker {
5
- walk(listener: WalkerListener): void {
6
- listener.onTypeDeclaration(this.type);
7
- const classMirror = this.type as ClassMirror;
8
- if (classMirror.constructors.length) {
9
- listener.onConstructorDeclaration(this.type.name, classMirror.constructors);
10
- }
11
- if (classMirror.fields.length) {
12
- listener.onFieldsDeclaration(this.sortType(classMirror.fields));
13
- }
14
- if (classMirror.properties.length) {
15
- listener.onPropertiesDeclaration(this.sortType(classMirror.properties));
16
- }
17
- if (classMirror.methods.length) {
18
- listener.onMethodsDeclaration(this.sortType(classMirror.methods));
19
- }
20
- if (classMirror.enums.length) {
21
- listener.onInnerEnumsDeclaration(this.sortType(classMirror.enums));
22
- }
23
- if (classMirror.classes.length) {
24
- listener.onInnerClassesDeclaration(this.sortType(classMirror.classes));
25
- }
26
- if (classMirror.interfaces.length) {
27
- listener.onInnerInterfacesDeclaration(this.sortType(classMirror.interfaces));
28
- }
29
- }
30
- }
@@ -1,7 +0,0 @@
1
- import { Walker, WalkerListener } from './walker';
2
-
3
- export class EnumWalker extends Walker {
4
- walk(listener: WalkerListener): void {
5
- listener.onTypeDeclaration(this.type);
6
- }
7
- }
@@ -1,12 +0,0 @@
1
- import { Walker, WalkerListener } from './walker';
2
- import { InterfaceMirror } from '@cparra/apex-reflection';
3
-
4
- export class InterfaceWalker extends Walker {
5
- walk(listener: WalkerListener): void {
6
- listener.onTypeDeclaration(this.type);
7
- const interfaceMirror = this.type as InterfaceMirror;
8
- if (interfaceMirror.methods.length) {
9
- listener.onMethodsDeclaration(this.sortType(interfaceMirror.methods));
10
- }
11
- }
12
- }
@@ -1,19 +0,0 @@
1
- import { Type } from '@cparra/apex-reflection';
2
- import { Walker } from './walker';
3
- import { ClassWalker } from './class-walker';
4
- import { EnumWalker } from './enum-walker';
5
- import { InterfaceWalker } from './interface-walker';
6
-
7
- export class WalkerFactory {
8
- static get(type: Type): Walker {
9
- switch (type.type_name) {
10
- case 'class':
11
- return new ClassWalker(type);
12
- case 'enum':
13
- return new EnumWalker(type);
14
- case 'interface':
15
- return new InterfaceWalker(type);
16
- }
17
- throw Error('Walker not found for type.');
18
- }
19
- }
@@ -1,42 +0,0 @@
1
- import {
2
- ClassMirror,
3
- ConstructorMirror,
4
- EnumMirror,
5
- FieldMirror,
6
- InterfaceMirror,
7
- MethodMirror,
8
- PropertyMirror,
9
- Type,
10
- } from '@cparra/apex-reflection';
11
- import { Settings } from '../../settings';
12
-
13
- export interface WalkerListener {
14
- onTypeDeclaration(typeMirror: Type): void;
15
-
16
- onConstructorDeclaration(className: string, constructors: ConstructorMirror[]): void;
17
-
18
- onFieldsDeclaration(fields: FieldMirror[]): void;
19
-
20
- onPropertiesDeclaration(properties: PropertyMirror[]): void;
21
-
22
- onMethodsDeclaration(methods: MethodMirror[]): void;
23
-
24
- onInnerEnumsDeclaration(enums: EnumMirror[]): void;
25
-
26
- onInnerClassesDeclaration(classes: ClassMirror[]): void;
27
-
28
- onInnerInterfacesDeclaration(interfaces: InterfaceMirror[]): void;
29
- }
30
-
31
- export abstract class Walker {
32
- constructor(public type: Type) {}
33
-
34
- abstract walk(listener: WalkerListener): void;
35
-
36
- protected sortType<T extends { name: string }>(types: T[]): T[] {
37
- if (Settings.getInstance().sortMembersAlphabetically()) {
38
- return types.sort((a, b) => a.name.localeCompare(b.name));
39
- }
40
- return types;
41
- }
42
- }
package/src/settings.ts DELETED
@@ -1,143 +0,0 @@
1
- import { GeneratorChoices } from './transpiler/generator-choices';
2
- import { LinkingStrategy } from './transpiler/processor-type-transpiler';
3
-
4
- export type OnBeforeFileWrite = (file: TargetFile) => TargetFile;
5
-
6
- export type TargetFile = {
7
- name: string;
8
- extension: string;
9
- dir: OutputDir;
10
- };
11
-
12
- export type OutputDir = {
13
- baseDir: string;
14
- fileDir: string;
15
- };
16
-
17
- export type TargetType = {
18
- name: string;
19
- typeName: 'class' | 'interface' | 'enum';
20
- accessModifier: string;
21
- description?: string;
22
- group?: string;
23
- };
24
-
25
- export interface SettingsConfig {
26
- sourceDirectory: string;
27
- scope: string[];
28
- outputDir: string;
29
- targetGenerator: GeneratorChoices;
30
- indexOnly: boolean;
31
- defaultGroupName: string;
32
- openApiTitle?: string;
33
- title: string;
34
- namespace?: string;
35
- openApiFileName: string;
36
- includeMetadata: boolean;
37
- rootDir?: string;
38
- sortMembersAlphabetically?: boolean;
39
- onAfterProcess?: (files: TargetFile[]) => void;
40
- onBeforeFileWrite?: (file: TargetFile) => TargetFile;
41
- frontMatterHeader?: (file: TargetType) => string[];
42
- linkingStrategy: LinkingStrategy;
43
- }
44
-
45
- export class Settings {
46
- private static instance: Settings;
47
-
48
- private constructor(public config: SettingsConfig) {}
49
-
50
- public static build(config: SettingsConfig) {
51
- Settings.instance = new Settings(config);
52
- }
53
-
54
- public static getInstance(): Settings {
55
- if (!Settings.instance) {
56
- throw new Error('Settings has not been initialized');
57
- }
58
- return Settings.instance;
59
- }
60
-
61
- get sourceDirectory(): string {
62
- return this.config.sourceDirectory;
63
- }
64
-
65
- get scope(): string[] {
66
- return this.config.scope;
67
- }
68
-
69
- get outputDir(): string {
70
- return this.config.outputDir;
71
- }
72
-
73
- get targetGenerator(): GeneratorChoices {
74
- return this.config.targetGenerator;
75
- }
76
-
77
- get indexOnly(): boolean {
78
- return this.config.indexOnly;
79
- }
80
-
81
- public getDefaultGroupName(): string {
82
- return this.config.defaultGroupName;
83
- }
84
-
85
- public getOpenApiTitle(): string | undefined {
86
- return this.config.openApiTitle ?? this.config.title;
87
- }
88
-
89
- public getTitle(): string {
90
- return this.config.title;
91
- }
92
-
93
- public getNamespace(): string | undefined {
94
- return this.config.namespace;
95
- }
96
-
97
- public getNamespacePrefix(): string {
98
- if (!this.config.namespace) {
99
- return '';
100
- }
101
- return `${this.config.namespace}.`;
102
- }
103
-
104
- public openApiFileName(): string {
105
- return this.config.openApiFileName;
106
- }
107
-
108
- public includeMetadata(): boolean {
109
- return this.config.includeMetadata;
110
- }
111
-
112
- public sortMembersAlphabetically(): boolean {
113
- return this.config.sortMembersAlphabetically ?? false;
114
- }
115
-
116
- public getRootDir(): string | undefined {
117
- return this.config.rootDir;
118
- }
119
-
120
- public onAfterProcess(files: TargetFile[]): void {
121
- if (this.config.onAfterProcess) {
122
- this.config.onAfterProcess(files);
123
- }
124
- }
125
-
126
- public onBeforeFileWrite(file: TargetFile): TargetFile {
127
- if (this.config.onBeforeFileWrite) {
128
- return this.config.onBeforeFileWrite(file);
129
- }
130
- return file;
131
- }
132
-
133
- public frontMatterHeader(file: TargetType): string[] {
134
- if (this.config.frontMatterHeader) {
135
- return this.config.frontMatterHeader(file);
136
- }
137
- return [];
138
- }
139
-
140
- public getLinkingStrategy(): LinkingStrategy {
141
- return this.config.linkingStrategy;
142
- }
143
- }
@@ -1,31 +0,0 @@
1
- import ProcessorTypeTranspiler from './processor-type-transpiler';
2
- import { GeneratorChoices } from './generator-choices';
3
- import { JekyllDocsProcessor } from './markdown/jekyll/jekyll-docsProcessor';
4
- import DocsifyDocsProcessor from './markdown/docsify/docsify-docs-processor';
5
- import { OpenApiDocsProcessor } from './openapi/open-api-docs-processor';
6
-
7
- export class TypeTranspilerFactory {
8
- private static typeTranspilerCache?: ProcessorTypeTranspiler;
9
-
10
- public static get(generator: GeneratorChoices): ProcessorTypeTranspiler {
11
- if (this.typeTranspilerCache) {
12
- return this.typeTranspilerCache;
13
- }
14
-
15
- switch (generator) {
16
- case 'jekyll':
17
- this.typeTranspilerCache = new JekyllDocsProcessor();
18
- return this.typeTranspilerCache;
19
- case 'docsify':
20
- this.typeTranspilerCache = new DocsifyDocsProcessor();
21
- return this.typeTranspilerCache;
22
- case 'openapi':
23
- this.typeTranspilerCache = new OpenApiDocsProcessor();
24
- return this.typeTranspilerCache;
25
- case 'plain-markdown':
26
- throw Error('Plain Markdown processor is not supported through this factory anymore.');
27
- default:
28
- throw Error('Invalid target generator');
29
- }
30
- }
31
- }
@@ -1,13 +0,0 @@
1
- import { OutputFile } from '../model/outputFile';
2
-
3
- export class FileContainer {
4
- _files: OutputFile[] = [];
5
-
6
- files(): OutputFile[] {
7
- return this._files;
8
- }
9
-
10
- pushFile(file: OutputFile): void {
11
- this._files.push(file);
12
- }
13
- }
@@ -1 +0,0 @@
1
- export type GeneratorChoices = 'jekyll' | 'docsify' | 'plain-markdown' | 'openapi';
@@ -1,61 +0,0 @@
1
- import { Type } from '@cparra/apex-reflection';
2
- import { TypesRepository } from '../../model/types-repository';
3
- import { Settings } from '../../settings';
4
- import State from '../../service/state';
5
-
6
- export default class ClassFileGeneratorHelper {
7
- public static getSanitizedGroup(classModel: Type) {
8
- return this.getClassGroup(classModel).replace(/ /g, '-').replace('.', '');
9
- }
10
-
11
- public static getFileLink(classModel: Type) {
12
- const [fullClassName, fileLink] = ClassFileGeneratorHelper.getFileLinkTuple(classModel);
13
- return `[${fullClassName}](${fileLink})`;
14
- }
15
-
16
- private static getFileLinkTuple(classModel: Type): [string, string] {
17
- const documentationRoot = Settings.getInstance().getRootDir() ?? '';
18
- const directoryRoot = `${documentationRoot}${this.getDirectoryRoot(classModel)}`;
19
- const fullClassName = `${Settings.getInstance().getNamespacePrefix()}${classModel.name}`;
20
- return [fullClassName, `${directoryRoot}${fullClassName}.md`];
21
- }
22
-
23
- public static getFileLinkByTypeName(typeName: string): string {
24
- const type = TypesRepository.getInstance().getFromScopedByName(typeName);
25
- if (!type) {
26
- // If the type is not found, we return a Markdown hyperlink with whatever we received.
27
- return `[${typeName}](${typeName})`;
28
- }
29
-
30
- return this.getFileLink(type);
31
- }
32
-
33
- private static getDirectoryRoot(classModel: Type) {
34
- // root-relative links start from the root by using a leading '/'
35
- if (Settings.getInstance().getLinkingStrategy() === 'root-relative') {
36
- return `/${this.getSanitizedGroup(classModel)}/`;
37
- }
38
-
39
- // path-relative links traverse the directory structure
40
- const typeBeingProcessed = State.getInstance().getTypeBeingProcessed();
41
- if (typeBeingProcessed) {
42
- if (this.getClassGroup(typeBeingProcessed) === this.getClassGroup(classModel)) {
43
- // If the types the same groups then we simply link directly to that file
44
- return './';
45
- } else {
46
- // If the types have different groups, then we have to go up a directory
47
- return `../${this.getSanitizedGroup(classModel)}/`;
48
- }
49
- } else {
50
- // If nothing is being processed, then we assume we are at the root and links should include the groups
51
- return `./${this.getSanitizedGroup(classModel)}/`;
52
- }
53
- }
54
-
55
- private static getClassGroup(classModel: Type): string {
56
- const groupAnnotation = classModel.docComment?.annotations.find(
57
- (annotation) => annotation.name.toLowerCase() === 'group',
58
- );
59
- return groupAnnotation?.body ?? Settings.getInstance().getDefaultGroupName();
60
- }
61
- }
@@ -1,12 +0,0 @@
1
- import { MarkdownTranspilerBase } from '../markdown-transpiler-base';
2
- import { LinkingStrategy } from '../../processor-type-transpiler';
3
-
4
- export default class DocsifyDocsProcessor extends MarkdownTranspilerBase {
5
- homeFileName(): string {
6
- return 'README';
7
- }
8
-
9
- getLinkingStrategy(): LinkingStrategy {
10
- return 'root-relative';
11
- }
12
- }
@@ -1,50 +0,0 @@
1
- import { MarkdownTranspilerBase } from '../markdown-transpiler-base';
2
- import { Type } from '@cparra/apex-reflection';
3
- import { MarkdownHomeFile } from '../../../model/markdown-home-file';
4
- import { MarkdownTypeFile } from '../../../model/markdown-type-file';
5
- import { LinkingStrategy } from '../../processor-type-transpiler';
6
- import { Settings } from '../../../settings';
7
-
8
- export class JekyllDocsProcessor extends MarkdownTranspilerBase {
9
- homeFileName(): string {
10
- return 'index';
11
- }
12
-
13
- onBeforeProcess = (types: Type[]) => {
14
- this._fileContainer.pushFile(new MarkdownHomeFile(this.homeFileName(), types, this.frontMatterForHomeFile));
15
- };
16
-
17
- onProcess(type: Type): void {
18
- this._fileContainer.pushFile(new MarkdownTypeFile(type, 1, this.getFrontMatterHeader(type)));
19
- }
20
-
21
- get frontMatterForHomeFile(): string {
22
- return '---\nlayout: default\n---';
23
- }
24
-
25
- getFrontMatterHeader(type: Type): string {
26
- const headerLines = ['---'];
27
- // "layout: default" is a required front matter header for Jekyll
28
- headerLines.push('layout: default');
29
- // Add any additional front matter headers that might have been configured in the settings
30
- const targetType = {
31
- name: type.name,
32
- typeName: type.type_name,
33
- accessModifier: type.access_modifier,
34
- group: type.group,
35
- description: type.docComment?.description,
36
- };
37
- const configuredHeaders = Settings.getInstance().frontMatterHeader(targetType);
38
- if (configuredHeaders) {
39
- configuredHeaders.forEach((header) => {
40
- headerLines.push(header);
41
- });
42
- }
43
- headerLines.push('---');
44
- return headerLines.join('\n');
45
- }
46
-
47
- getLinkingStrategy(): LinkingStrategy {
48
- return 'path-relative';
49
- }
50
- }
@@ -1,28 +0,0 @@
1
- import ProcessorTypeTranspiler from '../processor-type-transpiler';
2
- import { Type } from '@cparra/apex-reflection';
3
- import { FileContainer } from '../file-container';
4
- import { MarkdownHomeFile } from '../../model/markdown-home-file';
5
- import { MarkdownTypeFile } from '../../model/markdown-type-file';
6
-
7
- export abstract class MarkdownTranspilerBase extends ProcessorTypeTranspiler {
8
- protected readonly _fileContainer: FileContainer;
9
-
10
- constructor() {
11
- super();
12
- this._fileContainer = new FileContainer();
13
- }
14
-
15
- abstract homeFileName(): string;
16
-
17
- fileBuilder(): FileContainer {
18
- return this._fileContainer;
19
- }
20
-
21
- onBeforeProcess = (types: Type[]) => {
22
- this._fileContainer.pushFile(new MarkdownHomeFile(this.homeFileName(), types));
23
- };
24
-
25
- onProcess(type: Type): void {
26
- this._fileContainer.pushFile(new MarkdownTypeFile(type));
27
- }
28
- }
@@ -1,18 +0,0 @@
1
- import { Type } from '@cparra/apex-reflection';
2
- import { FileContainer } from './file-container';
3
-
4
- export type LinkingStrategy = 'root-relative' | 'path-relative';
5
-
6
- export default abstract class ProcessorTypeTranspiler {
7
- onBeforeProcess: ((types: Type[]) => void) | undefined;
8
-
9
- abstract onProcess(type: Type): void;
10
-
11
- onAfterProcess: ((types: Type[]) => void) | undefined;
12
-
13
- abstract fileBuilder(): FileContainer;
14
-
15
- getLinkingStrategy(): LinkingStrategy {
16
- return 'root-relative';
17
- }
18
- }
File without changes
File without changes
File without changes
File without changes