2022-03-15 19:23:38 +08:00
|
|
|
import { writeFile } from 'fs/promises'
|
|
|
|
import consola from 'consola'
|
|
|
|
import chalk from 'chalk'
|
|
|
|
import { epPackage, getPackageManifest } from '@element-plus/build'
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
const tagVersion = process.env.TAG_VERSION
|
|
|
|
const gitHead = process.env.GIT_HEAD
|
|
|
|
if (!tagVersion || !gitHead) {
|
|
|
|
consola.error(
|
|
|
|
new Error(
|
|
|
|
'No tag version or git head were found, make sure that you set the environment variable $TAG_VERSION \n'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2022-03-15 19:23:38 +08:00
|
|
|
consola.log(chalk.cyan('Start updating version'))
|
|
|
|
consola.log(chalk.cyan(`$TAG_VERSION: ${tagVersion}`))
|
|
|
|
consola.log(chalk.cyan(`$GIT_HEAD: ${gitHead}`))
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2022-03-15 19:23:38 +08:00
|
|
|
consola.debug(chalk.yellow(`Updating package.json for element-plus`))
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2021-09-26 01:29:07 +08:00
|
|
|
const json: Record<string, any> = getPackageManifest(epPackage)
|
2021-08-24 13:36:48 +08:00
|
|
|
|
|
|
|
json.version = tagVersion
|
|
|
|
json.gitHead = gitHead
|
|
|
|
|
|
|
|
if (!(process.argv.includes('-d') || process.argv.includes('--dry-run'))) {
|
|
|
|
try {
|
2022-03-15 19:23:38 +08:00
|
|
|
await writeFile(epPackage, JSON.stringify(json, null, 2), {
|
2021-08-24 13:36:48 +08:00
|
|
|
encoding: 'utf-8',
|
|
|
|
})
|
2022-03-08 14:03:32 +08:00
|
|
|
} catch {
|
2021-08-24 13:36:48 +08:00
|
|
|
process.exit(1)
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-15 19:23:38 +08:00
|
|
|
consola.log(json)
|
2021-08-24 13:36:48 +08:00
|
|
|
}
|
|
|
|
|
2022-03-15 19:23:38 +08:00
|
|
|
consola.debug(chalk.green(`$GIT_HEAD: ${gitHead}`))
|
|
|
|
consola.success(chalk.green(`Git head updated to ${gitHead}`))
|
|
|
|
}
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2022-03-15 19:23:38 +08:00
|
|
|
main()
|