Skip to content

Commit 31b2f56

Browse files
authored
feat(legacy-json): make source path configurable (#1111)
1 parent d97e261 commit 31b2f56

7 files changed

Lines changed: 16 additions & 8 deletions

File tree

‎packages/node-legacy/src/legacy-json-all/generate.mjs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { writeFile } from 'node:fs/promises';
44
import { join } from 'node:path';
55

66
import getConfig from '@doc-kit/core/utils/configuration/index.mjs';
7+
import { populate } from '@doc-kit/core/utils/configuration/templates.mjs';
78

89
import { legacyToJSON } from '../utils/legacyToJSON.mjs';
910

@@ -36,8 +37,10 @@ export async function generate(input) {
3637

3738
// Create a map of api name to index position for sorting
3839
const indexOrder = new Map(
39-
config.index?.map(({ api }, position) => [`doc/api/${api}.md`, position]) ??
40-
[]
40+
config.index?.map(({ api }, position) => [
41+
populate(config.sourceURL, { path: `${api}.md` }),
42+
position,
43+
]) ?? []
4144
);
4245

4346
// Sort input by index order (documents not in index go to the end)

‎packages/node-legacy/src/legacy-json-all/index.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default {
1818

1919
defaultConfiguration: {
2020
minify: false,
21+
sourceURL: 'doc/api/{path}',
2122
},
2223

2324
generate,

‎packages/node-legacy/src/legacy-json-all/types.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ export interface Output {
1414
}
1515

1616
export type Generator = GeneratorMetadata<
17-
{},
17+
{ sourceURL: string },
1818
Generate<Array<Section>, Promise<Output>>
1919
>;

‎packages/node-legacy/src/legacy-json/generate.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ const buildSection = createSectionBuilder();
2222
*/
2323
export async function processChunk(slicedInput, itemIndices) {
2424
const results = [];
25+
const config = getConfig('legacy-json');
26+
const sourceURL = config.sourceURL;
2527

2628
for (const idx of itemIndices) {
2729
const { head, nodes } = slicedInput[idx];
2830

29-
results.push(buildSection(head, nodes));
31+
results.push(buildSection(head, nodes, sourceURL));
3032
}
3133

3234
return results;

‎packages/node-legacy/src/legacy-json/index.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default {
2323
defaultConfiguration: {
2424
ref: 'main',
2525
minify: false,
26+
sourceURL: 'doc/api/{path}',
2627
},
2728

2829
hasParallelProcessor: true,

‎packages/node-legacy/src/legacy-json/types.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export interface MiscSection extends SectionBase {
179179
}
180180

181181
export type Generator = GeneratorMetadata<
182-
{},
182+
{ sourceURL: string },
183183
Generate<Array<MetadataEntry>, AsyncGenerator<Section>>,
184184
ProcessChunk<{ head: MetadataEntry; nodes: Array<MetadataEntry> }, Section>
185185
>;

‎packages/node-legacy/src/legacy-json/utils/buildSection.mjs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { enforceArray } from '@doc-kit/core/utils/array.mjs';
2+
import { populate } from '@doc-kit/core/utils/configuration/templates.mjs';
23
import { buildHierarchy } from '@doc-kit/core/utils/hierarchy.mjs';
34
import { getRemarkRehype as remark } from '@doc-kit/core/utils/remark.mjs';
45
import { parseList } from '@doc-kit/core/utils/signature/parseList.mjs';
@@ -183,14 +184,14 @@ export const createSectionBuilder = () => {
183184
* Builds the module section from head metadata and entries.
184185
* @param {import('@doc-kit/core/generators/metadata/types').MetadataEntry} head - The head metadata entry.
185186
* @param {Array<import('@doc-kit/core/generators/metadata/types').MetadataEntry>} entries - The list of metadata entries.
187+
* @param {string} sourceURL - The template URL for the generated API source files.
186188
* @returns {import('../types.d.ts').ModuleSection} The constructed module section.
187189
*/
188-
return (head, entries) => {
190+
return (head, entries, sourceURL) => {
189191
const rootModule = {
190192
type: 'module',
191193
api: head.api,
192-
// TODO(@avivkeller): This should be configurable
193-
source: `doc/api/${head.api}.md`,
194+
source: populate(sourceURL, { path: `${head.api}.md` }),
194195
};
195196

196197
buildHierarchy(entries).forEach(node => handleEntry(node, rootModule));

0 commit comments

Comments
 (0)