#!/usr/bin/env node // [start-readme] // // This script goes through all content and renders their HTML and from there // can analyze for various flaws (e.g. broken links) // // [end-readme] import fs from 'fs' import path from 'path' import { program, Option, InvalidArgumentError } from 'commander' import renderedContentLinkChecker from '../.github/actions-scripts/rendered-content-link-checker.js' import { getCoreInject, getUploadArtifactInject } from './helpers/action-injections.js' import { allVersions } from '../lib/all-versions.js' import github from './helpers/github.js' const STATIC_PREFIXES = { assets: path.resolve('assets'), public: path.resolve(path.join('data', 'graphql')), } // Sanity check that these are valid paths Object.entries(STATIC_PREFIXES).forEach(([key, value]) => { if (!fs.existsSync(value)) { throw new Error(`Can't find static prefix (${key}): ${value}`) } }) program .description('Analyze all checked content files, render them, and check for flaws.') .addOption( new Option( '-L, --level ', 'Level of broken link to be marked as a flaw (default: "warning")' ).choices(['all', 'warning', 'critical']) ) .option('-f, --filter ', 'Search filter(s) on the paths') .option( '-V, --version ', "Specific versions to only do (e.g. 'free-pro-team@latest')", (version) => { if (!(version in allVersions)) { for (const [key, data] of Object.entries(allVersions)) { if (version === data.miscVersionName) { return key } } throw new InvalidArgumentError( `'${version}' is not a recognized version. (not one of ${Object.keys(allVersions)})` ) } return version } ) .option('-v, --verbose', 'Verbose outputs') .option( '--create-report', 'Create a report issue in report-repository if there are flaws. (default: false)' ) .option( '--report-repository ', 'Repository to create issue in. (default: "github/docs-content")' ) .option( '--link-reports', 'If comments should be made on previous report and new report "linking" them. (default: false)' ) .option( '--report-author ', 'Previous author of report PR for linking. (default: "docs-bot")' ) .option( '--report-label