Skip to content

Commit

Permalink
feat(dgeni): add paths configurators (#2968)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Aug 14, 2024
1 parent 8bb271f commit fc81125
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Package } from 'dgeni';

import {
DaffDocKind,
DAFF_DOC_KIND_PATH_SEGMENT_MAP,
} from '@daffodil/docs-utils';

import { GenerateApiListProcessor } from '../../../processors/generateApiList';
import { Configurator } from '../../../utils/configurator.type';

export interface OutputPathsConfig {
kind: DaffDocKind;
outputPath: string;
}

// TODO: combine with guide configurator
export const outputPathsConfigurator: Configurator<OutputPathsConfig> = (config: OutputPathsConfig) => (pkg: Package) => pkg
.processor(new GenerateApiListProcessor())
.config((generateApiList: GenerateApiListProcessor) => {
generateApiList.outputFolder = `${config.outputPath}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[config.kind]}`;
})
.config((computePathsProcessor) => {
computePathsProcessor.pathTemplates.push({
docTypes: ['package'],
getPath: (doc) => {
doc.moduleFolder = `${config.outputPath}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[config.kind]}/${doc.id}`;
return doc.moduleFolder;
},
outputPathTemplate: '${moduleFolder}.json',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Package } from 'dgeni';
import { Configurator } from 'tools/dgeni/src/utils/configurator.type';

import {
DaffDocKind,
DAFF_DOC_KIND_PATH_SEGMENT_MAP,
} from '@daffodil/docs-utils';

export interface InputPathsConfig {
kind: DaffDocKind;
inputPathBase: string;
}

export const inputPathsConfigurator: Configurator<InputPathsConfig> = (config: InputPathsConfig) => (pkg: Package) => pkg
.config((readFilesProcessor) => {
readFilesProcessor.basePath = `${config.inputPathBase}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[config.kind]}`;
readFilesProcessor.sourceFiles = [
{ include: [
'**/*.md',
]},
];
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Package } from 'dgeni';

import {
DaffDocKind,
DAFF_DOC_KIND_PATH_SEGMENT_MAP,
} from '@daffodil/docs-utils';

import { Configurator } from '../../../../utils/configurator.type';
import { GenerateGuideListProcessor } from '../../processors/generateGuideList';

export interface OutputPathsConfig {
kind: DaffDocKind;
outputPath: string;
}

export const outputPathsConfigurator: Configurator<OutputPathsConfig> = (config: OutputPathsConfig) => (pkg: Package) => pkg
.processor(new GenerateGuideListProcessor())
.config((generateGuideList: GenerateGuideListProcessor) => {
generateGuideList.outputFolder = `${config.outputPath}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[config.kind]}`;
})
.config((computePathsProcessor) => {
computePathsProcessor.pathTemplates.push({
docTypes: ['guide'],
getPath: (doc) => {
doc.moduleFolder = `${config.outputPath}/${DAFF_DOC_KIND_PATH_SEGMENT_MAP[config.kind]}/${doc.id}`;
return `/${doc.moduleFolder}`;
},
outputPathTemplate: '${moduleFolder}.json',
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Package } from 'dgeni';

import {
InputPathsConfig,
inputPathsConfigurator,
} from './input';
import {
OutputPathsConfig,
outputPathsConfigurator,
} from './output';
import { Configurator } from '../../../../utils/configurator.type';

export type PathsConfig = InputPathsConfig & OutputPathsConfig;

export const pathsConfigurator: Configurator<PathsConfig> = (config: PathsConfig) => (pkg: Package) =>
outputPathsConfigurator(config)(inputPathsConfigurator(config)(pkg));

0 comments on commit fc81125

Please sign in to comment.