Skip to content

Commit

Permalink
make script/update-internal-links more user-friendly (#35992)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbe authored Mar 29, 2023
1 parent 2fd31a2 commit 2e6794f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 13 additions & 5 deletions script/update-internal-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -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,
}

Expand All @@ -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),
Expand Down Expand Up @@ -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. 🌈'))
Expand Down

0 comments on commit 2e6794f

Please sign in to comment.