-
Notifications
You must be signed in to change notification settings - Fork 1
Add feature to generate Markdown files #1087
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
Open
jshackell-sfdc
wants to merge
19
commits into
main
Choose a base branch
from
js/markdown
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0c5ef70
fix: claude code's first pass at generating markdown
jshackell-sfdc 94cbc48
fix: more changes
jshackell-sfdc 8e52e74
fix: more changes. Go claude code
jshackell-sfdc 9120041
fix: remove smoke tests
jshackell-sfdc a8b6c88
fix: fix problems
jshackell-sfdc cb6cf4b
fix: more finessing
jshackell-sfdc ecc80f0
fix: tweaks
jshackell-sfdc 1092cb0
fix: more tweaks
jshackell-sfdc fbeac6e
fix: remove leading $ in examples
jshackell-sfdc dd2b523
fix: implement feedback from Sorida
jshackell-sfdc d7f9478
fix: fix tests
jshackell-sfdc 7e4e9c4
fix: various changes
jshackell-sfdc 2c5db6b
fix: more formatting
jshackell-sfdc b121bd5
fix: remove most of the too-complex formatting of command and flag desc
jshackell-sfdc 4404757
fix: add markdown test generation as dependency for test suite
jshackell-sfdc 3105ef9
test: add comprehensive markdown output validation tests
jshackell-sfdc 499fc01
fix: skip HTML comments in entity escaping test
jshackell-sfdc b58f0d2
fix: add prettier-ignore comments and alphabetize flag rows
jshackell-sfdc b64a99a
fix: result of asking CC to cleanup code
jshackell-sfdc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,3 +53,4 @@ package.json.bak. | |
|
|
||
| /tmp | ||
| /test/tmp | ||
| /test/tmp-md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,11 @@ export default class CommandReferenceGenerate extends SfCommand<CommandReference | |
| summary: messages.getMessage('flags.config-path.summary'), | ||
| char: 'c', | ||
| }), | ||
| 'output-format': Flags.string({ | ||
| summary: messages.getMessage('flags.output-format.summary'), | ||
| options: ['dita', 'markdown'], | ||
| default: 'dita', | ||
| }), | ||
| }; | ||
|
|
||
| private loadedConfig!: Interfaces.Config; | ||
|
|
@@ -146,9 +151,13 @@ export default class CommandReferenceGenerate extends SfCommand<CommandReference | |
| const commands = await this.loadCommands(plugins); | ||
| const topicMetadata = this.loadTopicMetadata(commands); | ||
| const cliMeta = this.loadCliMeta(); | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| const docs = new Docs(Ditamap.outputDir, flags.hidden, topicMetadata, cliMeta); | ||
| const docs = new Docs( | ||
| Ditamap.outputDir, | ||
| flags['output-format'] as 'dita' | 'markdown', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change this to |
||
| flags.hidden, | ||
| topicMetadata ?? new Map<string, never>(), | ||
| cliMeta | ||
| ); | ||
|
|
||
| events.on('topic', ({ topic }: { topic: string }) => { | ||
| this.log(chalk.green(`Generating topic '${topic}'`)); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * Copyright 2026, Salesforce, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Dictionary, Optional } from '@salesforce/ts-types'; | ||
| import { CommandParameterData, replaceConfigVariables } from '../utils.js'; | ||
|
|
||
| export type FlagInfo = { | ||
| hidden: boolean; | ||
| description: string; | ||
| summary: string; | ||
| required: boolean; | ||
| kind: string; | ||
| type: string; | ||
| defaultHelpValue?: string; | ||
| default: string | (() => Promise<string>); | ||
| aliases?: string[]; | ||
| options?: string[]; | ||
| char?: string; | ||
| deprecated?: { version: string; to: string }; | ||
| }; | ||
|
|
||
| export const getDefault = async (flag: FlagInfo, flagName: string): Promise<string> => { | ||
| if (!flag) { | ||
| return ''; | ||
| } | ||
| if (flagName === 'target-org' || flagName === 'target-dev-hub') { | ||
| return ''; | ||
| } | ||
| if (typeof flag.default === 'function') { | ||
| try { | ||
| const help = await flag.default(); | ||
| return help.includes('[object Object]') ? '' : help ?? ''; | ||
| } catch { | ||
| return ''; | ||
| } | ||
| } else { | ||
| return flag.default; | ||
| } | ||
| }; | ||
|
|
||
| export const flagIsDefined = (input: [string, Optional<FlagInfo>]): input is [string, FlagInfo] => | ||
| input[1] !== undefined; | ||
|
|
||
| export const buildDescription = | ||
| (commandName: string) => | ||
| (binary: string) => | ||
| (flag: FlagInfo): string[] => { | ||
| const description = replaceConfigVariables( | ||
| Array.isArray(flag?.description) ? flag?.description.join('\n') : flag?.description ?? '', | ||
| binary, | ||
| commandName | ||
| ); | ||
| return formatParagraphs( | ||
| flag.summary ? `${replaceConfigVariables(flag.summary, binary, commandName)}\n${description}` : description | ||
| ); | ||
| }; | ||
|
|
||
| export const formatParagraphs = (textToFormat?: string): string[] => | ||
| textToFormat ? textToFormat.split('\n').filter((n) => n !== '') : []; | ||
|
|
||
| export const readBinary = (commandMeta: Record<string, unknown>): string => | ||
| 'binary' in commandMeta && typeof commandMeta.binary === 'string' ? commandMeta.binary : 'unknown'; | ||
|
|
||
| export const buildCommandParameters = async ( | ||
| commandName: string, | ||
| binary: string, | ||
| flags: Dictionary<FlagInfo> | ||
| ): Promise<CommandParameterData[]> => { | ||
| const descriptionBuilder = buildDescription(commandName)(binary); | ||
| return Promise.all( | ||
| [...Object.entries(flags)] | ||
| .filter(flagIsDefined) | ||
| .filter(([, flag]) => !flag.hidden) | ||
| .map( | ||
| async ([flagName, flag]) => | ||
| ({ | ||
| ...flag, | ||
| name: flagName, | ||
| description: descriptionBuilder(flag), | ||
| optional: !flag.required, | ||
| kind: flag.kind ?? flag.type, | ||
| hasValue: flag.type !== 'boolean', | ||
| defaultFlagValue: await getDefault(flag, flagName), | ||
| } satisfies CommandParameterData) | ||
| ) | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to add validation for
output-formatflag before docs: