chore: internal publish with revision.json (#5315)

This commit is contained in:
RUNZE LU 2022-09-06 17:51:36 +08:00 committed by GitHub
parent e76cdde50b
commit ee522af761
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 1 deletions

View File

@ -19,6 +19,7 @@
"coverage": "jest --coverage",
"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",
"publish-to-internal": "sh ./publish-to-internal.sh"
},
"dependencies": {

View File

@ -153,7 +153,8 @@
"lib",
"esm",
"sdk",
"schema.json"
"schema.json",
"revision.json"
],
"exports": {
".": {

View File

@ -13,6 +13,18 @@ mkdir npm
cp -rf packages npm
cp package.json npm
# 记录last commit便于区分内网版本包之间的差异
REVISION=revision.json
npm run revision -- $REVISION
if [ -f "$REVISION" ]; then
for dir in $(find ./npm/packages -mindepth 1 -maxdepth 1 -type d); do
[ -d "$dir" ] && cp $REVISION "$dir/$REVISION";
done;
else
echo "$REVISION not exists."
fi
cd npm
# package.json 里面把包名称换了

View File

@ -0,0 +1,47 @@
/**
* commit信息
*/
import path from 'path';
import {writeFileSync} from 'fs';
import {execSync} from 'child_process';
let outputFileName = process.argv[2];
if (!outputFileName) {
outputFileName = 'revision.json';
}
try {
const rootDir = execSync('git rev-parse --show-toplevel').toString().trim();
// 分支
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
// commit id
const SHA1 = execSync('git rev-parse --short HEAD').toString().trim();
// commit body
const commit = execSync(
`git log -n 1 --date=format:'%Y-%m-%d %H:%M:%S' --format="%s%n%an%n%cd"`
)
.toString()
.trim();
const [message, author, date] = commit.split('\n');
const content = JSON.stringify(
{branch, SHA1, message, author, date},
undefined,
2
);
writeFileSync(path.join(rootDir, outputFileName), content, {
encoding: 'utf8'
});
console.log(
'\x1b[32m%s\x1b[0m',
'✨ [amis] revision.json generated successfully!'
);
process.exit();
} catch (error) {
console.log('\x1b[31m%s\x1b[0m', '❌ [amis] revision.json failed to write!');
process.exit(1);
}