@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.
- package/dist/cli/generate.js +2745 -39
- package/dist/defaults-DUwru49Q.js +12 -0
- package/dist/defaults-SH0Rsi5E.js +11 -0
- package/dist/index.d.ts +62 -2
- package/dist/index.js +36 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.BaseClass.md +1 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.MultiInheritanceClass.md +1 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.ParentInterface.md +1 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.ReferencedEnum.md +1 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.SampleException.md +1 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.SampleInterface.md +1 -1
- package/examples/plain-markdown/docs/Miscellaneous/ns.Url.md +1 -1
- package/examples/plain-markdown/docs/Sample-Enums/ns.SampleEnum.md +1 -1
- package/examples/plain-markdown/docs/SampleGroup/ns.SampleClass.md +1 -1
- package/examples/plain-markdown/docs/index.md +1 -1
- package/examples/plain-markdown/package.json +3 -4
- package/examples/vitepress/.forceignore +12 -0
- package/examples/vitepress/apexdocs.config.ts +108 -0
- package/examples/vitepress/config/project-scratch-def.json +13 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js +259 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/_metadata.json +40 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js +11474 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js.map +7 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js +9172 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js.map +7 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/package.json +3 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4339 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +567 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/vue.js +323 -0
- package/examples/vitepress/docs/.vitepress/cache/deps/vue.js.map +7 -0
- package/examples/vitepress/docs/.vitepress/config.mts +21 -0
- package/examples/vitepress/docs/.vitepress/sidebar.json +119 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.BaseClass.md +20 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.MultiInheritanceClass.md +78 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.ParentInterface.md +19 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.ReferencedEnum.md +15 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.SampleException.md +28 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.SampleInterface.md +122 -0
- package/examples/vitepress/docs/Miscellaneous/apexdocs.Url.md +318 -0
- package/examples/vitepress/docs/Sample-Enums/apexdocs.SampleEnum.md +41 -0
- package/examples/vitepress/docs/SampleGroup/apexdocs.SampleClass.md +178 -0
- package/examples/vitepress/docs/api-examples.md +49 -0
- package/examples/vitepress/docs/index-frontmatter.md +16 -0
- package/examples/vitepress/docs/index.md +127 -0
- package/examples/vitepress/docs/markdown-examples.md +85 -0
- package/examples/vitepress/force-app/main/default/classes/BaseClass.cls +3 -0
- package/examples/vitepress/force-app/main/default/classes/MultiInheritanceClass.cls +1 -0
- package/examples/vitepress/force-app/main/default/classes/ParentInterface.cls +3 -0
- package/examples/vitepress/force-app/main/default/classes/ReferencedEnum.cls +5 -0
- package/examples/vitepress/force-app/main/default/classes/SampleClass.cls +72 -0
- package/examples/vitepress/force-app/main/default/classes/SampleEnum.cls +30 -0
- package/examples/vitepress/force-app/main/default/classes/SampleException.cls +17 -0
- package/examples/vitepress/force-app/main/default/classes/SampleInterface.cls +46 -0
- package/examples/vitepress/force-app/main/default/classes/Url.cls +195 -0
- package/examples/vitepress/package-lock.json +2574 -0
- package/examples/vitepress/package.json +18 -0
- package/examples/vitepress/sfdx-project.json +12 -0
- package/jest.config.js +1 -0
- package/package.json +11 -10
- package/src/application/Apexdocs.ts +16 -104
- package/src/application/__tests__/apex-file-reader.spec.ts +104 -0
- package/src/application/apex-file-reader.ts +42 -0
- package/src/application/file-writer.ts +25 -0
- package/src/application/generators/markdown.ts +53 -0
- package/src/application/generators/openapi.ts +56 -0
- package/src/cli/args.ts +17 -112
- package/src/cli/commands/markdown.ts +58 -0
- package/src/cli/generate.ts +7 -5
- package/src/{model/__tests__ → core/__test__}/manifest.spec.ts +1 -1
- package/src/core/manifest.ts +57 -51
- package/src/{__spec__/core → core/markdown/__test__}/expect-extensions.ts +5 -5
- package/src/core/markdown/__test__/generating-class-docs.spec.ts +727 -0
- package/src/{__spec__/core → core/markdown/__test__}/generating-enum-docs.spec.ts +82 -59
- package/src/{__spec__/core → core/markdown/__test__}/generating-interface-docs.spec.ts +94 -75
- package/src/core/markdown/__test__/generating-reference-guide.spec.ts +184 -0
- package/src/core/{__test__ → markdown/__test__}/inheritance-chain.test.ts +2 -2
- package/src/core/markdown/__test__/test-helpers.ts +22 -0
- package/src/core/{adapters → markdown/adapters}/__tests__/interface-adapter.spec.ts +38 -8
- package/src/core/{adapters → markdown/adapters}/apex-types.ts +7 -4
- package/src/core/{adapters → markdown/adapters}/inline.ts +1 -1
- package/src/core/markdown/adapters/renderable-bundle.ts +144 -0
- package/src/core/markdown/adapters/renderable-to-page-data.ts +92 -0
- package/src/core/{adapters → markdown/adapters}/types.d.ts +16 -2
- package/src/core/markdown/generate-docs.ts +158 -0
- package/src/core/markdown/reflection/error-handling.ts +37 -0
- package/src/core/markdown/reflection/filter-scope.ts +13 -0
- package/src/core/markdown/reflection/inheritance-chain-expanion.ts +22 -0
- package/src/core/markdown/reflection/inherited-member-expansion.ts +105 -0
- package/src/core/markdown/reflection/reflect-source.ts +41 -0
- package/src/core/markdown/reflection/sort-members.ts +59 -0
- package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/class-template.ts +2 -0
- package/src/core/markdown/templates/hookable.ts +7 -0
- package/src/core/{template.ts → markdown/templates/template.ts} +12 -12
- package/src/core/markdown/utils.ts +3 -0
- package/src/{transpiler → core}/openapi/__tests__/open-api-docs-processor.spec.ts +1 -1
- package/src/{model → core/openapi}/apex-type-wrappers/__tests__/ClassMirrorWrapper.spec.ts +3 -3
- package/src/core/openapi/file-container.ts +13 -0
- package/src/{service → core/openapi}/manifest-factory.ts +3 -3
- package/src/{transpiler → core}/openapi/open-api-docs-processor.ts +9 -10
- package/src/core/openapi/openapi-type-file.ts +14 -0
- package/src/{service → core/openapi}/parser.ts +8 -8
- package/src/{transpiler → core}/openapi/parsers/Builder.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/MethodParser.ts +5 -5
- package/src/{transpiler → core}/openapi/parsers/ParameterObjectBuilder.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/ReferenceBuilder.ts +3 -3
- package/src/{transpiler → core}/openapi/parsers/RequestBodyBuilder.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/ResponsesBuilder.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/__tests__/MethodParser.spec.ts +1 -1
- package/src/{transpiler → core}/openapi/parsers/__tests__/ParameterObjectBuilder.spec.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/__tests__/ReferenceBuilder.spec.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/__tests__/RequestBodyBuilder.spec.ts +2 -2
- package/src/{transpiler → core}/openapi/parsers/__tests__/ResponsesBuilder.spec.ts +1 -1
- package/src/{transpiler → core/openapi}/transpiler.ts +2 -6
- package/src/{model → core/openapi}/types-repository.ts +0 -9
- package/src/core/parse-apex-metadata.ts +14 -0
- package/src/core/settings.ts +56 -0
- package/src/core/shared/types.d.ts +92 -0
- package/src/core/shared/utils.ts +5 -0
- package/src/defaults.ts +8 -0
- package/src/index.ts +34 -2
- package/src/test-helpers/InterfaceMirrorBuilder.ts +0 -5
- package/src/test-helpers/SettingsBuilder.ts +1 -3
- package/src/util/logger.ts +2 -2
- package/src/util/string-utils.ts +0 -4
- package/tsconfig.json +5 -1
- package/apexdocs.config.ts +0 -13
- package/examples/plain-markdown/template.md +0 -3
- package/src/__spec__/core/generating-class-docs.spec.ts +0 -531
- package/src/__spec__/core/generating-reference-guide.spec.ts +0 -164
- package/src/__spec__/core/test-helpers.ts +0 -9
- package/src/application/generators/generate-markdown-files.ts +0 -53
- package/src/core/apex-bundle.ts +0 -3
- package/src/core/generate-docs.ts +0 -432
- package/src/model/markdown-file.ts +0 -122
- package/src/model/markdown-generation-util/doc-comment-annotation-util.ts +0 -50
- package/src/model/markdown-generation-util/field-declaration-util.ts +0 -71
- package/src/model/markdown-generation-util/index.ts +0 -3
- package/src/model/markdown-generation-util/method-declaration-util.ts +0 -166
- package/src/model/markdown-generation-util/type-declaration-util.ts +0 -91
- package/src/model/markdown-home-file.ts +0 -58
- package/src/model/markdown-type-file.ts +0 -169
- package/src/model/openapi/openapi-type-file.ts +0 -14
- package/src/model/outputFile.ts +0 -20
- package/src/service/__tests__/apex-file-reader.spec.ts +0 -93
- package/src/service/apex-file-reader.ts +0 -47
- package/src/service/file-writer.ts +0 -34
- package/src/service/metadata-processor.ts +0 -16
- package/src/service/state.ts +0 -24
- package/src/service/walkers/class-walker.ts +0 -30
- package/src/service/walkers/enum-walker.ts +0 -7
- package/src/service/walkers/interface-walker.ts +0 -12
- package/src/service/walkers/walker-factory.ts +0 -19
- package/src/service/walkers/walker.ts +0 -42
- package/src/settings.ts +0 -143
- package/src/transpiler/factory.ts +0 -31
- package/src/transpiler/file-container.ts +0 -13
- package/src/transpiler/generator-choices.ts +0 -1
- package/src/transpiler/markdown/class-file-generatorHelper.ts +0 -61
- package/src/transpiler/markdown/docsify/docsify-docs-processor.ts +0 -12
- package/src/transpiler/markdown/jekyll/jekyll-docsProcessor.ts +0 -50
- package/src/transpiler/markdown/markdown-transpiler-base.ts +0 -28
- package/src/transpiler/processor-type-transpiler.ts +0 -18
- /package/src/{service → application}/file-system.ts +0 -0
- /package/src/core/{adapters → markdown/adapters}/__tests__/documentables.spec.ts +0 -0
- /package/src/core/{adapters → markdown/adapters}/__tests__/references.spec.ts +0 -0
- /package/src/core/{adapters → markdown/adapters}/documentables.ts +0 -0
- /package/src/core/{adapters → markdown/adapters}/fields-and-properties.ts +0 -0
- /package/src/core/{adapters → markdown/adapters}/methods-and-constructors.ts +0 -0
- /package/src/core/{adapters → markdown/adapters}/type-utils.ts +0 -0
- /package/src/core/{inheritance-chain.ts → markdown/reflection/inheritance-chain.ts} +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/constructors-partial-template.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/documentable-partial-template.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/enum-template.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/fieldsPartialTemplate.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/grouped-members-partial-template.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/interface-template.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/methods-partial-template.ts +0 -0
- /package/src/core/{templates → markdown/templates}/reference-guide.ts +0 -0
- /package/src/{transpiler/markdown/plain-markdown → core/markdown/templates}/type-doc-partial.ts +0 -0
- /package/src/{service → core/openapi}/__tests__/manifest-factory.spec.ts +0 -0
- /package/src/{model → core}/openapi/__tests__/open-api.spec.ts +0 -0
- /package/src/{model → core}/openapi/apex-doc-types.ts +0 -0
- /package/src/{model → core/openapi}/apex-type-wrappers/ClassMirrorWrapper.ts +0 -0
- /package/src/{model → core/openapi}/apex-type-wrappers/MethodMirrorWrapper.ts +0 -0
- /package/src/{model → core}/openapi/open-api-types.ts +0 -0
- /package/src/{model → core}/openapi/open-api.ts +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SourceFile } from '../../shared/types';
|
|
2
|
+
import { generateDocs as gen, MarkdownGeneratorConfig } from '../generate-docs';
|
|
3
|
+
import { referenceGuideTemplate } from '../templates/reference-guide';
|
|
4
|
+
|
|
5
|
+
export function apexBundleFromRawString(raw: string, rawMetadata?: string): SourceFile {
|
|
6
|
+
return {
|
|
7
|
+
filePath: 'test.cls',
|
|
8
|
+
content: raw,
|
|
9
|
+
metadataContent: rawMetadata ?? null,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateDocs(apexBundles: SourceFile[], config?: Partial<MarkdownGeneratorConfig>) {
|
|
14
|
+
return gen(apexBundles, {
|
|
15
|
+
targetDir: 'target',
|
|
16
|
+
scope: ['global', 'public'],
|
|
17
|
+
defaultGroupName: 'Miscellaneous',
|
|
18
|
+
sortMembersAlphabetically: true,
|
|
19
|
+
referenceGuideTemplate: referenceGuideTemplate,
|
|
20
|
+
...config,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
import { typeToRenderable } from '../apex-types';
|
|
2
|
-
import { InterfaceMirrorBuilder } from '
|
|
3
|
-
import { AnnotationBuilder } from '
|
|
4
|
-
import { MethodMirrorBuilder, ParameterBuilder } from '
|
|
2
|
+
import { InterfaceMirrorBuilder } from '../../../../test-helpers/InterfaceMirrorBuilder';
|
|
3
|
+
import { AnnotationBuilder } from '../../../../test-helpers/AnnotationBuilder';
|
|
4
|
+
import { MethodMirrorBuilder, ParameterBuilder } from '../../../../test-helpers/MethodMirrorBuilder';
|
|
5
|
+
import { MarkdownGeneratorConfig } from '../../generate-docs';
|
|
5
6
|
|
|
6
7
|
function linkGenerator(type: string): string {
|
|
7
8
|
return type;
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
const defaultMarkdownGeneratorConfig: MarkdownGeneratorConfig = {
|
|
12
|
+
targetDir: '',
|
|
13
|
+
scope: ['global', 'public'],
|
|
14
|
+
namespace: '',
|
|
15
|
+
defaultGroupName: 'Miscellaneous',
|
|
16
|
+
referenceGuideTemplate: '',
|
|
17
|
+
sortMembersAlphabetically: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
10
20
|
describe('Conversion from InterfaceMirror to InterfaceSource understandable by the templating engine', () => {
|
|
11
21
|
it('converts the name', () => {
|
|
12
22
|
const interfaceMirror = new InterfaceMirrorBuilder().withName('SampleInterface').build();
|
|
13
|
-
const interfaceSource = typeToRenderable(
|
|
23
|
+
const interfaceSource = typeToRenderable(
|
|
24
|
+
{ filePath: '', type: interfaceMirror },
|
|
25
|
+
linkGenerator,
|
|
26
|
+
defaultMarkdownGeneratorConfig,
|
|
27
|
+
);
|
|
14
28
|
|
|
15
29
|
expect(interfaceSource.name).toBe('SampleInterface');
|
|
16
30
|
});
|
|
17
31
|
|
|
18
32
|
it('converts the access modifier', () => {
|
|
19
33
|
const interfaceMirror = new InterfaceMirrorBuilder().build();
|
|
20
|
-
const interfaceSource = typeToRenderable(
|
|
34
|
+
const interfaceSource = typeToRenderable(
|
|
35
|
+
{ filePath: '', type: interfaceMirror },
|
|
36
|
+
linkGenerator,
|
|
37
|
+
defaultMarkdownGeneratorConfig,
|
|
38
|
+
);
|
|
21
39
|
|
|
22
40
|
expect(interfaceSource.meta.accessModifier).toBe('public');
|
|
23
41
|
});
|
|
@@ -26,7 +44,11 @@ describe('Conversion from InterfaceMirror to InterfaceSource understandable by t
|
|
|
26
44
|
const interfaceMirror = new InterfaceMirrorBuilder()
|
|
27
45
|
.addAnnotation(new AnnotationBuilder().withName('MyAnnotation').build())
|
|
28
46
|
.build();
|
|
29
|
-
const interfaceSource = typeToRenderable(
|
|
47
|
+
const interfaceSource = typeToRenderable(
|
|
48
|
+
{ filePath: '', type: interfaceMirror },
|
|
49
|
+
linkGenerator,
|
|
50
|
+
defaultMarkdownGeneratorConfig,
|
|
51
|
+
);
|
|
30
52
|
|
|
31
53
|
expect(interfaceSource.doc.annotations).toEqual(['MYANNOTATION']);
|
|
32
54
|
});
|
|
@@ -44,7 +66,11 @@ describe('Conversion from InterfaceMirror to InterfaceSource understandable by t
|
|
|
44
66
|
)
|
|
45
67
|
.build();
|
|
46
68
|
|
|
47
|
-
const interfaceSource = typeToRenderable(
|
|
69
|
+
const interfaceSource = typeToRenderable(
|
|
70
|
+
{ filePath: '', type: interfaceMirror },
|
|
71
|
+
linkGenerator,
|
|
72
|
+
defaultMarkdownGeneratorConfig,
|
|
73
|
+
);
|
|
48
74
|
|
|
49
75
|
expect(interfaceSource.methods.value).toHaveLength(1);
|
|
50
76
|
expect(interfaceSource.methods.value[0].signature.value.content[0]).toBe('public String sampleMethod()');
|
|
@@ -72,7 +98,11 @@ describe('Conversion from InterfaceMirror to InterfaceSource understandable by t
|
|
|
72
98
|
)
|
|
73
99
|
.build();
|
|
74
100
|
|
|
75
|
-
const interfaceSource = typeToRenderable(
|
|
101
|
+
const interfaceSource = typeToRenderable(
|
|
102
|
+
{ filePath: '', type: interfaceMirror },
|
|
103
|
+
linkGenerator,
|
|
104
|
+
defaultMarkdownGeneratorConfig,
|
|
105
|
+
);
|
|
76
106
|
|
|
77
107
|
expect(interfaceSource.methods.value).toHaveLength(1);
|
|
78
108
|
expect(interfaceSource.methods.value[0].signature.value.content[0]).toBe(
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import { adaptDescribable, adaptDocumentable } from './documentables';
|
|
15
15
|
import { adaptConstructor, adaptMethod } from './methods-and-constructors';
|
|
16
16
|
import { adaptFieldOrProperty } from './fields-and-properties';
|
|
17
|
+
import { MarkdownGeneratorConfig } from '../generate-docs';
|
|
17
18
|
|
|
18
19
|
type GetReturnRenderable<T extends Type> = T extends InterfaceMirror
|
|
19
20
|
? RenderableInterface
|
|
@@ -22,11 +23,12 @@ type GetReturnRenderable<T extends Type> = T extends InterfaceMirror
|
|
|
22
23
|
: RenderableEnum;
|
|
23
24
|
|
|
24
25
|
export function typeToRenderable<T extends Type>(
|
|
25
|
-
type: T,
|
|
26
|
+
parsedFile: { filePath: string; type: T },
|
|
26
27
|
linkGenerator: GetRenderableContentByTypeName,
|
|
27
|
-
|
|
28
|
-
): GetReturnRenderable<T> {
|
|
28
|
+
config: MarkdownGeneratorConfig,
|
|
29
|
+
): GetReturnRenderable<T> & { filePath: string; namespace?: string } {
|
|
29
30
|
function getRenderable(): RenderableInterface | RenderableClass | RenderableEnum {
|
|
31
|
+
const { type } = parsedFile;
|
|
30
32
|
switch (type.type_name) {
|
|
31
33
|
case 'enum':
|
|
32
34
|
return enumTypeToEnumSource(type as EnumMirror, linkGenerator) as RenderableEnum;
|
|
@@ -39,7 +41,8 @@ export function typeToRenderable<T extends Type>(
|
|
|
39
41
|
|
|
40
42
|
return {
|
|
41
43
|
...(getRenderable() as GetReturnRenderable<T>),
|
|
42
|
-
|
|
44
|
+
filePath: parsedFile.filePath,
|
|
45
|
+
namespace: config.namespace,
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { ParsedFile } from '../../shared/types';
|
|
2
|
+
import { Link, RenderableBundle, StringOrLink } from './types';
|
|
3
|
+
import { typeToRenderable } from './apex-types';
|
|
4
|
+
import { adaptDescribable } from './documentables';
|
|
5
|
+
import { Type } from '@cparra/apex-reflection';
|
|
6
|
+
import { MarkdownGeneratorConfig } from '../generate-docs';
|
|
7
|
+
|
|
8
|
+
export function parsedFilesToRenderableBundle(
|
|
9
|
+
config: MarkdownGeneratorConfig,
|
|
10
|
+
parsedFiles: ParsedFile[],
|
|
11
|
+
): RenderableBundle {
|
|
12
|
+
return parsedFiles.reduce<RenderableBundle>(
|
|
13
|
+
(acc, parsedFile) => {
|
|
14
|
+
const renderable = typeToRenderable(
|
|
15
|
+
parsedFile,
|
|
16
|
+
(referenceName) => {
|
|
17
|
+
return linkFromTypeNameGenerator(
|
|
18
|
+
parsedFile.type,
|
|
19
|
+
parsedFiles.map((file) => file.type),
|
|
20
|
+
referenceName,
|
|
21
|
+
config,
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
config,
|
|
25
|
+
);
|
|
26
|
+
acc.renderables.push(renderable);
|
|
27
|
+
|
|
28
|
+
const descriptionLines = parsedFile.type.docComment?.descriptionLines;
|
|
29
|
+
const reference = {
|
|
30
|
+
typeName: parsedFile.type.name,
|
|
31
|
+
directory: getDirectoryFromRoot(config, parsedFile.type),
|
|
32
|
+
title: getLinkFromRoot(config, parsedFile.type),
|
|
33
|
+
description: adaptDescribable(descriptionLines, (referenceName) =>
|
|
34
|
+
getPossibleLinkFromRoot(
|
|
35
|
+
config,
|
|
36
|
+
referenceName,
|
|
37
|
+
findType(
|
|
38
|
+
parsedFiles.map((file) => file.type),
|
|
39
|
+
referenceName,
|
|
40
|
+
),
|
|
41
|
+
),
|
|
42
|
+
).description,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const group = getTypeGroup(parsedFile.type, config);
|
|
46
|
+
if (!acc.references[group]) {
|
|
47
|
+
acc.references[group] = [];
|
|
48
|
+
}
|
|
49
|
+
acc.references[group].push(reference);
|
|
50
|
+
|
|
51
|
+
return acc;
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
references: {},
|
|
55
|
+
renderables: [],
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function linkFromTypeNameGenerator(
|
|
61
|
+
typeBeingDocumented: Type,
|
|
62
|
+
repository: Type[],
|
|
63
|
+
referenceName: string,
|
|
64
|
+
config: MarkdownGeneratorConfig,
|
|
65
|
+
): StringOrLink {
|
|
66
|
+
const type = findType(repository, referenceName);
|
|
67
|
+
if (!type) {
|
|
68
|
+
// If the type is not found, we return the type name as a string.
|
|
69
|
+
return referenceName;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const [fullClassName, fileLink] = getFileLinkTuple(typeBeingDocumented, type, config);
|
|
73
|
+
return {
|
|
74
|
+
__type: 'link',
|
|
75
|
+
title: fullClassName,
|
|
76
|
+
url: fileLink,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getPossibleLinkFromRoot(config: MarkdownGeneratorConfig, fallback: string, type?: Type): StringOrLink {
|
|
81
|
+
if (!type) {
|
|
82
|
+
return fallback;
|
|
83
|
+
}
|
|
84
|
+
const namespacePrefix = config.namespace ? `${config.namespace}.` : '';
|
|
85
|
+
const title = `${namespacePrefix}${type.name}`;
|
|
86
|
+
return {
|
|
87
|
+
__type: 'link',
|
|
88
|
+
title: title,
|
|
89
|
+
url: `${getDirectoryFromRoot(config, type)}/${title}.md`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function getDirectoryFromRoot(config: MarkdownGeneratorConfig, type?: Type): string {
|
|
94
|
+
if (!type) {
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
return `./${getSanitizedGroup(type, config)}`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function findType(repository: Type[], referenceName: string) {
|
|
101
|
+
return repository.find((currentType: Type) => currentType.name.toLowerCase() === referenceName.toLowerCase());
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function getFileLinkTuple(
|
|
105
|
+
typeBeingDocumented: Type,
|
|
106
|
+
referencedType: Type,
|
|
107
|
+
config: MarkdownGeneratorConfig,
|
|
108
|
+
): [string, string] {
|
|
109
|
+
const namespacePrefix = config.namespace ? `${config.namespace}.` : '';
|
|
110
|
+
const directoryRoot = `${getDirectoryRoot(typeBeingDocumented, referencedType, config)}`;
|
|
111
|
+
// TODO: Instead of adding a "." to the name when there is a namespace, maybe we want to create a folder for everything
|
|
112
|
+
// within that namespace and put the files in there.
|
|
113
|
+
const fullClassName = `${namespacePrefix}${referencedType.name}`;
|
|
114
|
+
return [fullClassName, `${directoryRoot}${fullClassName}.md`];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getDirectoryRoot(typeBeingDocumented: Type, referencedType: Type, config: MarkdownGeneratorConfig) {
|
|
118
|
+
if (getTypeGroup(typeBeingDocumented, config) === getTypeGroup(referencedType, config)) {
|
|
119
|
+
// If the types the same groups then we simply link directly to that file
|
|
120
|
+
return './';
|
|
121
|
+
} else {
|
|
122
|
+
// If the types have different groups, then we have to go up a directory
|
|
123
|
+
return `../${getSanitizedGroup(referencedType, config)}/`;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function getTypeGroup(type: Type, config: MarkdownGeneratorConfig): string {
|
|
128
|
+
const groupAnnotation = type.docComment?.annotations.find((annotation) => annotation.name.toLowerCase() === 'group');
|
|
129
|
+
return groupAnnotation?.body ?? config.defaultGroupName;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function getSanitizedGroup(classModel: Type, config: MarkdownGeneratorConfig) {
|
|
133
|
+
return getTypeGroup(classModel, config).replace(/ /g, '-').replace('.', '');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function getLinkFromRoot(config: MarkdownGeneratorConfig, type: Type): Link {
|
|
137
|
+
const namespacePrefix = config.namespace ? `${config.namespace}.` : '';
|
|
138
|
+
const title = `${namespacePrefix}${type.name}`;
|
|
139
|
+
return {
|
|
140
|
+
__type: 'link',
|
|
141
|
+
title: title,
|
|
142
|
+
url: `${getDirectoryFromRoot(config, type)}/${title}.md`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ReferenceGuideReference, Renderable, RenderableBundle, RenderableEnum } from './types';
|
|
2
|
+
import { DocPageData, DocumentationBundle } from '../../shared/types';
|
|
3
|
+
import { pipe } from 'fp-ts/function';
|
|
4
|
+
import { CompilationRequest, Template } from '../templates/template';
|
|
5
|
+
import { enumMarkdownTemplate } from '../templates/enum-template';
|
|
6
|
+
import { interfaceMarkdownTemplate } from '../templates/interface-template';
|
|
7
|
+
import { classMarkdownTemplate } from '../templates/class-template';
|
|
8
|
+
|
|
9
|
+
export const convertToDocumentationBundle = (
|
|
10
|
+
referenceGuideTemplate: string,
|
|
11
|
+
{ references, renderables }: RenderableBundle,
|
|
12
|
+
): DocumentationBundle => ({
|
|
13
|
+
referenceGuide: {
|
|
14
|
+
directory: '',
|
|
15
|
+
frontmatter: null,
|
|
16
|
+
content: referencesToReferenceGuideContent(references, referenceGuideTemplate),
|
|
17
|
+
fileExtension: 'md',
|
|
18
|
+
fileName: 'index',
|
|
19
|
+
},
|
|
20
|
+
docs: renderables.map((renderable: Renderable) => renderableToPageData(Object.values(references).flat(), renderable)),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
function referencesToReferenceGuideContent(
|
|
24
|
+
references: { [key: string]: ReferenceGuideReference[] },
|
|
25
|
+
template: string,
|
|
26
|
+
): string {
|
|
27
|
+
function alphabetizeReferences(references: { [key: string]: ReferenceGuideReference[] }): {
|
|
28
|
+
[key: string]: ReferenceGuideReference[];
|
|
29
|
+
} {
|
|
30
|
+
return Object.keys(references)
|
|
31
|
+
.sort((a, b) => a.localeCompare(b))
|
|
32
|
+
.reduce<{ [key: string]: ReferenceGuideReference[] }>((acc, key) => {
|
|
33
|
+
acc[key] = references[key].sort((a, b) => a.title.toString().localeCompare(b.title.toString()));
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return pipe(references, alphabetizeReferences, (references) =>
|
|
39
|
+
compile({
|
|
40
|
+
template: template,
|
|
41
|
+
source: references,
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function renderableToPageData(referenceGuideReference: ReferenceGuideReference[], renderable: Renderable): DocPageData {
|
|
47
|
+
function buildDocOutput(renderable: Renderable, docContents: string): DocPageData {
|
|
48
|
+
const reference = referenceGuideReference.find(
|
|
49
|
+
(ref) => ref.typeName.toLowerCase() === renderable.name.toLowerCase(),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const namespacePrefix = renderable.namespace ? `${renderable.namespace}.` : '';
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
source: {
|
|
56
|
+
filePath: renderable.filePath,
|
|
57
|
+
name: renderable.name,
|
|
58
|
+
type: renderable.type,
|
|
59
|
+
},
|
|
60
|
+
fileName: `${namespacePrefix}${renderable.name}`,
|
|
61
|
+
fileExtension: 'md',
|
|
62
|
+
directory: `${reference?.directory}`,
|
|
63
|
+
frontmatter: null,
|
|
64
|
+
content: docContents,
|
|
65
|
+
group: renderable.doc.group ?? 'Miscellaneous',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return pipe(renderable, resolveApexTypeTemplate, compile, (docContents) => buildDocOutput(renderable, docContents));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function resolveApexTypeTemplate(renderable: Renderable): CompilationRequest {
|
|
73
|
+
function getTemplate(renderable: Renderable): string {
|
|
74
|
+
switch (renderable.type) {
|
|
75
|
+
case 'enum':
|
|
76
|
+
return enumMarkdownTemplate;
|
|
77
|
+
case 'interface':
|
|
78
|
+
return interfaceMarkdownTemplate;
|
|
79
|
+
case 'class':
|
|
80
|
+
return classMarkdownTemplate;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
template: getTemplate(renderable),
|
|
86
|
+
source: renderable as RenderableEnum,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function compile(request: CompilationRequest): string {
|
|
91
|
+
return Template.getInstance().compile(request);
|
|
92
|
+
}
|
|
@@ -20,10 +20,24 @@ export type ClassMirrorWithInheritanceChain = ClassMirror & { inheritanceChain:
|
|
|
20
20
|
export type FieldMirrorWithInheritance = FieldMirror & InheritanceSupport;
|
|
21
21
|
export type PropertyMirrorWithInheritance = PropertyMirror & InheritanceSupport;
|
|
22
22
|
export type MethodMirrorWithInheritance = MethodMirror & InheritanceSupport;
|
|
23
|
-
export type FieldOrProperty = FieldMirrorWithInheritance | PropertyMirrorWithInheritance;
|
|
24
23
|
|
|
25
24
|
// Renderable types
|
|
26
25
|
|
|
26
|
+
export type ReferenceGuideReference = {
|
|
27
|
+
typeName: string;
|
|
28
|
+
directory: string;
|
|
29
|
+
title: Link;
|
|
30
|
+
description: RenderableContent[] | undefined;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type RenderableBundle = {
|
|
34
|
+
// References are grouped by their defined @group annotation
|
|
35
|
+
references: {
|
|
36
|
+
[key: string]: ReferenceGuideReference[];
|
|
37
|
+
};
|
|
38
|
+
renderables: Renderable[];
|
|
39
|
+
};
|
|
40
|
+
|
|
27
41
|
export type Link = {
|
|
28
42
|
readonly __type: 'link';
|
|
29
43
|
title: string;
|
|
@@ -166,4 +180,4 @@ export type RenderableEnum = RenderableType & {
|
|
|
166
180
|
values: RenderableSection<EnumValue[]>;
|
|
167
181
|
};
|
|
168
182
|
|
|
169
|
-
export type Renderable = RenderableClass | RenderableInterface | RenderableEnum;
|
|
183
|
+
export type Renderable = (RenderableClass | RenderableInterface | RenderableEnum) & { filePath: string };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { pipe } from 'fp-ts/function';
|
|
2
|
+
import * as E from 'fp-ts/Either';
|
|
3
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
4
|
+
import yaml from 'js-yaml';
|
|
5
|
+
|
|
6
|
+
import { apply } from '#utils/fp';
|
|
7
|
+
import {
|
|
8
|
+
DocPageData,
|
|
9
|
+
DocumentationBundle,
|
|
10
|
+
Frontmatter,
|
|
11
|
+
PostHookDocumentationBundle,
|
|
12
|
+
ReferenceGuidePageData,
|
|
13
|
+
SourceFile,
|
|
14
|
+
TransformDocPage,
|
|
15
|
+
TransformDocs,
|
|
16
|
+
TransformReferenceGuide,
|
|
17
|
+
UserDefinedMarkdownConfig,
|
|
18
|
+
} from '../shared/types';
|
|
19
|
+
import { parsedFilesToRenderableBundle } from './adapters/renderable-bundle';
|
|
20
|
+
import { reflectSourceCode } from './reflection/reflect-source';
|
|
21
|
+
import { checkForReflectionErrors } from './reflection/error-handling';
|
|
22
|
+
import { addInheritanceChainToTypes } from './reflection/inheritance-chain-expanion';
|
|
23
|
+
import { addInheritedMembersToTypes } from './reflection/inherited-member-expansion';
|
|
24
|
+
import { convertToDocumentationBundle } from './adapters/renderable-to-page-data';
|
|
25
|
+
import { filterScope } from './reflection/filter-scope';
|
|
26
|
+
import { Template } from './templates/template';
|
|
27
|
+
import { hookableTemplate } from './templates/hookable';
|
|
28
|
+
import { sortMembers } from './reflection/sort-members';
|
|
29
|
+
import { isSkip } from '../shared/utils';
|
|
30
|
+
|
|
31
|
+
export type MarkdownGeneratorConfig = Pick<
|
|
32
|
+
UserDefinedMarkdownConfig,
|
|
33
|
+
| 'targetDir'
|
|
34
|
+
| 'scope'
|
|
35
|
+
| 'namespace'
|
|
36
|
+
| 'defaultGroupName'
|
|
37
|
+
| 'transformReferenceGuide'
|
|
38
|
+
| 'transformDocs'
|
|
39
|
+
| 'transformDocPage'
|
|
40
|
+
> & {
|
|
41
|
+
referenceGuideTemplate: string;
|
|
42
|
+
sortMembersAlphabetically: boolean;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export class HookError {
|
|
46
|
+
readonly _tag = 'HookError';
|
|
47
|
+
|
|
48
|
+
constructor(public error: unknown) {}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function generateDocs(apexBundles: SourceFile[], config: MarkdownGeneratorConfig) {
|
|
52
|
+
const filterOutOfScope = apply(filterScope, config.scope);
|
|
53
|
+
const convertToRenderableBundle = apply(parsedFilesToRenderableBundle, config);
|
|
54
|
+
const convertToDocumentationBundleForTemplate = apply(convertToDocumentationBundle, config.referenceGuideTemplate);
|
|
55
|
+
const sortTypeMembers = apply(sortMembers, config.sortMembersAlphabetically);
|
|
56
|
+
|
|
57
|
+
return pipe(
|
|
58
|
+
apexBundles,
|
|
59
|
+
reflectSourceCode,
|
|
60
|
+
checkForReflectionErrors,
|
|
61
|
+
E.map(filterOutOfScope),
|
|
62
|
+
E.map(addInheritedMembersToTypes),
|
|
63
|
+
E.map(addInheritanceChainToTypes),
|
|
64
|
+
E.map(sortTypeMembers),
|
|
65
|
+
E.map(convertToRenderableBundle),
|
|
66
|
+
E.map(convertToDocumentationBundleForTemplate),
|
|
67
|
+
TE.fromEither,
|
|
68
|
+
TE.flatMap((bundle) =>
|
|
69
|
+
TE.tryCatch(
|
|
70
|
+
() => documentationBundleHook(bundle, config),
|
|
71
|
+
(error) => new HookError(error),
|
|
72
|
+
),
|
|
73
|
+
),
|
|
74
|
+
TE.map((bundle: PostHookDocumentationBundle) => ({
|
|
75
|
+
referenceGuide: isSkip(bundle.referenceGuide)
|
|
76
|
+
? bundle.referenceGuide
|
|
77
|
+
: {
|
|
78
|
+
...bundle.referenceGuide,
|
|
79
|
+
content: Template.getInstance().compile({
|
|
80
|
+
source: {
|
|
81
|
+
frontmatter: toFrontmatterString(bundle.referenceGuide.frontmatter),
|
|
82
|
+
content: bundle.referenceGuide.content,
|
|
83
|
+
},
|
|
84
|
+
template: hookableTemplate,
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
docs: bundle.docs.map((doc) => ({
|
|
88
|
+
...doc,
|
|
89
|
+
content: Template.getInstance().compile({
|
|
90
|
+
source: {
|
|
91
|
+
frontmatter: toFrontmatterString(doc.frontmatter),
|
|
92
|
+
content: doc.content,
|
|
93
|
+
},
|
|
94
|
+
template: hookableTemplate,
|
|
95
|
+
}),
|
|
96
|
+
})),
|
|
97
|
+
})),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function toFrontmatterString(frontmatter: Frontmatter): string {
|
|
102
|
+
if (typeof frontmatter === 'string') {
|
|
103
|
+
return frontmatter;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!frontmatter) {
|
|
107
|
+
return '';
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const yamlString = yaml.dump(frontmatter);
|
|
111
|
+
return `---\n${yamlString}---\n`;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Configurable hooks
|
|
115
|
+
function passThroughHook<T>(value: T): T {
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const documentationBundleHook = async (
|
|
120
|
+
bundle: DocumentationBundle,
|
|
121
|
+
config: MarkdownGeneratorConfig,
|
|
122
|
+
): Promise<PostHookDocumentationBundle> => {
|
|
123
|
+
return {
|
|
124
|
+
referenceGuide: await transformReferenceGuide(bundle.referenceGuide, config.transformReferenceGuide),
|
|
125
|
+
docs: await transformDocs(bundle.docs, config.transformDocs, config.transformDocPage),
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const transformReferenceGuide = async (
|
|
130
|
+
referenceGuide: ReferenceGuidePageData,
|
|
131
|
+
hook: TransformReferenceGuide = passThroughHook,
|
|
132
|
+
) => {
|
|
133
|
+
const result = await hook(referenceGuide);
|
|
134
|
+
if (isSkip(result)) {
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...referenceGuide,
|
|
140
|
+
...(await hook(referenceGuide)),
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const transformDocs = async (
|
|
145
|
+
docs: DocPageData[],
|
|
146
|
+
transformDocsHook: TransformDocs = passThroughHook,
|
|
147
|
+
transformDocPageHook: TransformDocPage = passThroughHook,
|
|
148
|
+
): Promise<Awaited<DocPageData[]>> => {
|
|
149
|
+
const transformed = await transformDocsHook(docs);
|
|
150
|
+
return Promise.all(transformed.map((doc) => transformDocPage(doc, transformDocPageHook)));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const transformDocPage = async (doc: DocPageData, hook: TransformDocPage = passThroughHook) => {
|
|
154
|
+
return {
|
|
155
|
+
...doc,
|
|
156
|
+
...(await hook(doc)),
|
|
157
|
+
};
|
|
158
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
|
+
import { ParsedFile } from '../../shared/types';
|
|
3
|
+
import { pipe } from 'fp-ts/function';
|
|
4
|
+
|
|
5
|
+
export class ReflectionErrors {
|
|
6
|
+
readonly _tag = 'ReflectionErrors';
|
|
7
|
+
constructor(public errors: ReflectionError[]) {}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class ReflectionError {
|
|
11
|
+
constructor(
|
|
12
|
+
public file: string,
|
|
13
|
+
public message: string,
|
|
14
|
+
) {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function checkForReflectionErrors(reflectionResult: E.Either<ReflectionError, ParsedFile>[]) {
|
|
18
|
+
function reduceReflectionResultIntoSingleEither(results: E.Either<ReflectionError, ParsedFile>[]): {
|
|
19
|
+
errors: ReflectionError[];
|
|
20
|
+
parsedFiles: ParsedFile[];
|
|
21
|
+
} {
|
|
22
|
+
return results.reduce<{ errors: ReflectionError[]; parsedFiles: ParsedFile[] }>(
|
|
23
|
+
(acc, result) => {
|
|
24
|
+
E.isLeft(result) ? acc.errors.push(result.left) : acc.parsedFiles.push(result.right);
|
|
25
|
+
return acc;
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
errors: [],
|
|
29
|
+
parsedFiles: [],
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return pipe(reflectionResult, reduceReflectionResultIntoSingleEither, ({ errors, parsedFiles }) =>
|
|
35
|
+
errors.length ? E.left(new ReflectionErrors(errors)) : E.right(parsedFiles),
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ParsedFile } from '../../shared/types';
|
|
2
|
+
import Manifest from '../../manifest';
|
|
3
|
+
|
|
4
|
+
export function filterScope(scopes: string[], parsedFiles: ParsedFile[]): ParsedFile[] {
|
|
5
|
+
return parsedFiles
|
|
6
|
+
.filter(({ type }) => Manifest.shouldFilterType(type, scopes))
|
|
7
|
+
.map((parsedFile) => {
|
|
8
|
+
return {
|
|
9
|
+
...parsedFile,
|
|
10
|
+
type: Manifest.filterSingleType(parsedFile.type, scopes, false),
|
|
11
|
+
};
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ClassMirror, Type } from '@cparra/apex-reflection';
|
|
2
|
+
import { createInheritanceChain } from './inheritance-chain';
|
|
3
|
+
import { ParsedFile } from '../../shared/types';
|
|
4
|
+
import { parsedFilesToTypes } from '../utils';
|
|
5
|
+
|
|
6
|
+
export const addInheritanceChainToTypes = (parsedFiles: ParsedFile[]) =>
|
|
7
|
+
parsedFiles.map((parsedFile) => ({
|
|
8
|
+
...parsedFile,
|
|
9
|
+
type: addInheritanceChain(parsedFile.type, parsedFilesToTypes(parsedFiles)),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
function addInheritanceChain<T extends Type>(current: T, repository: Type[]): T {
|
|
13
|
+
if (current.type_name === 'enum' || current.type_name === 'interface') {
|
|
14
|
+
return current;
|
|
15
|
+
} else {
|
|
16
|
+
const inheritanceChain = createInheritanceChain(repository, current as ClassMirror);
|
|
17
|
+
return {
|
|
18
|
+
...current,
|
|
19
|
+
inheritanceChain,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|