Browse Source

update conch logic (#38599)

pull/38608/head
二货爱吃白萝卜 2 years ago
committed by GitHub
parent
commit
59134781d9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      scripts/post-script.js

30
scripts/post-script.js

@ -6,6 +6,8 @@ const chalk = require('chalk');
const { spawnSync } = require('child_process');
const packageJson = require('../package.json');
const CONCH_TAG = 'conch-v5';
const DEPRECIATED_VERSION = {
'>= 4.21.6 < 4.22.0': ['https://github.com/ant-design/ant-design/pull/36682'],
'>=4.22.2 <=4.22.5': [
@ -22,7 +24,7 @@ const DEPRECIATED_VERSION = {
};
function matchDeprecated(version) {
const match = Object.keys(DEPRECIATED_VERSION).find(depreciated =>
const match = Object.keys(DEPRECIATED_VERSION).find((depreciated) =>
semver.satisfies(version, depreciated),
);
@ -45,15 +47,15 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
return;
}
const { time, 'dist-tags': distTags } = await fetch('http://registry.npmjs.org/antd').then(res =>
res.json(),
const { time, 'dist-tags': distTags } = await fetch('http://registry.npmjs.org/antd').then(
(res) => res.json(),
);
console.log('🐚 Latest Conch Version:', chalk.green(distTags.conch || 'null'), '\n');
console.log('🐚 Latest Conch Version:', chalk.green(distTags[CONCH_TAG] || 'null'), '\n');
// Sort and get the latest versions
const versionList = Object.keys(time)
.filter(version => semver.valid(version) && !semver.prerelease(version))
.filter((version) => semver.valid(version) && !semver.prerelease(version))
.sort((v1, v2) => {
const time1 = dayjs(time[v1]).valueOf();
const time2 = dayjs(time[v2]).valueOf();
@ -66,7 +68,7 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
// Cut off
.slice(0, 30)
// Formatter
.map(version => ({
.map((version) => ({
publishTime: time[version],
timeDiff: dayjs().diff(dayjs(time[version])),
value: version,
@ -102,8 +104,8 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
let defaultVersion = defaultVersionObj ? defaultVersionObj.value : null;
// If default version is less than current, use current
if (semver.compare(defaultVersion, distTags.conch) < 0) {
defaultVersion = distTags.conch;
if (semver.compare(defaultVersion, distTags[CONCH_TAG]) < 0) {
defaultVersion = distTags[CONCH_TAG];
}
const { default: inquirer } = await import('inquirer');
@ -114,7 +116,7 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
name: 'conchVersion',
default: defaultVersion,
message: 'Please select Conch Version:',
choices: latestVersions.map(info => {
choices: latestVersions.map((info) => {
const { value, publishTime, depreciated } = info;
const desc = dayjs(publishTime).fromNow();
@ -132,9 +134,9 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
// Default Mark
value === defaultVersion ? '(default)' : '',
// Current Mark
value === distTags.conch ? chalk.gray('- current') : '',
value === distTags[CONCH_TAG] ? chalk.gray('- current') : '',
]
.filter(str => String(str).trim())
.filter((str) => String(str).trim())
.join(' '),
};
}),
@ -146,7 +148,7 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
if (deprecatedObj.match) {
console.log('\n');
console.log(chalk.red('Deprecated For:'));
deprecatedObj.reason.forEach(reason => {
deprecatedObj.reason.forEach((reason) => {
console.log(chalk.yellow(` * ${reason}`));
});
console.log('\n');
@ -166,11 +168,11 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
}
// Check if need to update
if (!conchVersion || distTags.conch === conchVersion) {
if (!conchVersion || distTags[CONCH_TAG] === conchVersion) {
console.log(`🎃 Conch Version not change. Safe to ${chalk.green('ignore')}.`);
} else {
console.log('💾 Tagging Conch Version:', chalk.green(conchVersion));
spawnSync('npm', ['dist-tag', 'add', `antd@${conchVersion}`, 'conch'], {
spawnSync('npm', ['dist-tag', 'add', `antd@${conchVersion}`, CONCH_TAG], {
stdio: 'inherit',
stdin: 'inherit',
});

Loading…
Cancel
Save