Skip to content

Commit

Permalink
fix: make api table formatter a preProcessor
Browse files Browse the repository at this point in the history
- add preProcessors since api table formatting completely breaks api.md when run after templateReplacer
  • Loading branch information
DukeFerdinand committed Nov 5, 2024
1 parent 13e0aed commit 6366cff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/build/processors/defaultDocsProcessor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const fileConfigs = (config) => [
identifier: 'api.md',
input: fromAuroComponentRoot("/docs/partials/api.md"),
output: fromAuroComponentRoot("/demo/api.md"),
postProcessors: [templateFiller.formatApiTable],
preProcessors: [templateFiller.formatApiTable],
}
];

Expand Down
18 changes: 14 additions & 4 deletions scripts/utils/sharedFileProcessorUtils.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import path from 'path';
import * as mdMagic from 'markdown-magic';
import fs from 'node:fs/promises';
import { fileURLToPath } from 'url';

import AuroLibraryUtils from "./auroLibraryUtils.mjs";
import { AuroTemplateFiller } from "./auroTemplateFiller.mjs";
Expand Down Expand Up @@ -75,8 +73,12 @@ export const nonEsmComponents = ['combobox', 'datepicker', 'menu', 'pane', 'sele
*/
// TODO: test this in auro-flight before merging to main
export function fromAuroComponentRoot(pathLike) {
const currentDir = fileURLToPath(new URL('.', import.meta.url))
return path.join(currentDir, `${auroLibraryUtils.getProjectRootPath}${pathLike}`)
if (pathLike.startsWith('/')) {
// remove the first slash
return auroLibraryUtils.getProjectRootPath + pathLike.slice(1)
}

return auroLibraryUtils.getProjectRootPath + pathLike
}


Expand Down Expand Up @@ -149,6 +151,7 @@ export function generateReadmeUrl(branchOrTag = 'master', variantOverride = '')
* @property {string | InputFileType} input - path to an input file, including filename
* @property {string} output - path to an output file, including filename
* @property {Partial<MarkdownMagicOptions>} [mdMagicConfig] - extra configuration options for md magic
* @property {Array<(contents: string) => string>} [preProcessors] - extra processor functions to run on content AFTER markdownmagic and BEFORE templateFiller
* @property {Array<(contents: string) => string>} [postProcessors] - extra processor functions to run on content
*/

Expand Down Expand Up @@ -241,6 +244,13 @@ export async function processContentForFile(config) {
// 3a. Read the output file contents
let fileContents = await fs.readFile(output, {encoding: 'utf-8'});

// 3c. Run any post-processors
if (config.postProcessors) {
for (const processor of config.postProcessors) {
fileContents = processor(fileContents)
}
}

// 3b. Replace template variables in output file
fileContents = templateFiller.replaceTemplateValues(fileContents);

Expand Down

0 comments on commit 6366cff

Please sign in to comment.