@cparra/apexdocs 2.25.0-alpha.8 → 2.25.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/cli/generate.js +153 -165
  2. package/dist/index.d.ts +51 -13
  3. package/examples/plain-markdown/docs/index.md +25 -33
  4. package/examples/plain-markdown/docs/{Miscellaneous/ns.BaseClass.md → miscellaneous/BaseClass.md} +1 -1
  5. package/examples/plain-markdown/docs/{Miscellaneous/ns.MultiInheritanceClass.md → miscellaneous/MultiInheritanceClass.md} +5 -6
  6. package/examples/plain-markdown/docs/{Miscellaneous/ns.SampleException.md → miscellaneous/SampleException.md} +3 -4
  7. package/examples/plain-markdown/docs/{Miscellaneous/ns.SampleInterface.md → miscellaneous/SampleInterface.md} +22 -29
  8. package/examples/plain-markdown/docs/{Miscellaneous/ns.Url.md → miscellaneous/Url.md} +32 -43
  9. package/examples/plain-markdown/docs/sample-enums/SampleEnum.md +36 -0
  10. package/examples/plain-markdown/docs/{SampleGroup/ns.SampleClass.md → samplegroup/SampleClass.md} +8 -11
  11. package/examples/vitepress/apexdocs.config.ts +1 -3
  12. package/examples/vitepress/docs/.vitepress/sidebar.json +18 -18
  13. package/examples/vitepress/docs/index.md +10 -10
  14. package/examples/vitepress/docs/{Miscellaneous/apexdocs.BaseClass.md → miscellaneous/BaseClass.md} +1 -1
  15. package/examples/vitepress/docs/{Miscellaneous/apexdocs.MultiInheritanceClass.md → miscellaneous/MultiInheritanceClass.md} +2 -2
  16. package/examples/vitepress/docs/{Miscellaneous/apexdocs.SampleException.md → miscellaneous/SampleException.md} +1 -1
  17. package/examples/vitepress/docs/{Miscellaneous/apexdocs.SampleInterface.md → miscellaneous/SampleInterface.md} +6 -6
  18. package/examples/vitepress/docs/{Miscellaneous/apexdocs.Url.md → miscellaneous/Url.md} +3 -3
  19. package/examples/vitepress/docs/{Sample-Enums/apexdocs.SampleEnum.md → sample-enums/SampleEnum.md} +3 -3
  20. package/examples/vitepress/docs/{SampleGroup/apexdocs.SampleClass.md → samplegroup/SampleClass.md} +4 -4
  21. package/package.json +1 -1
  22. package/src/application/apex-file-reader.ts +3 -3
  23. package/src/application/file-writer.ts +5 -9
  24. package/src/application/generators/markdown.ts +9 -4
  25. package/src/application/generators/openapi.ts +4 -4
  26. package/src/core/markdown/__test__/generating-class-docs.spec.ts +5 -3
  27. package/src/core/markdown/__test__/generating-enum-docs.spec.ts +3 -3
  28. package/src/core/markdown/__test__/generating-interface-docs.spec.ts +5 -3
  29. package/src/core/markdown/__test__/generating-reference-guide.spec.ts +3 -7
  30. package/src/core/markdown/__test__/test-helpers.ts +3 -3
  31. package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +40 -5
  32. package/src/core/markdown/adapters/apex-types.ts +3 -2
  33. package/src/core/markdown/adapters/reference-guide.ts +35 -0
  34. package/src/core/markdown/adapters/renderable-bundle.ts +43 -119
  35. package/src/core/markdown/adapters/renderable-to-page-data.ts +12 -15
  36. package/src/core/markdown/adapters/types.d.ts +4 -6
  37. package/src/core/markdown/generate-docs.ts +99 -42
  38. package/src/core/markdown/reflection/inheritance-chain-expanion.ts +1 -1
  39. package/src/core/markdown/reflection/reflect-source.ts +8 -4
  40. package/src/core/openapi/manifest-factory.ts +2 -2
  41. package/src/core/openapi/openapi-type-file.ts +1 -3
  42. package/src/core/openapi/parser.ts +4 -4
  43. package/src/core/shared/types.d.ts +52 -14
  44. package/src/index.ts +2 -1
  45. package/examples/plain-markdown/docs/Sample-Enums/ns.SampleEnum.md +0 -38
  46. /package/examples/plain-markdown/docs/{Miscellaneous/ns.ParentInterface.md → miscellaneous/ParentInterface.md} +0 -0
  47. /package/examples/plain-markdown/docs/{Miscellaneous/ns.ReferencedEnum.md → miscellaneous/ReferencedEnum.md} +0 -0
  48. /package/examples/vitepress/docs/{Miscellaneous/apexdocs.ParentInterface.md → miscellaneous/ParentInterface.md} +0 -0
  49. /package/examples/vitepress/docs/{Miscellaneous/apexdocs.ReferencedEnum.md → miscellaneous/ReferencedEnum.md} +0 -0
