From 2e6794f7b9ae3b4e33506b01bc83573e88144711 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Wed, 29 Mar 2023 18:34:51 -0400 Subject: [PATCH] make script/update-internal-links more user-friendly (#35992) --- .github/workflows/test.yml | 4 ++-- script/update-internal-links.js | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 89aaf64b6b95..4234b8f29f34 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -97,11 +97,11 @@ jobs: run: | # If either of these fail, it means our fixture content's internal # links can and should be updated. - ./script/update-internal-links.js --dry-run --check --strict --verbose \ + ./script/update-internal-links.js --dry-run --check --strict \ tests/fixtures/content \ --exclude tests/fixtures/content/get-started/foo/typo-autotitling.md \ --exclude tests/fixtures/content/get-started/foo/anchor-autotitling.md - ./script/update-internal-links.js --dry-run --check --strict --verbose \ + ./script/update-internal-links.js --dry-run --check --strict \ tests/fixtures/data - name: Clone all translations diff --git a/script/update-internal-links.js b/script/update-internal-links.js index 8b8854f43bf0..6677b317f7c5 100755 --- a/script/update-internal-links.js +++ b/script/update-internal-links.js @@ -22,7 +22,7 @@ import walkFiles from './helpers/walk-files.js' program .description('Update internal links in content files') - .option('-v, --verbose', 'Verbose outputs') + .option('--silent', 'The opposite of verbose') .option('--debug', "Don't hide any errors") .option('--dry-run', "Don't actually write changes to disk") .option('--dont-set-autotitle', "Do NOT transform the link text to 'AUTOTITLE' (if applicable)") @@ -77,11 +77,17 @@ async function main(files, opts) { throw new Error(`No files found in ${files}`) } + const verbose = !opts.silent + + if (verbose) { + console.log(chalk.bold(`Updating internal links in ${actualFiles.length} found files...`)) + } + // The updateInternalLinks doesn't use "negatives" for certain options const options = { setAutotitle: !opts.dontSetAutotitle, fixHref: !opts.dontFixHref, - verbose: !!opts.verbose, + verbose, strict: !!opts.strict, } @@ -108,11 +114,11 @@ async function main(files, opts) { const differentContent = content !== newContent const differentData = !equalObject(data, newData) if (differentContent || differentData) { - if (opts.verbose || opts.check) { + if (verbose || opts.check) { if (opts.check) { exitCheck++ } - if (opts.verbose) { + if (verbose) { console.log( opts.dryRun ? 'Would change...' : 'Will change...', chalk.bold(file), @@ -188,7 +194,9 @@ async function main(files, opts) { } if (exitCheck) { - console.log(chalk.yellow(`More than one file would become different. Unsuccessful check.`)) + if (verbose) { + console.log(chalk.yellow(`More than one file would become different. Unsuccessful check.`)) + } process.exit(exitCheck) } else if (opts.check) { console.log(chalk.green('No changes needed or necessary. 🌈'))