Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ export default defineMarkdownConfig({
});
```

You can also leverage the `exclude` property to indirectly modify things like custom metadata records you do
not want included in the custom metadata type object documentation.

```typescript
//...
exclude: ['**/*.md-meta.xml']
//...
```

### Excluding Tags from Appearing in the Documentation

Note: Only works for Markdown documentation.
Expand Down
14 changes: 7 additions & 7 deletions examples/vitepress/docs/.vitepress/cache/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"hash": "f2216e85",
"hash": "05eb2d4f",
"configHash": "7f7b0dad",
"lockfileHash": "76121266",
"browserHash": "441a8d6a",
"lockfileHash": "3a9c2374",
"browserHash": "a831d6e7",
"optimized": {
"vue": {
"src": "../../../../node_modules/vue/dist/vue.runtime.esm-bundler.js",
"file": "vue.js",
"fileHash": "885cbaa9",
"fileHash": "1632d62a",
"needsInterop": false
},
"vitepress > @vue/devtools-api": {
"src": "../../../../node_modules/@vue/devtools-api/dist/index.js",
"file": "vitepress___@vue_devtools-api.js",
"fileHash": "ff3ba36c",
"fileHash": "dc8fec00",
"needsInterop": false
},
"vitepress > @vueuse/core": {
"src": "../../../../node_modules/@vueuse/core/index.mjs",
"file": "vitepress___@vueuse_core.js",
"fileHash": "b6cc6d79",
"fileHash": "3d02446b",
"needsInterop": false
},
"@theme/index": {
"src": "../../../../node_modules/vitepress/dist/client/theme-default/index.js",
"file": "@theme_index.js",
"fileHash": "6b17bcd7",
"fileHash": "3d2d1de3",
"needsInterop": false
}
},
Expand Down
4 changes: 4 additions & 0 deletions examples/vitepress/docs/.vitepress/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
{
"text": "Speaker__c",
"link": "custom-objects/Speaker__c.md"
},
{
"text": "VisibleCMT__mdt",
"link": "custom-objects/VisibleCMT__mdt.md"
}
]
}
Expand Down
10 changes: 9 additions & 1 deletion examples/vitepress/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,12 @@ These custom fields have been added or removed.

### Contact

- New Field: PhotoUrl__c. URL of the contact's photo
- New Field: PhotoUrl__c. URL of the contact's photo

## New or Removed Custom Metadata Type Records

These custom metadata type records have been added or removed.

### VisibleCMT__mdt

- New Custom Metadata Record: Some_Record_1
29 changes: 29 additions & 0 deletions examples/vitepress/docs/custom-objects/VisibleCMT__mdt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: VisibleCMT__mdt
---

# VisibleCMT

## API Name
`VisibleCMT__mdt`

## Fields
### Field1
**Required**

**API Name**

`apexdocs__Field1__c`

**Type**

*Text*

## Records
### Some Record 1

`Protected`

**API Name**

`VisibleCMT.Some_Record_1`
2 changes: 2 additions & 0 deletions examples/vitepress/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Represents a line item on a sales order.

Represents a speaker at an event.

### [VisibleCMT__mdt](custom-objects/VisibleCMT__mdt)

## Miscellaneous

### [BaseClass](miscellaneous/BaseClass)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<label>Some Record 1</label>
<protected>true</protected>
<values>
<field>Field1__c</field>
<value xsi:type="xsd:string">Sample Value</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>SameNamespaceMDT</label>
<pluralLabel>SameNamespaceMDTs</pluralLabel>
<visibility>Protected</visibility>
</CustomObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>VisibleCMT</label>
<pluralLabel>VisibleCMTs</pluralLabel>
<visibility>Public</visibility>
</CustomObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Field1__c</fullName>
<externalId>false</externalId>
<fieldManageability>DeveloperControlled</fieldManageability>
<label>Field1</label>
<length>255</length>
<required>true</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
<label>VisibleCMT</label>
<pluralLabel>VisibleCMTs</pluralLabel>
<visibility>Public</visibility>
</CustomObject>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Field1__c</fullName>
<externalId>false</externalId>
<fieldManageability>DeveloperControlled</fieldManageability>
<label>Field1</label>
<length>255</length>
<required>true</required>
<type>Text</type>
<unique>false</unique>
</CustomField>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cparra/apexdocs",
"version": "3.7.3",
"version": "3.8.0",
"description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
"keywords": [
"apex",
Expand Down
13 changes: 6 additions & 7 deletions src/application/Apexdocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import markdown from './generators/markdown';
import openApi from './generators/openapi';
import changelog from './generators/changelog';

import { processFiles } from './source-code-file-reader';
import { allComponentTypes, processFiles } from './source-code-file-reader';
import { DefaultFileSystem } from './file-system';
import { Logger } from '#utils/logger';
import {
Expand Down Expand Up @@ -52,10 +52,9 @@ async function processMarkdown(config: UserDefinedMarkdownConfig) {
return pipe(
E.tryCatch(
() =>
readFiles(['ApexClass', 'CustomObject', 'CustomField'], { includeMetadata: config.includeMetadata })(
config.sourceDir,
config.exclude,
),
readFiles(allComponentTypes, {
includeMetadata: config.includeMetadata,
})(config.sourceDir, config.exclude),
(e) => new FileReadingError('An error occurred while reading files.', e),
),
TE.fromEither,
Expand All @@ -73,8 +72,8 @@ async function processOpenApi(config: UserDefinedOpenApiConfig, logger: Logger)
async function processChangeLog(config: UserDefinedChangelogConfig) {
function loadFiles(): [UnparsedSourceBundle[], UnparsedSourceBundle[]] {
return [
readFiles(['ApexClass', 'CustomObject', 'CustomField'])(config.previousVersionDir, config.exclude),
readFiles(['ApexClass', 'CustomObject', 'CustomField'])(config.currentVersionDir, config.exclude),
readFiles(allComponentTypes)(config.previousVersionDir, config.exclude),
readFiles(allComponentTypes)(config.currentVersionDir, config.exclude),
];
}

Expand Down
63 changes: 60 additions & 3 deletions src/application/source-code-file-reader.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { FileSystem } from './file-system';
import { UnparsedApexBundle, UnparsedCustomFieldBundle, UnparsedCustomObjectBundle } from '../core/shared/types';
import {
UnparsedApexBundle,
UnparsedCustomFieldBundle,
UnparsedCustomMetadataBundle,
UnparsedCustomObjectBundle,
} from '../core/shared/types';
import { minimatch } from 'minimatch';
import { flow, pipe } from 'fp-ts/function';
import { apply } from '#utils/fp';

type ComponentTypes = 'ApexClass' | 'CustomObject' | 'CustomField';
export type ComponentTypes = 'ApexClass' | 'CustomObject' | 'CustomField' | 'CustomMetadata';
export const allComponentTypes: ComponentTypes[] = ['ApexClass', 'CustomObject', 'CustomField', 'CustomMetadata'];

/**
* Simplified representation of a source component, with only
Expand Down Expand Up @@ -43,6 +49,14 @@ type CustomFieldSourceComponent = {
parentName: string;
};

type CustomMetadataSourceComponent = {
type: 'CustomMetadata';
apiName: string;
name: string;
contentPath: string;
parentName: string;
};

function getApexSourceComponents(
includeMetadata: boolean,
sourceComponents: SourceComponentAdapter[],
Expand Down Expand Up @@ -125,6 +139,41 @@ function toUnparsedCustomFieldBundle(
}));
}

function getCustomMetadataSourceComponents(
sourceComponents: SourceComponentAdapter[],
): CustomMetadataSourceComponent[] {
function getParentAndNamePair(component: SourceComponentAdapter): [string, string] {
// Custom metadata take the format [Namespace].[ParentName].[MetadataName], where namespace is optional.
// Here we split the strig and return the last 2 elements, representing the parent and the metadata name.
const [parentName, name] = component.name.split('.').slice(-2);
return [parentName, name];
}

return sourceComponents
.filter((component) => component.type.name === 'CustomMetadata')
.map((component) => ({
apiName: component.name,
name: getParentAndNamePair(component)[1],
type: 'CustomMetadata' as const,
contentPath: component.xml!,
parentName: getParentAndNamePair(component)[0],
}));
}

function toUnparsedCustomMetadataBundle(
fileSystem: FileSystem,
customMetadataSourceComponents: CustomMetadataSourceComponent[],
): UnparsedCustomMetadataBundle[] {
return customMetadataSourceComponents.map((component) => ({
apiName: component.apiName,
type: 'custommetadata',
name: component.name,
filePath: component.contentPath,
content: fileSystem.readFile(component.contentPath),
parentName: component.parentName,
}));
}

/**
* Reads from source code files and returns their raw body.
*/
Expand All @@ -137,7 +186,12 @@ export function processFiles(fileSystem: FileSystem) {
ComponentTypes,
(
components: SourceComponentAdapter[],
) => (UnparsedApexBundle | UnparsedCustomObjectBundle | UnparsedCustomFieldBundle)[]
) => (
| UnparsedApexBundle
| UnparsedCustomObjectBundle
| UnparsedCustomFieldBundle
| UnparsedCustomMetadataBundle
)[]
> = {
ApexClass: flow(apply(getApexSourceComponents, options.includeMetadata), (apexSourceComponents) =>
toUnparsedApexBundle(fileSystem, apexSourceComponents),
Expand All @@ -148,6 +202,9 @@ export function processFiles(fileSystem: FileSystem) {
CustomField: flow(getCustomFieldSourceComponents, (customFieldSourceComponents) =>
toUnparsedCustomFieldBundle(fileSystem, customFieldSourceComponents),
),
CustomMetadata: flow(getCustomMetadataSourceComponents, (customMetadataSourceComponents) =>
toUnparsedCustomMetadataBundle(fileSystem, customMetadataSourceComponents),
),
};

const convertersToUse = componentTypesToRetrieve.map((componentType) => converters[componentType]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CustomFieldMetadata } from '../../../reflection/sobject/reflect-custom-field-source';

export default class CustomFieldMetadataBuilder {
name: string = 'MyField';
description: string | null = null;

withName(name: string): CustomFieldMetadataBuilder {
this.name = name;
return this;
}

withDescription(testDescription: string) {
this.description = testDescription;
return this;
}

build(): CustomFieldMetadata {
return {
type: 'Text',
type_name: 'customfield',
label: 'MyField',
name: this.name,
description: this.description,
parentName: 'MyObject',
required: false,
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CustomMetadataMetadata } from '../../../reflection/sobject/reflect-custom-metadata-source';

export default class CustomMetadataMetadataBuilder {
parentName: string = 'MyObject';
name: string = 'FieldName__c';

withName(name: string): CustomMetadataMetadataBuilder {
this.name = name;
return this;
}

build(): CustomMetadataMetadata {
return {
type_name: 'custommetadata',
apiName: `${this.parentName}.${this.name}`,
protected: false,
label: 'MyMetadata',
name: this.name,
parentName: this.parentName,
};
}
}
Loading