@@ -4,9 +4,7 @@ import { OpenApiPageData } from '../shared/types';
4
4
  export function createOpenApiFile(fileName: string, openApiModel: OpenApi): OpenApiPageData {
5
5
  const content = JSON.stringify({ ...openApiModel, namespace: undefined }, null, 2);
6
6
  return {
7
- fileExtension: 'json',
8
- fileName,
9
- directory: '',
7
+ filePath: '',
10
8
  content,
11
9
  frontmatter: null,
12
10
  group: null,
@@ -1,18 +1,18 @@
1
1
  import { ClassMirror, InterfaceMirror, ReflectionResult, Type } from '@cparra/apex-reflection';
2
2
  import { parseApexMetadata } from '../parse-apex-metadata';
3
3
  import { Logger } from '#utils/logger';
4
- import { SourceFile } from '../shared/types';
4
+ import { UnparsedSourceFile } from '../shared/types';
5
5
 
6
6
  export interface TypeParser {
7
- parse(reflect: (apexBundle: SourceFile) => ReflectionResult): Type[];
7
+ parse(reflect: (apexBundle: UnparsedSourceFile) => ReflectionResult): Type[];
8
8
  }
9
9
 
10
10
  type NameAware = { name: string };
11
11
 
12
12
  export class RawBodyParser implements TypeParser {
13
- constructor(public typeBundles: SourceFile[]) {}
13
+ constructor(public typeBundles: UnparsedSourceFile[]) {}
14
14
 
15
- parse(reflect: (apexBundle: SourceFile) => ReflectionResult): Type[] {
15
+ parse(reflect: (apexBundle: UnparsedSourceFile) => ReflectionResult): Type[] {
16
16
  const types = this.typeBundles
17
17
  .map((currentBundle) => {
18
18
  Logger.log(`Parsing file: ${currentBundle.filePath}`);
@@ -2,10 +2,14 @@ import { Type } from '@cparra/apex-reflection';
2
2
 
3
3
  export type Generator = 'markdown' | 'openapi';
4
4
 
5
+ /**
6
+ * The configurable hooks that can be used to modify the output of the generator.
7
+ */
5
8
  export type ConfigurableHooks = {
6
9
  transformReferenceGuide: TransformReferenceGuide;
7
10
  transformDocs: TransformDocs;
8
11
  transformDocPage: TransformDocPage;
12
+ transformReference: TransformReference;
9
13
  };
10
14
 
11
15
  export type UserDefinedMarkdownConfig = {
@@ -28,37 +32,44 @@ export type UserDefinedOpenApiConfig = {
28
32
 
29
33
  export type UserDefinedConfig = UserDefinedMarkdownConfig | UserDefinedOpenApiConfig;
30
34
 
31
- export type SourceFile = {
35
+ export type UnparsedSourceFile = {
32
36
  filePath: string;
33
37
  content: string;
34
38
  metadataContent: string | null;
35
39
  };
36
40
 
37
- export type ParsedFile = {
41
+ export type SourceFileMetadata = {
38
42
  filePath: string;
43
+ name: string;
44
+ type: 'interface' | 'class' | 'enum';
45
+ };
46
+
47
+ export type ParsedFile = {
48
+ source: SourceFileMetadata;
39
49
  type: Type;
40
50
  };
41
51
 
52
+ export type DocPageReference = {
53
+ source: SourceFileMetadata;
54
+ // The name under which the type should be displayed in the documentation.
55
+ // By default, this will match the source.name, but it can be configured by the user.
56
+ displayName: string;
57
+ // The location of the file relative to the root of the documentation.
58
+ pathFromRoot: string;
59
+ };
60
+
42
61
  type Frontmatter = string | Record<string, unknown> | null;
43
62
 
44
63
  export type ReferenceGuidePageData = {
45
- directory: string;
46
64
  frontmatter: Frontmatter;
47
65
  content: string;
48
- fileExtension: string;
49
- fileName: string;
66
+ filePath: string;
50
67
  };
51
68
 
52
69
  export type DocPageData = {
53
- source: {
54
- filePath: string;
55
- name: string;
56
- type: 'interface' | 'class' | 'enum';
57
- };
70
+ source: SourceFileMetadata;
58
71
  group: string | null;
59
- fileName: string;
60
- fileExtension: string;
61
- directory: string;
72
+ filePath: string;
62
73
  frontmatter: Frontmatter;
63
74
  content: string;
64
75
  };
@@ -72,6 +83,9 @@ export type DocumentationBundle = {
72
83
  docs: DocPageData[];
73
84
  };
74
85
 
86
+ /**
87
+ * Represents a file to be skipped.
88
+ */
75
89
  export type Skip = {
76
90
  readonly _tag: 'Skip';
77
91
  };
@@ -83,10 +97,34 @@ export type PostHookDocumentationBundle = {
83
97
 
84
98
  // Configurable Hooks
85
99
 
100
+ type ConfigurableDocPageReference = Omit<DocPageReference, 'source'>;
101
+
102
+ type ConfigurableDocPageData = Omit<DocPageData, 'source' | 'filePath'>;
103
+
104
+ /**
105
+ * Allows changing where the files are written to.
106
+ */
107
+ export type TransformReference = (
108
+ reference: DocPageReference,
109
+ ) => Partial<ConfigurableDocPageReference> | Promise<ConfigurableDocPageReference>;
110
+
111
+ /**
112
+ * Allows changing the frontmatter and content of the reference guide, or even if creating a reference
113
+ * guide will be skipped altogether.
114
+ */
86
115
  export type TransformReferenceGuide = (
87
116
  referenceGuide: ReferenceGuidePageData,
88
117
  ) => Partial<ReferenceGuidePageData> | Skip | Promise<Partial<ReferenceGuidePageData> | Skip>;
89
118
 
119
+ /**
120
+ * The main purpose if for allowing for doc pages to be skipped, but it can also be used to change the frontmatter
121
+ * and content of the doc pages.
122
+ */
90
123
  export type TransformDocs = (docs: DocPageData[]) => DocPageData[] | Promise<DocPageData[]>;
91
124
 
92
- export type TransformDocPage = (doc: DocPageData) => Partial<DocPageData> | Promise<Partial<DocPageData>>;
125
+ /**
126
+ * Allows changing the frontmatter and content of the doc pages.
127
+ */
128
+ export type TransformDocPage = (
129
+ doc: DocPageData,
130
+ ) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>;
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import type {
5
5
  UserDefinedMarkdownConfig,
6
6
  ReferenceGuidePageData,
7
7
  DocPageData,
8
+ DocPageReference,
8
9
  } from './core/shared/types';
9
10
  import { defaults } from './defaults';
10
11
 
@@ -32,4 +33,4 @@ function skip(): Skip {
32
33
 
33
34
  // Exports
34
35
 
35
- export { defineMarkdownConfig, skip, ConfigurableHooks, ReferenceGuidePageData, DocPageData };
36
+ export { defineMarkdownConfig, skip, ConfigurableHooks, ReferenceGuidePageData, DocPageData, DocPageReference };
@@ -1,38 +0,0 @@
1
- # SampleEnum Enum
2
-
3
- `NAMESPACEACCESSIBLE`
4
-
5
- This is a sample enum. This references [ns.ReferencedEnum](../Miscellaneous/ns.ReferencedEnum.md) .
6
-
7
- This description has several lines
8
-
9
- **Some Custom**
10
-
11
- Test. I can also have a [ns.ReferencedEnum](../Miscellaneous/ns.ReferencedEnum.md) here.
12
-
13
- And it can be multiline.
14
-
15
- **Group** Sample Enums
16
-
17
- **Author** John Doe
18
-
19
- **Date** 2022-01-01
20
-
21
- **See** [ns.ReferencedEnum](../Miscellaneous/ns.ReferencedEnum.md)
22
-
23
- ## Namespace
24
- ns
25
-
26
- ## Diagram
27
- ```mermaid
28
- graph TD
29
- A[SampleEnum] -->|references| B[ReferencedEnum]
30
- B -->|referenced by| A
31
- ```
32
-
33
- ## Values
34
- | Value | Description |
35
- |-------|-------------|
36
- | VALUE1 | This is value 1 |
37
- | VALUE2 | This is value 2 |
38
- | VALUE3 | This is value 3 |