Browse Source

chore: conch script (#33766)

pull/33771/head
二货机器人 3 years ago
committed by GitHub
parent
commit
0d11475213
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 67
      scripts/post-script.js

2
package.json

@ -83,6 +83,7 @@
"pretty-quick": "pretty-quick",
"pub": "npm run version && antd-tools run pub",
"prepublishOnly": "antd-tools run guard",
"postpublish": "node ./scripts/post-script.js",
"site:theme": "npm run site:theme-dark && npm run site:theme-compact",
"site:theme-dark": "cross-env ESBUILD=1 ANT_THEME=dark bisheng build -c ./site/bisheng.config.js",
"site:theme-compact": "cross-env ESBUILD=1 ANT_THEME=compact bisheng build -c ./site/bisheng.config.js",
@ -270,6 +271,7 @@
"remove-files-webpack-plugin": "^1.4.5",
"rimraf": "^3.0.0",
"scrollama": "^3.0.0",
"semver": "^7.3.5",
"simple-git": "^2.23.0",
"string-replace-loader": "^3.0.3",
"stylelint": "^14.0.0",

67
scripts/post-script.js

@ -0,0 +1,67 @@
const fetch = require('isomorphic-fetch');
const semver = require('semver');
const moment = require('moment');
const inquirer = require('inquirer');
const chalk = require('chalk');
const { spawnSync } = require('child_process');
const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 15; // 15 days
(async function process() {
console.log(chalk.cyan('🤖 Post Publish Scripting...\n'));
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');
// Sort and get the latest versions
const versionList = Object.keys(time)
.filter(version => semver.valid(version) && !semver.prerelease(version))
.sort((v1, v2) => {
const time1 = moment(time[v1]).valueOf();
const time2 = moment(time[v2]).valueOf();
return time2 - time1;
});
// Slice for choosing the latest versions
const latestVersions = versionList.slice(0, 10).map(version => ({
publishTime: time[version],
timeDiff: moment().diff(moment(time[version])),
value: version,
}));
const defaultVersionObj = latestVersions.find(({ timeDiff }) => timeDiff >= SAFE_DAYS_DIFF);
const defaultVersion = defaultVersionObj ? defaultVersionObj.value : null;
// Selection
const { conchVersion } = await inquirer.prompt([
{
type: 'list',
name: 'conchVersion',
default: defaultVersion,
message: 'Please select Conch Version:',
choices: latestVersions.map(info => {
const { value, publishTime } = info;
const desc = moment(publishTime).fromNow();
return {
...info,
name: `${value} (${desc}) ${value === defaultVersion ? '(default)' : ''}`,
};
}),
},
]);
// Check if need to update
if (distTags.conch === 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'], {
stdio: 'inherit',
stdin: 'inherit',
});
}
})();
Loading…
Cancel
Save