2022-01-24 11:26:26 +08:00
|
|
|
/* eslint-disable no-console */
|
2023-07-28 16:17:43 +08:00
|
|
|
const { spawnSync } = require('child_process');
|
2023-04-29 12:52:56 +08:00
|
|
|
const fetch = require('isomorphic-fetch');
|
|
|
|
const semver = require('semver');
|
|
|
|
const dayjs = require('dayjs');
|
|
|
|
const chalk = require('chalk');
|
|
|
|
const relativeTime = require('dayjs/plugin/relativeTime');
|
2022-01-19 15:27:05 +08:00
|
|
|
|
2022-12-13 23:21:20 +08:00
|
|
|
dayjs.extend(relativeTime);
|
2023-04-28 16:57:25 +08:00
|
|
|
|
2022-11-16 23:36:34 +08:00
|
|
|
const CONCH_TAG = 'conch-v5';
|
|
|
|
|
2022-07-26 14:01:08 +08:00
|
|
|
const DEPRECIATED_VERSION = {
|
|
|
|
'>= 4.21.6 < 4.22.0': ['https://github.com/ant-design/ant-design/pull/36682'],
|
2022-08-17 12:00:23 +08:00
|
|
|
'>=4.22.2 <=4.22.5': [
|
2022-08-15 18:15:14 +08:00
|
|
|
'https://github.com/ant-design/ant-design/issues/36932',
|
|
|
|
'https://github.com/ant-design/ant-design/pull/36800',
|
2022-08-17 12:00:23 +08:00
|
|
|
'https://github.com/ant-design/ant-design/issues/37024',
|
2022-08-15 18:15:14 +08:00
|
|
|
],
|
2022-09-08 17:30:49 +08:00
|
|
|
'4.23.0': ['https://github.com/ant-design/ant-design/issues/37461'],
|
2022-10-11 11:37:54 +08:00
|
|
|
'4.23.5': [
|
|
|
|
'https://github.com/ant-design/ant-design/issues/37929',
|
|
|
|
'https://github.com/ant-design/ant-design/issues/37931',
|
|
|
|
],
|
2022-11-04 16:18:43 +08:00
|
|
|
'4.24.0': ['https://github.com/ant-design/ant-design/issues/38371'],
|
2022-12-08 17:49:04 +08:00
|
|
|
'5.0.4': ['https://github.com/ant-design/ant-design/issues/39284'],
|
2022-12-26 13:41:45 +08:00
|
|
|
'5.0.6': ['https://github.com/ant-design/ant-design/issues/39807'],
|
|
|
|
'5.1.0': ['https://github.com/react-component/drawer/pull/370'],
|
2023-01-04 22:40:35 +08:00
|
|
|
'5.1.2': ['https://github.com/ant-design/ant-design/issues/39949'],
|
2023-01-09 21:03:08 +08:00
|
|
|
'5.1.3': ['https://github.com/ant-design/ant-design/issues/40113'],
|
2023-01-12 17:52:19 +08:00
|
|
|
'5.1.4': ['https://github.com/ant-design/ant-design/issues/40186'],
|
2023-03-08 17:20:17 +08:00
|
|
|
'>= 5.2.3 <= 5.3.0': [
|
|
|
|
'https://github.com/ant-design/ant-design/pull/40719#issuecomment-1453418135',
|
|
|
|
],
|
2023-04-11 20:23:14 +08:00
|
|
|
'5.4.1': ['https://github.com/ant-design/ant-design/issues/41751'],
|
2023-04-27 10:06:29 +08:00
|
|
|
'>= 5.4.3 <= 5.4.5': [
|
|
|
|
'https://github.com/ant-design/cssinjs/pull/108',
|
|
|
|
'https://github.com/ant-design/ant-design/pull/41993',
|
|
|
|
],
|
2023-06-20 13:41:35 +08:00
|
|
|
'5.6.2': ['https://github.com/ant-design/ant-design/issues/43113'],
|
2023-06-26 19:09:17 +08:00
|
|
|
'5.6.3': ['https://github.com/ant-design/ant-design/issues/43190'],
|
2023-07-20 20:43:47 +08:00
|
|
|
'5.7.0': ['https://github.com/ant-design/ant-design/issues/43684'],
|
|
|
|
'5.7.1': [
|
|
|
|
'https://github.com/ant-design/ant-design/issues/43654',
|
|
|
|
'https://github.com/ant-design/ant-design/issues/43684',
|
|
|
|
],
|
2022-07-26 14:01:08 +08:00
|
|
|
};
|
|
|
|
|
2023-04-29 12:52:56 +08:00
|
|
|
function matchDeprecated(version) {
|
2022-11-16 23:36:34 +08:00
|
|
|
const match = Object.keys(DEPRECIATED_VERSION).find((depreciated) =>
|
2022-07-26 14:01:08 +08:00
|
|
|
semver.satisfies(version, depreciated),
|
|
|
|
);
|
|
|
|
|
2023-04-29 12:52:56 +08:00
|
|
|
const reason = DEPRECIATED_VERSION[match] || [];
|
2022-07-26 14:01:08 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
match,
|
|
|
|
reason: Array.isArray(reason) ? reason : [reason],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-01-20 15:36:03 +08:00
|
|
|
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
|
2022-01-19 15:27:05 +08:00
|
|
|
|
|
|
|
(async function process() {
|
|
|
|
console.log(chalk.cyan('🤖 Post Publish Scripting...\n'));
|
2022-07-08 10:48:29 +08:00
|
|
|
|
2022-12-13 11:37:01 +08:00
|
|
|
// if (packageJson.version.startsWith('5.0')) {
|
|
|
|
// console.log(chalk.green('🤖 Next version, skipped.'));
|
|
|
|
// return;
|
|
|
|
// }
|
2022-07-08 10:48:29 +08:00
|
|
|
|
2022-11-16 23:36:34 +08:00
|
|
|
const { time, 'dist-tags': distTags } = await fetch('http://registry.npmjs.org/antd').then(
|
|
|
|
(res) => res.json(),
|
2022-01-19 15:27:05 +08:00
|
|
|
);
|
|
|
|
|
2022-11-16 23:36:34 +08:00
|
|
|
console.log('🐚 Latest Conch Version:', chalk.green(distTags[CONCH_TAG] || 'null'), '\n');
|
2022-01-19 15:27:05 +08:00
|
|
|
|
|
|
|
// Sort and get the latest versions
|
|
|
|
const versionList = Object.keys(time)
|
2022-11-16 23:36:34 +08:00
|
|
|
.filter((version) => semver.valid(version) && !semver.prerelease(version))
|
2022-01-19 15:27:05 +08:00
|
|
|
.sort((v1, v2) => {
|
2022-02-14 14:40:40 +08:00
|
|
|
const time1 = dayjs(time[v1]).valueOf();
|
|
|
|
const time2 = dayjs(time[v2]).valueOf();
|
2022-01-19 15:27:05 +08:00
|
|
|
|
|
|
|
return time2 - time1;
|
|
|
|
});
|
|
|
|
|
|
|
|
// Slice for choosing the latest versions
|
2022-07-26 14:01:08 +08:00
|
|
|
const latestVersions = versionList
|
|
|
|
// Cut off
|
|
|
|
.slice(0, 30)
|
|
|
|
// Formatter
|
2022-11-16 23:36:34 +08:00
|
|
|
.map((version) => ({
|
2022-07-26 14:01:08 +08:00
|
|
|
publishTime: time[version],
|
2022-07-29 15:56:11 +08:00
|
|
|
timeDiff: dayjs().diff(dayjs(time[version])),
|
2022-07-26 14:01:08 +08:00
|
|
|
value: version,
|
|
|
|
depreciated: matchDeprecated(version).match,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const filteredLatestVersions = latestVersions
|
|
|
|
// Filter deprecated versions
|
|
|
|
.filter(({ depreciated }) => !depreciated);
|
2022-01-19 15:27:05 +08:00
|
|
|
|
2022-07-26 14:01:08 +08:00
|
|
|
const startDefaultVersionIndex = filteredLatestVersions.findIndex(
|
2022-01-20 15:36:03 +08:00
|
|
|
({ timeDiff }) => timeDiff >= SAFE_DAYS_START,
|
|
|
|
);
|
2022-07-26 14:01:08 +08:00
|
|
|
const defaultVersionList = filteredLatestVersions
|
|
|
|
.slice(0, startDefaultVersionIndex + 1)
|
|
|
|
.reverse();
|
2022-01-20 15:36:03 +08:00
|
|
|
|
|
|
|
// Find safe version
|
2023-04-29 12:52:56 +08:00
|
|
|
let defaultVersionObj;
|
2022-01-20 15:36:03 +08:00
|
|
|
for (let i = 0; i < defaultVersionList.length - 1; i += 1) {
|
|
|
|
defaultVersionObj = defaultVersionList[i];
|
|
|
|
const nextVersionObj = defaultVersionList[i + 1];
|
|
|
|
|
|
|
|
if (defaultVersionObj.timeDiff - nextVersionObj.timeDiff > SAFE_DAYS_DIFF) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultVersionObj = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not find to use the latest version instead
|
|
|
|
defaultVersionObj = defaultVersionObj || defaultVersionList[defaultVersionList.length - 1];
|
2022-08-15 18:15:14 +08:00
|
|
|
let defaultVersion = defaultVersionObj ? defaultVersionObj.value : null;
|
|
|
|
|
|
|
|
// If default version is less than current, use current
|
2022-11-16 23:36:34 +08:00
|
|
|
if (semver.compare(defaultVersion, distTags[CONCH_TAG]) < 0) {
|
|
|
|
defaultVersion = distTags[CONCH_TAG];
|
2022-08-15 18:15:14 +08:00
|
|
|
}
|
2022-01-19 15:27:05 +08:00
|
|
|
|
2022-09-26 20:56:23 +08:00
|
|
|
const { default: inquirer } = await import('inquirer');
|
2022-01-19 15:27:05 +08:00
|
|
|
// Selection
|
2022-07-26 14:01:08 +08:00
|
|
|
let { conchVersion } = await inquirer.prompt([
|
2022-01-19 15:27:05 +08:00
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
name: 'conchVersion',
|
|
|
|
default: defaultVersion,
|
|
|
|
message: 'Please select Conch Version:',
|
2022-11-16 23:36:34 +08:00
|
|
|
choices: latestVersions.map((info) => {
|
2022-07-26 14:01:08 +08:00
|
|
|
const { value, publishTime, depreciated } = info;
|
2022-02-14 14:40:40 +08:00
|
|
|
const desc = dayjs(publishTime).fromNow();
|
2022-01-19 15:27:05 +08:00
|
|
|
|
2023-04-29 12:52:56 +08:00
|
|
|
//
|
|
|
|
|
2022-01-19 15:27:05 +08:00
|
|
|
return {
|
|
|
|
...info,
|
2022-08-15 18:15:14 +08:00
|
|
|
name: [
|
|
|
|
// Warning
|
|
|
|
depreciated ? '🚨' : '✅',
|
|
|
|
// Version
|
|
|
|
value,
|
|
|
|
// Date Diff
|
|
|
|
`(${desc})`,
|
|
|
|
// Default Mark
|
|
|
|
value === defaultVersion ? '(default)' : '',
|
|
|
|
// Current Mark
|
2022-11-16 23:36:34 +08:00
|
|
|
value === distTags[CONCH_TAG] ? chalk.gray('- current') : '',
|
2022-08-15 18:15:14 +08:00
|
|
|
]
|
2022-11-16 23:36:34 +08:00
|
|
|
.filter((str) => String(str).trim())
|
2022-08-15 18:15:14 +08:00
|
|
|
.join(' '),
|
2022-01-19 15:27:05 +08:00
|
|
|
};
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2022-07-26 14:01:08 +08:00
|
|
|
// Make sure it's not deprecated version
|
|
|
|
const deprecatedObj = matchDeprecated(conchVersion);
|
|
|
|
if (deprecatedObj.match) {
|
|
|
|
console.log('\n');
|
|
|
|
console.log(chalk.red('Deprecated For:'));
|
2022-11-16 23:36:34 +08:00
|
|
|
deprecatedObj.reason.forEach((reason) => {
|
2022-07-26 14:01:08 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-19 15:27:05 +08:00
|
|
|
// Check if need to update
|
2022-11-16 23:36:34 +08:00
|
|
|
if (!conchVersion || distTags[CONCH_TAG] === conchVersion) {
|
2022-01-19 15:27:05 +08:00
|
|
|
console.log(`🎃 Conch Version not change. Safe to ${chalk.green('ignore')}.`);
|
|
|
|
} else {
|
|
|
|
console.log('💾 Tagging Conch Version:', chalk.green(conchVersion));
|
2023-04-29 12:52:56 +08:00
|
|
|
spawnSync('npm', ['dist-tag', 'add', `antd@${conchVersion}`, CONCH_TAG], {
|
|
|
|
stdio: 'inherit',
|
|
|
|
stdin: 'inherit',
|
|
|
|
});
|
2022-01-19 15:27:05 +08:00
|
|
|
}
|
|
|
|
})();
|