Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some small pathing issues with new script #88

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/build/processors/defaultDocsProcessor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export const defaultDocsProcessorConfig = {
// eslint-disable-next-line no-warning-comments
// TODO: remove this variant when all components are updated to use latest auro-library
// AND the default README.md is updated to use the new paths
readmeVariant: "_updated_paths"
remoteReadmeVariant: "_updated_paths"
};

/**
* @param {ProcessorConfig} config - The configuration for this processor.
* @returns {import('../utils/sharedFileProcessorUtils').FileProcessorConfig[]}
*/
export const fileConfigs = (config = defaultDocsProcessorConfig) => [
export const fileConfigs = (config) => [
// README.md
{
identifier: 'README.md',
Expand All @@ -59,7 +59,7 @@ export const fileConfigs = (config = defaultDocsProcessorConfig) => [
identifier: 'api.md',
input: fromAuroComponentRoot("/docs/partials/api.md"),
output: fromAuroComponentRoot("/demo/api.md"),
postProcessors: [templateFiller.formatApiTable],
preProcessors: [templateFiller.formatApiTable],
}
];

Expand Down
10 changes: 3 additions & 7 deletions scripts/utils/auroLibraryUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@
import * as fs from 'fs';
import * as path from 'path';
import chalk from 'chalk';
import { fileURLToPath } from 'url';

import {Logger} from "./logger.mjs";

export default class AuroLibraryUtils {
getDirname() {
if (typeof __dirname === 'undefined') {
Logger.warn('Unable to determine project root as __dirname is not defined. Assuming current directory is okay!', true);
return '';
}

// eslint-disable-next-line no-undef
return __dirname;
return fileURLToPath(import.meta.url);
}

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

import AuroLibraryUtils from "./auroLibraryUtils.mjs";
import { AuroTemplateFiller } from "./auroTemplateFiller.mjs";
Expand Down Expand Up @@ -75,8 +74,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 path.join(auroLibraryUtils.getProjectRootPath, pathLike.slice(1))
}

return path.join(auroLibraryUtils.getProjectRootPath, pathLike)
}


Expand Down Expand Up @@ -149,6 +152,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,17 +245,24 @@ export async function processContentForFile(config) {
// 3a. Read the output file contents
let fileContents = await fs.readFile(output, {encoding: 'utf-8'});

// 3b. Replace template variables in output file
// 3b. Run any pre-processors
if (config.preProcessors) {
for (const processor of config.preProcessors) {
fileContents = processor(fileContents)
}
}

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

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

// 3d. Write the final file contents
// 3e. Write the final file contents
if (!await AuroFileHandler.tryWriteFile(output, fileContents)) {
throw new Error(`Error writing "${bareFileName}" file to output ${output}`);
}
Expand Down