-
-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from yamadashy/feature/markdown-style
feat(style): Add Markdown output style
- Loading branch information
Showing
9 changed files
with
177 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,81 @@ | ||
import Handlebars from 'handlebars'; | ||
import type { OutputGeneratorContext } from './outputGeneratorTypes.js'; | ||
import { | ||
generateHeader, | ||
generateSummaryAdditionalInfo, | ||
generateSummaryFileFormat, | ||
generateSummaryNotes, | ||
generateSummaryPurpose, | ||
generateSummaryUsageGuidelines, | ||
} from './outputStyleDecorator.js'; | ||
|
||
export const generateMarkdownStyle = (outputGeneratorContext: OutputGeneratorContext) => { | ||
const template = Handlebars.compile(markdownTemplate); | ||
|
||
const renderContext = { | ||
generationHeader: generateHeader(outputGeneratorContext.generationDate), | ||
summaryPurpose: generateSummaryPurpose(), | ||
summaryFileFormat: generateSummaryFileFormat(), | ||
summaryUsageGuidelines: generateSummaryUsageGuidelines( | ||
outputGeneratorContext.config, | ||
outputGeneratorContext.instruction, | ||
), | ||
summaryNotes: generateSummaryNotes(outputGeneratorContext.config), | ||
summaryAdditionalInfo: generateSummaryAdditionalInfo(), | ||
headerText: outputGeneratorContext.config.output.headerText, | ||
instruction: outputGeneratorContext.instruction, | ||
treeString: outputGeneratorContext.treeString, | ||
processedFiles: outputGeneratorContext.processedFiles, | ||
}; | ||
|
||
return `${template(renderContext).trim()}\n`; | ||
}; | ||
|
||
const markdownTemplate = /* md */ ` | ||
{{{generationHeader}}} | ||
# File Summary | ||
## Purpose | ||
{{{summaryPurpose}}} | ||
## File Format | ||
{{{summaryFileFormat}}} | ||
4. Multiple file entries, each consisting of: | ||
a. A header with the file path (## File: path/to/file) | ||
b. The full contents of the file in a code block | ||
## Usage Guidelines | ||
{{{summaryUsageGuidelines}}} | ||
## Notes | ||
{{{summaryNotes}}} | ||
## Additional Info | ||
{{#if headerText}} | ||
### User Provided Header | ||
{{{headerText}}} | ||
{{/if}} | ||
{{{summaryAdditionalInfo}}} | ||
# Repository Structure | ||
\`\`\` | ||
{{{treeString}}} | ||
\`\`\` | ||
# Repository Files | ||
{{#each processedFiles}} | ||
## File: {{{this.path}}} | ||
\`\`\` | ||
{{{this.content}}} | ||
\`\`\` | ||
{{/each}} | ||
{{#if instruction}} | ||
# Instruction | ||
{{{instruction}}} | ||
{{/if}} | ||
`; |
This file contains 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 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 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 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,34 @@ | ||
import process from 'node:process'; | ||
import { beforeEach, describe, expect, test, vi } from 'vitest'; | ||
import { generateMarkdownStyle } from '../../../src/core/output/markdownStyleGenerator.js'; | ||
import { buildOutputGeneratorContext } from '../../../src/core/output/outputGenerator.js'; | ||
import { createMockConfig } from '../../testing/testUtils.js'; | ||
|
||
vi.mock('fs/promises'); | ||
|
||
describe('outputGenerator', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
test('generateMarkdownOutput should include user-provided header text', async () => { | ||
const mockConfig = createMockConfig({ | ||
output: { | ||
filePath: 'output.md', | ||
style: 'markdown', | ||
headerText: 'Custom header text', | ||
topFilesLength: 2, | ||
showLineNumbers: false, | ||
removeComments: false, | ||
removeEmptyLines: false, | ||
}, | ||
}); | ||
|
||
const context = await buildOutputGeneratorContext(process.cwd(), mockConfig, [], []); | ||
const output = await generateMarkdownStyle(context); | ||
|
||
expect(output).toContain('# File Summary'); | ||
expect(output).toContain('# Repository Structure'); | ||
expect(output).toContain('# Repository Files'); | ||
}); | ||
}); |