mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
chore: ChangeLog命令支持按照commit类型排序, 执行完成后删除本地缓存 (#8810)
This commit is contained in:
parent
20c9f4f815
commit
eb5c6f730c
@ -2,20 +2,25 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
import util from 'util';
|
||||
import {exec as nodeExec} from 'child_process';
|
||||
import {fileURLToPath} from 'url';
|
||||
|
||||
const exec = util.promisify(nodeExec);
|
||||
|
||||
const pkg = '@fex/amis';
|
||||
const folder = path.join(path.dirname(__filename), '../node_modules');
|
||||
|
||||
export async function main(from: string, to: string) {
|
||||
export async function main(from: string, to: string, useMarkdown: boolean = false) {
|
||||
const toBeClearedQueue = [];
|
||||
let {stdout: packFromStdout} = await exec(
|
||||
`npm pack ${pkg}@${from} --pack-destination="${folder}"`
|
||||
);
|
||||
const fromFilname = packFromStdout.trim();
|
||||
const fromFolder = `${folder}/amis_${from}`;
|
||||
const fromTgz = path.join(folder, fromFilname);
|
||||
|
||||
await exec(`mkdir -p ${fromFolder}`);
|
||||
await exec(`tar -xzvf ${path.join(folder, fromFilname)} -C ${fromFolder}`);
|
||||
await exec(`tar -xzvf ${fromTgz} -C ${fromFolder}`);
|
||||
|
||||
toBeClearedQueue.push(fromFolder, fromTgz);
|
||||
|
||||
const fromRevision = JSON.parse(
|
||||
fs.readFileSync(fromFolder + '/package/revision.json', 'utf-8').trim()
|
||||
@ -26,8 +31,12 @@ export async function main(from: string, to: string) {
|
||||
);
|
||||
const toFilname = packToStdout.trim();
|
||||
const toFolder = `${folder}/amis_${to}`;
|
||||
const toTgz = path.join(folder, toFilname);
|
||||
|
||||
await exec(`mkdir -p ${toFolder}`);
|
||||
await exec(`tar -xzvf ${path.join(folder, toFilname)} -C ${toFolder}`);
|
||||
await exec(`tar -xzvf ${toTgz} -C ${toFolder}`);
|
||||
|
||||
toBeClearedQueue.push(toFolder, toTgz);
|
||||
|
||||
const toRevision = JSON.parse(
|
||||
fs.readFileSync(toFolder + '/package/revision.json', 'utf-8').trim()
|
||||
@ -49,7 +58,43 @@ export async function main(from: string, to: string) {
|
||||
return msg;
|
||||
})
|
||||
.filter(item => item);
|
||||
console.log(commits.join('\n'));
|
||||
|
||||
const prefixes = ['feat', 'feats', 'feat(amis)', 'feat(amis-editor)', 'fix', 'fix(amis)', 'fix(amis-editor)', 'chore', 'chore(amis)', 'chore(amis-editor)', 'styles', 'style', 'style(amis)', 'style(amis-editor)', 'docs', 'doc', 'docs(amis)', 'docs(amis-editor)', 'perf', 'refactor', 'revert',];
|
||||
|
||||
/** 按照commit类型排序 */
|
||||
commits.sort((lhs, rhs) => {
|
||||
let lhsPrefixIndex = prefixes.findIndex(p => p === lhs.split(/\s*[::]+\s*/)[0]);
|
||||
let rhsPrefixIndex = prefixes.findIndex(p => p === rhs.split(/\s*[::]+\s*/)[0]);
|
||||
|
||||
/** 找不到对应的标签就排队尾 */
|
||||
if (lhsPrefixIndex === -1) {
|
||||
lhsPrefixIndex = prefixes.length + 1;
|
||||
}
|
||||
|
||||
if (rhsPrefixIndex === -1) {
|
||||
rhsPrefixIndex = prefixes.length + 1;
|
||||
}
|
||||
|
||||
return lhsPrefixIndex - rhsPrefixIndex;
|
||||
})
|
||||
|
||||
console.log(
|
||||
'\x1b[32m%s\x1b[0m',
|
||||
`✨ [@fex/amis] ${from} ===> ${to} change log:`
|
||||
);
|
||||
|
||||
if (useMarkdown) {
|
||||
console.log(commits.map(i => `* ${i}`).join('\n'));
|
||||
} else {
|
||||
console.log(commits.join('\n'));
|
||||
}
|
||||
|
||||
/** 清除缓存的文件和文件夹 */
|
||||
await exec(`npx rimraf ${toBeClearedQueue.join(' ')}`);
|
||||
console.log(
|
||||
'\x1b[32m%s\x1b[0m',
|
||||
'✨ [@fex/amis] Temporarily cached files have been successfully cleared!'
|
||||
);
|
||||
}
|
||||
|
||||
main.apply(null, process.argv.slice(2)).catch((err: any) => {
|
||||
|
Loading…
Reference in New Issue
Block a user