feat: 添加 getChangeLog script 帮助快速生成内部版本差异 (#8162)

This commit is contained in:
liaoxuezhi 2023-09-19 11:45:02 +08:00 committed by GitHub
parent 665756e850
commit 3d5fabc599
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View File

@ -24,6 +24,7 @@
"version": "lerna version",
"release": "npm run build --workspaces && lerna publish from-package --registry=https://registry.npmjs.org --ignore-scripts",
"revision": "ts-node ./scripts/generate-revision.ts",
"getChangeLog": "ts-node ./scripts/getChangeLog",
"publish-to-internal": "sh ./publish-to-internal.sh",
"stylelint": "npx stylelint 'packages/**/*.scss'",
"typecheck": "tsc --noEmit"

58
scripts/getChangeLog.ts Normal file
View File

@ -0,0 +1,58 @@
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) {
let {stdout: packFromStdout} = await exec(
`npm pack ${pkg}@${from} --pack-destination="${folder}"`
);
const fromFilname = packFromStdout.trim();
const fromFolder = `${folder}/amis_${from}`;
await exec(`mkdir -p ${fromFolder}`);
await exec(`tar -xzvf ${path.join(folder, fromFilname)} -C ${fromFolder}`);
const fromRevision = JSON.parse(
fs.readFileSync(fromFolder + '/package/revision.json', 'utf-8').trim()
);
const {stdout: packToStdout} = await exec(
`npm pack ${pkg}@${to} --pack-destination="${folder}"`
);
const toFilname = packToStdout.trim();
const toFolder = `${folder}/amis_${to}`;
await exec(`mkdir -p ${toFolder}`);
await exec(`tar -xzvf ${path.join(folder, toFilname)} -C ${toFolder}`);
const toRevision = JSON.parse(
fs.readFileSync(toFolder + '/package/revision.json', 'utf-8').trim()
);
const {stdout: logs} = await exec(
`git log ${fromRevision.SHA1}...${toRevision.SHA1}^ --oneline`
);
const lines = logs.split('\n');
const commits = lines
.map(line => {
const [SHA1, ...message] = line.split(' ');
const msg = message.join(' ');
if (msg.startsWith('Merge') || msg.startsWith('bump:')) {
return '';
}
return msg;
})
.filter(item => item);
console.log(commits.join('\n'));
}
main.apply(null, process.argv.slice(2)).catch((err: any) => {
console.error(err);
process.exit(1);
});