From d97c294dd2024215acf88741263f6abbc29d6c31 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 19 May 2020 23:50:24 -0700 Subject: [PATCH] feat: update DEP0XXX tags during release prep --- lib/prepare_release.js | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/lib/prepare_release.js b/lib/prepare_release.js index 9a5b12c9..9eec1706 100644 --- a/lib/prepare_release.js +++ b/lib/prepare_release.js @@ -113,6 +113,11 @@ class ReleasePreparation { await this.updateREPLACEMEs(); cli.stopSpinner('Updated REPLACEME items in docs'); + // Update any new deprecations in the codebase. + cli.startSpinner('Updating DEPOXXX items in codebase'); + const depCount = await this.updateDeprecations(); + cli.stopSpinner(`Updated ${depCount} DEPOXXX items in codebase`); + // Fetch date to use in release commit & changelogs. const todayDate = new Date().toISOString().split('T')[0]; this.date = await cli.prompt('Enter release date in YYYY-MM-DD format:', @@ -225,6 +230,45 @@ class ReleasePreparation { ]).trim(); } + async updateDeprecations() { + const deprecationPattern = + /<\s*a id="DEP0([0-9]{3})+"[^>]*><\s*\/\s*a>/g; + const newDeprecationPattern = + /<\s*a id="DEP0([X]+[0-9]*)+"[^>]*><\s*\/\s*a>/g; + + const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md'); + const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8'); + + const deprecationNumbers = [ + ...deprecationFile.matchAll(deprecationPattern) + ].map(m => m[1]).reverse(); + const newDeprecationNumbers = [ + ...deprecationFile.matchAll(newDeprecationPattern) + ].map(m => m[1]); + + // Pull highest deprecation number off the list and increment from there. + let depNumber = parseInt(deprecationNumbers[0]) + 1; + + // Loop through each new unmarked deprecation number and replace instances. + for (const newDep of newDeprecationNumbers) { + await replace({ + files: [ + 'doc/api/*.md', + 'lib/**/*.js', + 'src/**/*.{h,cc}', + 'test/**/*.js' + ], + ignore: 'test/common/README.md', + from: new RegExp(`DEP0${newDep}`, 'g'), + to: `DEP0${depNumber}` + }); + + depNumber++; + } + + return newDeprecationNumbers.length; + } + async updateREPLACEMEs() { const { newVersion } = this;