chore: Support deprecated version warning (#36701)

pull/36711/head
二货机器人 3 years ago committed by GitHub
parent 78bc4a3537
commit 789a557b84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,23 @@ const inquirer = require('inquirer');
const chalk = require('chalk');
const { spawnSync } = require('child_process');
const DEPRECIATED_VERSION = {
'>= 4.21.6 < 4.22.0': ['https://github.com/ant-design/ant-design/pull/36682'],
};
function matchDeprecated(version) {
const match = Object.keys(DEPRECIATED_VERSION).find(depreciated =>
semver.satisfies(version, depreciated),
);
const reason = DEPRECIATED_VERSION[match] || [];
return {
match,
reason: Array.isArray(reason) ? reason : [reason],
};
}
const SAFE_DAYS_START = 1000 * 60 * 60 * 24 * 15; // 15 days
const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be stable
@ -28,16 +45,27 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
});
// Slice for choosing the latest versions
const latestVersions = versionList.slice(0, 20).map(version => ({
publishTime: time[version],
timeDiff: moment().diff(moment(time[version])),
value: version,
}));
const latestVersions = versionList
// Cut off
.slice(0, 30)
// Formatter
.map(version => ({
publishTime: time[version],
timeDiff: moment().diff(moment(time[version])),
value: version,
depreciated: matchDeprecated(version).match,
}));
const filteredLatestVersions = latestVersions
// Filter deprecated versions
.filter(({ depreciated }) => !depreciated);
const startDefaultVersionIndex = latestVersions.findIndex(
const startDefaultVersionIndex = filteredLatestVersions.findIndex(
({ timeDiff }) => timeDiff >= SAFE_DAYS_START,
);
const defaultVersionList = latestVersions.slice(0, startDefaultVersionIndex + 1).reverse();
const defaultVersionList = filteredLatestVersions
.slice(0, startDefaultVersionIndex + 1)
.reverse();
// Find safe version
let defaultVersionObj;
@ -57,26 +85,52 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
const defaultVersion = defaultVersionObj ? defaultVersionObj.value : null;
// Selection
const { conchVersion } = await inquirer.prompt([
let { conchVersion } = await inquirer.prompt([
{
type: 'list',
name: 'conchVersion',
default: defaultVersion,
message: 'Please select Conch Version:',
choices: latestVersions.map(info => {
const { value, publishTime } = info;
const { value, publishTime, depreciated } = info;
const desc = moment(publishTime).fromNow();
return {
...info,
name: `${value} (${desc}) ${value === defaultVersion ? '(default)' : ''}`,
name: `${depreciated ? '🚨' : '✅'} ${value} (${desc}) ${
value === defaultVersion ? '(default)' : ''
}`,
};
}),
},
]);
// Make sure it's not deprecated version
const deprecatedObj = matchDeprecated(conchVersion);
if (deprecatedObj.match) {
console.log('\n');
console.log(chalk.red('Deprecated For:'));
deprecatedObj.reason.forEach(reason => {
console.log(chalk.yellow(` * ${reason}`));
});
console.log('\n');
const { conchConfirm } = await inquirer.prompt([
{
type: 'confirm',
name: 'conchVersion',
default: false,
message: 'SURE to continue?!!',
},
]);
if (!conchConfirm) {
conchVersion = null;
}
}
// Check if need to update
if (distTags.conch === conchVersion) {
if (!conchVersion || distTags.conch === conchVersion) {
console.log(`🎃 Conch Version not change. Safe to ${chalk.green('ignore')}.`);
} else {
console.log('💾 Tagging Conch Version:', chalk.green(conchVersion));

Loading…
Cancel
Save