Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changelog hook improvements #218

Merged
merged 4 commits into from
Nov 26, 2024
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ npm-debug.log
/dist/
/lib/
.sfdx/

# Added by Illuminated Cloud
.localdev/
/IlluminatedCloud/
/out/
target/
/.illuminatedCloud/
**/tsconfig*.json
**/*.tsbuildinfo
1 change: 1 addition & 0 deletions .idea/apexdocs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,39 @@ Allows changing the frontmatter and content of the changelog page.
type TransformChangeLogPage = (
changelog: ChangeLogPageData,
) => Partial<ChangeLogPageData> | Promise<Partial<ChangeLogPageData>>

// Supporting types

type ChangeLogPageData = {
source: SourceChangelog;
frontmatter: string | Record<string, any>;
content: string;
outputDocPath: string;
};

type SourceChangelog = {
fileChanges: FileChange[];
};

type FileChange = {
name: string;
fileType: 'apex' | 'customobject';
changeType: 'added' | 'removed' | 'changed';
changes?: {
addedMethods?: string[];
removedMethods?: string[];
addedFields?: string[];
removedFields?: string[];
addedProperties?: string[];
removedProperties?: string[];
addedCustomFields?: string[];
removedCustomFields?: string[];
addedSubtypes?: string[];
removedSubtypes?: string[];
addedEnumValues?: string[];
removedEnumValues?: string[];
};
};
```

Example
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.6.0",
"version": "3.7.0",
"description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
"keywords": [
"apex",
Expand Down
8 changes: 6 additions & 2 deletions src/core/changelog/generate-change-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Type } from '@cparra/apex-reflection';
import { filterApexSourceFiles, filterCustomObjectsAndFields } from '#utils/source-bundle-utils';
import { CustomFieldMetadata } from '../reflection/sobject/reflect-custom-field-source';
import { hookableTemplate } from '../markdown/templates/hookable';
import changelogToSourceChangelog from './helpers/changelog-to-source-changelog';

type Config = Omit<UserDefinedChangelogConfig, 'targetGenerator'>;

Expand All @@ -38,7 +39,9 @@ export function generateChangeLog(
if (config.skipIfNoChanges && !hasChanges(changelog)) {
return skip();
}
return pipe(convertToRenderableChangelog(changelog, newManifest.types), compile, convertToPageData);
return pipe(convertToRenderableChangelog(changelog, newManifest.types), compile, (content) =>
convertToPageData(content, changelog),
);
}

return pipe(
Expand Down Expand Up @@ -106,8 +109,9 @@ function compile(renderable: RenderableChangelog): string {
return Template.getInstance().compile(compilationRequest);
}

function toPageData(fileName: string, content: string): ChangeLogPageData {
function toPageData(fileName: string, content: string, changelog: Changelog): ChangeLogPageData {
return {
source: changelogToSourceChangelog(changelog),
frontmatter: null,
content,
outputDocPath: `${fileName}.md`,
Expand Down
103 changes: 103 additions & 0 deletions src/core/changelog/helpers/changelog-to-source-changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { Changelog } from '../process-changelog';
import { FileChange, SourceChangelog } from '../../shared/types';

/**
* Converts a Changelog to a SourceChangelog, which is a version of a Changelog that is exposed through the hook.
* We have this conversion to avoid exposing the internal Changelog structure to the hook.
* @param changelog The Changelog to convert.
* @returns The SourceChangelog.
*/
export default function (changelog: Changelog): SourceChangelog {
const newApexTypes = changelog.newApexTypes.map<FileChange>((newType) => {
return {
name: newType,
fileType: 'apex',
changeType: 'added',
};
});

const removedApexTypes = changelog.removedApexTypes.map<FileChange>((removedType) => {
return {
name: removedType,
fileType: 'apex',
changeType: 'removed',
};
});

const newCustomObjects = changelog.newCustomObjects.map<FileChange>((newType) => {
return {
name: newType,
fileType: 'customobject',
changeType: 'added',
};
});

const removedCustomObjects = changelog.removedCustomObjects.map<FileChange>((removedType) => {
return {
name: removedType,
fileType: 'customobject',
changeType: 'removed',
};
});

const modifiedApexTypes = changelog.newOrModifiedApexMembers.map<FileChange>((modifiedType) => {
return {
name: modifiedType.typeName,
fileType: 'apex',
changeType: 'changed',
changes: {
addedMethods: modifiedType.modifications.filter((mod) => mod.__typename === 'NewMethod').map((mod) => mod.name),
removedMethods: modifiedType.modifications
.filter((mod) => mod.__typename === 'RemovedMethod')
.map((mod) => mod.name),
addedFields: modifiedType.modifications.filter((mod) => mod.__typename === 'NewField').map((mod) => mod.name),
removedFields: modifiedType.modifications
.filter((mod) => mod.__typename === 'RemovedField')
.map((mod) => mod.name),
addedProperties: modifiedType.modifications
.filter((mod) => mod.__typename === 'NewProperty')
.map((mod) => mod.name),
removedProperties: modifiedType.modifications
.filter((mod) => mod.__typename === 'RemovedProperty')
.map((mod) => mod.name),
addedSubtypes: modifiedType.modifications.filter((mod) => mod.__typename === 'NewType').map((mod) => mod.name),
removedSubtypes: modifiedType.modifications
.filter((mod) => mod.__typename === 'RemovedType')
.map((mod) => mod.name),
addedEnumValues: modifiedType.modifications
.filter((mod) => mod.__typename === 'NewEnumValue')
.map((mod) => mod.name),
removedEnumValues: modifiedType.modifications
.filter((mod) => mod.__typename === 'RemovedEnumValue')
.map((mod) => mod.name),
},
};
});

const modifiedCustomObjects = changelog.customObjectModifications.map<FileChange>((modifiedType) => {
return {
name: modifiedType.typeName,
fileType: 'customobject',
changeType: 'changed',
changes: {
addedCustomFields: modifiedType.modifications
.filter((mod) => mod.__typename === 'NewField')
.map((mod) => mod.name),
removedCustomFields: modifiedType.modifications
.filter((mod) => mod.__typename === 'RemovedField')
.map((mod) => mod.name),
},
};
});

return {
fileChanges: [
...newApexTypes,
...removedApexTypes,
...newCustomObjects,
...removedCustomObjects,
...modifiedApexTypes,
...modifiedCustomObjects,
],
};
}
4 changes: 2 additions & 2 deletions src/core/reflection/sobject/parse-picklist-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function toPickListValues(customField: MaybeTyped): string[] | undefined {
if ('valueSetDefinition' in valueSet) {
const valueSetDefinition = valueSet.valueSetDefinition as object;
if ('value' in valueSetDefinition) {
const pickListValues = valueSetDefinition.value as object[];
return pickListValues.filter((each) => 'fullName' in each).map((each) => each.fullName as string);
const pickListValues = valueSetDefinition.value as Record<'fullName', string>[];
return pickListValues.filter((each) => 'fullName' in each).map((current) => current.fullName);
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions src/core/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,32 @@ export type DocPageData = {

export type OpenApiPageData = Omit<DocPageData, 'source' | 'type'>;

export type FileChange = {
name: string;
fileType: 'apex' | 'customobject';
changeType: 'added' | 'removed' | 'changed';
changes?: {
addedMethods?: string[];
removedMethods?: string[];
addedFields?: string[];
removedFields?: string[];
addedProperties?: string[];
removedProperties?: string[];
addedCustomFields?: string[];
removedCustomFields?: string[];
addedSubtypes?: string[];
removedSubtypes?: string[];
addedEnumValues?: string[];
removedEnumValues?: string[];
};
};

export type SourceChangelog = {
fileChanges: FileChange[];
};

export type ChangeLogPageData = {
source: SourceChangelog;
frontmatter: Frontmatter;
content: string;
outputDocPath: string;
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
DocPageData,
DocPageReference,
ChangeLogPageData,
SourceChangelog,
ConfigurableDocPageData,
TransformReferenceGuide,
TransformDocs,
Expand Down Expand Up @@ -79,6 +80,7 @@ export {
ReferenceGuidePageData,
DocPageData,
ChangeLogPageData,
SourceChangelog,
DocPageReference,
Skip,
ConfigurableDocPageData,
Expand Down
Loading