Skip to content

Commit fcebe5f

Browse files
Copilotneilime
andcommitted
Enhanced ReadableContentHandler.append to accept strings directly, eliminating many .from() calls
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
1 parent 5cd1024 commit fcebe5f

22 files changed

Lines changed: 181 additions & 143 deletions

packages/cicd/github-actions/src/migration/abstract-migration.adapter.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { injectable, inject } from 'inversify';
22
import { StringDecoder } from 'string_decoder';
33
import { MigrationAdapter, SectionIdentifier, FileReaderAdapter } from '@ci-dokumentor/core';
4-
import { ReadableContentHandler } from '@ci-dokumentor/core';
5-
import type { FormatterAdapter, MigrateDocumentationPayload, ReadableContent, ReadableContentHandler, ReaderAdapter } from '@ci-dokumentor/core';
4+
import { ReadableContent } from '@ci-dokumentor/core';
5+
import type { FormatterAdapter, MigrateDocumentationPayload, ReadableContent, ReadableContent, ReaderAdapter } from '@ci-dokumentor/core';
66

77
/**
88
* Abstract base class for migration adapters in the github-actions package.
@@ -89,14 +89,14 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
8989
await rendererAdapter.replaceContent(content);
9090
}
9191

92-
protected abstract migrateContent(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent;
92+
protected abstract migrateContent(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent;
9393

9494
/**
9595
* Generic helper that replaces tool-specific start/end markers inside a
9696
* content fragment with the standardized ci-dokumentor markers using the
9797
* configured patterns and section mappings.
9898
*/
99-
protected processMarkerMappings(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
99+
protected processMarkerMappings(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
100100
// Process the fragment line-by-line to avoid allocating a single large
101101
// string for the entire fragment. We still perform replacements on each
102102
// line using the configured start/end patterns, but the scope is the
@@ -125,9 +125,9 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
125125
// Alternate between start and end on successive matches
126126
seenToggle = !seenToggle;
127127
if (seenToggle) {
128-
return ReadableContentHandler.append(formatterAdapter.sectionStart(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
128+
return ReadableContent.append(formatterAdapter.sectionStart(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
129129
}
130-
return ReadableContentHandler.append(formatterAdapter.lineBreak(), formatterAdapter.sectionEnd(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
130+
return ReadableContent.append(formatterAdapter.lineBreak(), formatterAdapter.sectionEnd(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
131131
});
132132
} else {
133133
// Replace end then start to avoid nested replacement issues when
@@ -138,7 +138,7 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
138138
if (!standardSection) {
139139
return '';
140140
}
141-
return ReadableContentHandler.append(formatterAdapter.lineBreak(), formatterAdapter.sectionEnd(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
141+
return ReadableContent.append(formatterAdapter.lineBreak(), formatterAdapter.sectionEnd(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
142142
});
143143
}
144144

@@ -148,12 +148,12 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
148148
if (!standardSection) {
149149
return '';
150150
}
151-
return ReadableContentHandler.append(formatterAdapter.sectionStart(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
151+
return ReadableContent.append(formatterAdapter.sectionStart(standardSection), formatterAdapter.lineBreak()).toString('utf-8');
152152
});
153153
}
154154
}
155155

156-
parts.push(ReadableContentHandler.from(out));
156+
parts.push(ReadableContent.from(out));
157157

158158
if (addNewline) {
159159
parts.push(formatterAdapter.lineBreak());
@@ -180,7 +180,7 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
180180
processLine(rem, false);
181181
}
182182

183-
return ReadableContentHandler.append(...parts);
183+
return ReadableContent.append(...parts);
184184
}
185185

186186
protected mapToStandardSection(sectionName: string) {
@@ -191,7 +191,7 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
191191
/**
192192
* Merge consecutive sections that map to the same target section
193193
*/
194-
private mergeConsecutiveSections(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
194+
private mergeConsecutiveSections(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
195195
let result = content.toString('utf-8');
196196

197197
// Pattern to match section start and end markers
@@ -253,20 +253,20 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
253253
const mergedContent = group.contents.join('').replace(/^\s*\n|\n\s*$/g, '').trim();
254254
const replacement = formatterAdapter.section(
255255
group.type,
256-
ReadableContentHandler.from(mergedContent)
256+
ReadableContent.from(mergedContent)
257257
).toString('utf-8');
258258

259259
result = result.substring(0, group.start) + replacement.trim() + result.substring(group.end);
260260
}
261261
});
262262

263-
return ReadableContentHandler.from(result);
263+
return ReadableContent.from(result);
264264
}
265265

266266
/**
267267
* Add missing supported section markers in the appropriate positions
268268
*/
269-
private addMissingSections(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
269+
private addMissingSections(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
270270

271271
const expectedSections: SectionIdentifier[] = Object.values(SectionIdentifier);
272272

@@ -338,20 +338,20 @@ export abstract class AbstractMigrationAdapter implements MigrationAdapter {
338338

339339
// If before doesn't end with a newline, add one
340340
const sep = /\n$/.test(before) ? '' : '\n';
341-
content = ReadableContentHandler.append(
342-
ReadableContentHandler.from(before),
343-
ReadableContentHandler.from(sep),
341+
content = ReadableContent.append(
342+
ReadableContent.from(before),
343+
ReadableContent.from(sep),
344344
formatterAdapter.lineBreak(),
345345
sectionContent,
346-
after.trim().length > 0 ? ReadableContentHandler.from(after) : Buffer.alloc(0)
346+
after.trim().length > 0 ? ReadableContent.from(after) : Buffer.alloc(0)
347347
);
348348
} else {
349349
// No suitable anchor, append at end with a preceding newline
350350
const sep = /\n$/.test(contentString) ? '' : '\n';
351351

352-
content = ReadableContentHandler.append(
352+
content = ReadableContent.append(
353353
content,
354-
ReadableContentHandler.from(sep),
354+
ReadableContent.from(sep),
355355
formatterAdapter.lineBreak(),
356356
sectionContent,
357357
);

packages/cicd/github-actions/src/migration/actdocs-migration.adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ActdocsMigrationAdapter extends AbstractMigrationAdapter {
3333
detectionPattern: /<!--\s*actdocs\s+\w+\s+(start|end)\s*-->/i,
3434
};
3535

36-
protected migrateContent(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
36+
protected migrateContent(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
3737
// Delegate the replacement logic to the shared helper in the abstract class.
3838
return this.processMarkerMappings(content, formatterAdapter);
3939
}

packages/cicd/github-actions/src/migration/action-docs-migration.adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ActionDocsMigrationAdapter extends AbstractMigrationAdapter {
3333
detectionPattern: /<!--\s*action-docs-\w+\s+source=["'][^"']+["']\s*-->/,
3434
};
3535

36-
protected migrateContent(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
36+
protected migrateContent(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
3737
// Delegate marker replacement and mapping to the base class helper which
3838
// operates on the provided content fragment to avoid allocating large
3939
// intermediate strings here.

packages/cicd/github-actions/src/migration/auto-doc-migration.adapter.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { injectable, injectFromBase } from 'inversify';
22
import { StringDecoder } from 'string_decoder';
33
import { SectionIdentifier } from '@ci-dokumentor/core';
4-
import { ReadableContentHandler } from '@ci-dokumentor/core';
4+
import { ReadableContent } from '@ci-dokumentor/core';
55
import type { FormatterAdapter, ReadableContent } from '@ci-dokumentor/core';
66
import { AbstractMigrationAdapter } from './abstract-migration.adapter.js';
77

@@ -32,7 +32,7 @@ export class AutoDocMigrationAdapter extends AbstractMigrationAdapter {
3232
detectionPattern: /^##\s+(Inputs|Outputs|Secrets|Description)\s*$/m,
3333
};
3434

35-
protected migrateContent(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
35+
protected migrateContent(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
3636

3737
const decoder = new StringDecoder('utf8');
3838
const chunkSize = 8 * 1024;
@@ -53,14 +53,14 @@ export class AutoDocMigrationAdapter extends AbstractMigrationAdapter {
5353
const sectionIdentifier = this.mapToStandardSection(current.sectionKey.toLowerCase());
5454
if (sectionIdentifier) {
5555
const contentPart = current.parts.length
56-
? ReadableContentHandler.append(ReadableContentHandler.from(current.headerLine), formatterAdapter.lineBreak(), ...current.parts)
57-
: ReadableContentHandler.from(current.headerLine);
56+
? ReadableContent.append(ReadableContent.from(current.headerLine), formatterAdapter.lineBreak(), ...current.parts)
57+
: ReadableContent.from(current.headerLine);
5858
const wrapped = formatterAdapter.section(sectionIdentifier, contentPart);
5959
outputParts.push(wrapped);
6060
} else {
6161
// Unknown section: emit original header + content as-is
62-
outputParts.push(ReadableContentHandler.from(current.headerLine), formatterAdapter.lineBreak());
63-
if (current.parts.length) outputParts.push(ReadableContentHandler.append(...current.parts));
62+
outputParts.push(ReadableContent.from(current.headerLine), formatterAdapter.lineBreak());
63+
if (current.parts.length) outputParts.push(ReadableContent.append(...current.parts));
6464
}
6565
current = null;
6666
};
@@ -80,10 +80,10 @@ export class AutoDocMigrationAdapter extends AbstractMigrationAdapter {
8080

8181
// Not a header
8282
if (current) {
83-
current.parts.push(ReadableContentHandler.from(line), formatterAdapter.lineBreak());
83+
current.parts.push(ReadableContent.from(line), formatterAdapter.lineBreak());
8484
} else {
8585
// Outside any section, preserve original content
86-
outputParts.push(ReadableContentHandler.from(line), formatterAdapter.lineBreak());
86+
outputParts.push(ReadableContent.from(line), formatterAdapter.lineBreak());
8787
}
8888
};
8989

@@ -107,6 +107,6 @@ export class AutoDocMigrationAdapter extends AbstractMigrationAdapter {
107107
// Flush any final open section
108108
flushCurrent();
109109

110-
return ReadableContentHandler.append(...outputParts);
110+
return ReadableContent.append(...outputParts);
111111
}
112112
}

packages/cicd/github-actions/src/migration/github-action-readme-generator-migration.adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class GitHubActionReadmeGeneratorMigrationAdapter extends AbstractMigrati
4141
detectionPattern: /<!--\s*(start|end)\s+[\w[\]/.-]+\s*-->/,
4242
};
4343

44-
protected migrateContent(content: ReadableContent, ReadableContentHandler, formatterAdapter: FormatterAdapter): ReadableContent {
44+
protected migrateContent(content: ReadableContent, ReadableContent, formatterAdapter: FormatterAdapter): ReadableContent {
4545
// The adapter needs some special normalization for example paths; we
4646
// perform normalization first by mapping any examples-like identifiers to
4747
// a canonical 'examples' key inside the fragment before handing it to the

packages/cicd/github-actions/src/section/badges-section-generator.adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReadableContent, ReadableContentHandler, ReadableContent, ReadableContentHandler, RepositoryProvider, SectionGenerationPayload, SectionGeneratorAdapter, SectionOptions } from '@ci-dokumentor/core';
1+
import { ReadableContent, ReadableContent, ReadableContent, ReadableContent, RepositoryProvider, SectionGenerationPayload, SectionGeneratorAdapter, SectionOptions } from '@ci-dokumentor/core';
22
import { GitHubActionsManifest } from '../github-actions-parser.js';
33
import { GitHubActionsSectionGeneratorAdapter } from './github-actions-section-generator.adapter.js';
44
import { FormatterAdapter, SectionIdentifier } from '@ci-dokumentor/core';
@@ -194,16 +194,16 @@ export class BadgesSectionGenerator extends GitHubActionsSectionGeneratorAdapter
194194
}
195195

196196
const badgeCollectionContent = linkedBadges.map((linkedBadge) => {
197-
let badgeContent = formatterAdapter.badge(ReadableContentHandler.from(linkedBadge.badge.label).from(linkedBadge.badge.url));
197+
let badgeContent = formatterAdapter.badge(ReadableContent.from(linkedBadge.badge.label).from(linkedBadge.badge.url));
198198
if (linkedBadge.url) {
199199
badgeContent = formatterAdapter.link(
200200
badgeContent,
201-
ReadableContentHandler.from(linkedBadge.url)
201+
ReadableContent.from(linkedBadge.url)
202202
);
203203
}
204204
return [badgeContent, formatterAdapter.lineBreak()];
205205
}).flat();
206206

207-
return ReadableContentHandler.append(...badgeCollectionContent);
207+
return ReadableContent.append(...badgeCollectionContent);
208208
}
209209
}

packages/cicd/github-actions/src/section/contributing-section-generator.adapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReadableContent, ReadableContentHandler, ReadableContent, ReadableContentHandler, SectionGenerationPayload } from '@ci-dokumentor/core';
1+
import { ReadableContent, ReadableContent, ReadableContent, ReadableContent, SectionGenerationPayload } from '@ci-dokumentor/core';
22
import { GitHubActionsManifest } from '../github-actions-parser.js';
33
import { GitHubActionsSectionGeneratorAdapter } from './github-actions-section-generator.adapter.js';
44
import { SectionIdentifier } from '@ci-dokumentor/core';
@@ -19,10 +19,10 @@ export class ContributingSectionGenerator extends GitHubActionsSectionGeneratorA
1919

2020
const contributingText = `Contributions are welcome! Please see the [contributing guidelines](${contributingInfo.url}) for more details.`;
2121

22-
return ReadableContentHandler.append(
23-
formatterAdapter.heading(ReadableContentHandler.from('Contributing'), 2),
22+
return ReadableContent.append(
23+
formatterAdapter.heading(ReadableContent.from('Contributing'), 2),
2424
formatterAdapter.lineBreak(),
25-
formatterAdapter.paragraph(ReadableContentHandler.from(contributingText)),
25+
formatterAdapter.paragraph(ReadableContent.from(contributingText)),
2626
);
2727
}
2828
}

packages/cicd/github-actions/src/section/examples-section-generator.adapter.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect, beforeEach, afterEach, vi, Mocked } from 'vitest';
22
import { ExamplesSectionGenerator } from './examples-section-generator.adapter.js';
3-
import { VersionService, SectionIdentifier, ManifestVersion, ReadableContent, ReadableContentHandler, FormatterAdapter, RepositoryProvider, ReaderAdapter } from '@ci-dokumentor/core';
3+
import { VersionService, SectionIdentifier, ManifestVersion, ReadableContent, ReadableContent, FormatterAdapter, RepositoryProvider, ReaderAdapter } from '@ci-dokumentor/core';
44
import { GitHubAction, GitHubWorkflow } from '../github-actions-parser.js';
55
import { ReaderAdapterMockFactory, RepositoryInfoMockFactory, RepositoryProviderMockFactory, VersionServiceMockFactory } from '@ci-dokumentor/core/tests';
66

packages/cicd/github-actions/src/section/examples-section-generator.adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class ExamplesSectionGenerator extends GitHubActionsSectionGeneratorAdapt
102102
}
103103
}
104104

105-
return ReadableContentHandler.append(...examplesContent);
105+
return ReadableContent.append(...examplesContent);
106106
}
107107

108108
/**
@@ -289,7 +289,7 @@ export class ExamplesSectionGenerator extends GitHubActionsSectionGeneratorAdapt
289289
/**
290290
* Process code snippets to replace or add version information for action calls
291291
*/
292-
private processCodeSnippet(code: ReadableContent, ReadableContentHandler, usesName: string, version?: ManifestVersion): ReadableContent {
292+
private processCodeSnippet(code: ReadableContent, ReadableContent, usesName: string, version?: ManifestVersion): ReadableContent {
293293
if (!version || !version.sha) {
294294
return code;
295295
}

packages/cicd/github-actions/src/section/generated-section-generator.adapter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReadableContent, ReadableContentHandler, ReadableContent, ReadableContentHandler, SectionGenerationPayload } from '@ci-dokumentor/core';
1+
import { ReadableContent, ReadableContent, ReadableContent, ReadableContent, SectionGenerationPayload } from '@ci-dokumentor/core';
22
import { GitHubActionsManifest } from '../github-actions-parser.js';
33
import { GitHubActionsSectionGeneratorAdapter } from './github-actions-section-generator.adapter.js';
44
import { SectionIdentifier } from '@ci-dokumentor/core';
@@ -13,10 +13,10 @@ export class GeneratedSectionGenerator extends GitHubActionsSectionGeneratorAdap
1313
async generateSection({ formatterAdapter }: SectionGenerationPayload<GitHubActionsManifest>): Promise<ReadableContent> {
1414
const generatedText = 'This documentation was automatically generated by [CI Dokumentor](https://github.com/hoverkraft-tech/ci-dokumentor).';
1515

16-
return ReadableContentHandler.append(
16+
return ReadableContent.append(
1717
formatterAdapter.horizontalRule(),
1818
formatterAdapter.lineBreak(),
19-
formatterAdapter.paragraph(ReadableContentHandler.from(generatedText)),
19+
formatterAdapter.paragraph(ReadableContent.from(generatedText)),
2020
);
2121
}
2222
}

0 commit comments

Comments
 (0)