Skip to content

Commit

Permalink
feat: add syncGithubFiles.mjs script
Browse files Browse the repository at this point in the history
  • Loading branch information
DukeFerdinand committed Nov 5, 2024
1 parent 57965ad commit 207009d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
88 changes: 88 additions & 0 deletions scripts/build/syncGithubFiles.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {Logger} from "../utils/logger.mjs";
import {
fromAuroComponentRoot,
generateReadmeUrl, generateWCGeneratorUrl,
processContentForFile,
templateFiller
} from "../utils/sharedFileProcessorUtils.mjs";

// Finally, the main function
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/**
* Processor config object.
* @typedef {Object} ProcessorConfig
* @property {boolean} [overwriteLocalCopies=true] - The release version tag to use instead of master.
* @property {string} [generatorTemplateVersion="master"] - The release version tag to use instead of master.
* (like "_esm" to make README_esm.md).
*/

const DOT_GITHUB_PATH = '.github';
const ISSUE_TEMPLATE_PATH = `${DOT_GITHUB_PATH}/ISSUE_TEMPLATE`;

/**
* @param {ProcessorConfig} config - The configuration for this processor.
* @return {import('../utils/sharedFileProcessorUtils').FileProcessorConfig[]}
*/
const generateFiles = (config) => [
// bug_report.yml
{
identifier: 'bug_report.yml',
input: {
remoteUrl: generateWCGeneratorUrl(config.generatorTemplateVersion, `templates/${ISSUE_TEMPLATE_PATH}/bug_report.yml`),
fileName: fromAuroComponentRoot(`docTemplates/${ISSUE_TEMPLATE_PATH}/bug_report.yml`),
overwrite: config.overwriteLocalCopies
},
output: fromAuroComponentRoot(`${ISSUE_TEMPLATE_PATH}/bug_report.yml`)
},
// config.yml
{
identifier: 'config.yml',
input: {
remoteUrl: generateWCGeneratorUrl(config.generatorTemplateVersion, `templates/${ISSUE_TEMPLATE_PATH}/config.yml`),
fileName: fromAuroComponentRoot(`docTemplates/${ISSUE_TEMPLATE_PATH}/config.yml`),
overwrite: config.overwriteLocalCopies
},
output: fromAuroComponentRoot(`${ISSUE_TEMPLATE_PATH}/config.yml`)
},
// PULL_REQUEST_TEMPLATE.md
{
identifier: 'PULL_REQUEST_TEMPLATE.md',
input: {
remoteUrl: generateWCGeneratorUrl(config.generatorTemplateVersion, `templates/${DOT_GITHUB_PATH}/PULL_REQUEST_TEMPLATE.md`),
fileName: fromAuroComponentRoot(`docTemplates/${DOT_GITHUB_PATH}/PULL_REQUEST_TEMPLATE.md`),
overwrite: config.overwriteLocalCopies
},
output: fromAuroComponentRoot(`${DOT_GITHUB_PATH}/PULL_REQUEST_TEMPLATE.md`)
},
];

/**
*
* @param {ProcessorConfig} config - The configuration for this processor.
* @return {Promise<void>}
*/
export async function syncGithubFiles(config = {
overwriteLocalCopies: true,
generatorTemplateVersion: "master",
}) {
// setup
await templateFiller.extractNames();

for (const file of generateFiles(config)) {
try {
Logger.log(`Processing file: ${file.identifier}`);
// eslint-disable-next-line no-await-in-loop
await processContentForFile(file);
} catch (error) {
Logger.error(`Error processing file: ${file.identifier}, ${error.message}`);
}
}
}

syncGithubFiles().then(() => {
Logger.log('Docs processed successfully');
}).
catch((err) => {
Logger.error(`Error processing docs: ${err.message}`);
});
5 changes: 3 additions & 2 deletions scripts/utils/sharedFileProcessorUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export function generateReadmeUrl(branchOrTag = 'master', variantOverride = '')

/**
* @typedef {Object} FileProcessorConfig
* @property {string | InputFileType} input - path to input file, including filename
* @property {string} output - path to output file, including filename
* @property {string} identifier - A unique identifier for this file (used for logging).
* @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>} [postProcessors] - extra processor functions to run on content
*/
Expand Down

0 comments on commit 207009d

Please sign in to comment.