element-plus/scripts/update-version.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

import fs from 'fs'
import { epPackage } from '../build/utils/paths'
import { cyan, red, yellow, green } from '../build/utils/log'
import { getPackageManifest } from '../build/utils/pkg'
const tagVersion = process.env.TAG_VERSION
const gitHead = process.env.GIT_HEAD
if (!tagVersion || !gitHead) {
2021-09-26 01:29:07 +08:00
red(
'No tag version or git head were found, make sure that you set the environment variable $TAG_VERSION \n'
)
process.exit(1)
}
2021-09-26 01:29:07 +08:00
cyan('Start updating version')
2021-09-26 01:29:07 +08:00
cyan(
['NOTICE:', `$TAG_VERSION: ${tagVersion}`, `$GIT_HEAD: ${gitHead}`].join('\n')
)
;(async () => {
2021-09-26 01:29:07 +08:00
yellow(`Updating package.json for element-plus`)
2021-09-26 01:29:07 +08:00
const json: Record<string, any> = getPackageManifest(epPackage)
json.version = tagVersion
json.gitHead = gitHead
if (!(process.argv.includes('-d') || process.argv.includes('--dry-run'))) {
try {
2021-09-26 01:29:07 +08:00
await fs.promises.writeFile(epPackage, JSON.stringify(json, null, 2), {
encoding: 'utf-8',
})
} catch (e) {
process.exit(1)
}
} else {
console.log(json)
}
2021-09-26 01:29:07 +08:00
green(`Version updated to ${tagVersion}`)
2021-09-26 01:29:07 +08:00
green(`Git head updated to ${gitHead}`)
})()