mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-06 17:18:40 +08:00
build: 📦 发布时自动处理最低版本号
This commit is contained in:
parent
4c22cf515e
commit
bdf51a3283
11
.github/CONTRIBUTING.md
vendored
11
.github/CONTRIBUTING.md
vendored
@ -35,6 +35,17 @@ git clone https://gitee.com/fant-mini/wot-design-uni.git
|
||||
- 确保代码可以通过仓库的 `ESLint` 校验。
|
||||
- 确保代码格式是规范的,使用 `prettier` 进行代码格式化。
|
||||
|
||||
### 关于新功能
|
||||
|
||||
新功能需要标注最低版本号,如何确定版本号呢?当然没那么复杂啦!只需要各位贡献者在`/docs/*.md`内需要显示最低版本号的地方写上`$LOWEST_VERSION$`占位符即可;当下一次发版时,脚手架将会自动确定版本号并替换全部`/docs/*.md`中的`$LOWEST_VERSION$`占位符
|
||||
|
||||
```
|
||||
| 参数 | 说明 | 类型 | 可选值 | 默认值 | 最低版本 |
|
||||
| ----- | --------------- | ------ | --------- | --------- | ---------------- |
|
||||
| text | 设置通知栏文案 | `string` | - | - | $LOWEST_VERSION$ |
|
||||
```
|
||||
|
||||
|
||||
## Commit
|
||||
|
||||
开发之后,在 commit 代码时,commit message 请遵循以下格式:
|
||||
|
||||
@ -12,14 +12,43 @@ const inquirer = require('inquirer')
|
||||
const { execSync } = require('child_process')
|
||||
const { writeFileSync, readFileSync } = require('fs')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
|
||||
const src = path.resolve(__dirname, '../src/uni_modules/wot-design-uni')
|
||||
|
||||
const oldVersion = require('../package.json').version
|
||||
const LOWEST_VERSION = '$LOWEST_VERSION$'
|
||||
|
||||
const handleLowestVersion = (dir, version) => {
|
||||
const files = fs.readdirSync(dir)
|
||||
|
||||
for (const item of files) {
|
||||
const itemPath = path.resolve(dir, item)
|
||||
const stat = fs.statSync(itemPath)
|
||||
|
||||
if (stat.isFile()) {
|
||||
if (item.endsWith('.md')) {
|
||||
let content = fs.readFileSync(itemPath, {
|
||||
encoding: 'utf-8'
|
||||
})
|
||||
|
||||
if (content.includes(LOWEST_VERSION)) {
|
||||
content = content.replace(LOWEST_VERSION, version)
|
||||
writeFileSync(itemPath, content)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handleLowestVersion(itemPath, version)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inquirer
|
||||
.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'version',
|
||||
message: '请选择发版类型(默认值:✨ minor)',
|
||||
message: '请选择发版类型(默认值:✨ minor)',
|
||||
choices: ['🐛 patch 小版本', '✨ minor 中版本', '🚀 major 大版本'],
|
||||
default: '✨ minor 中版本'
|
||||
},
|
||||
@ -56,16 +85,20 @@ inquirer
|
||||
// 更新版本
|
||||
const file = readFileSync(path.resolve(__dirname, '../package.json'))
|
||||
const packageJson = JSON.parse(file.toString())
|
||||
const version = packageJson.version
|
||||
console.log(`√ bumping version in package.json from ${oldVersion} to ${version}`)
|
||||
const newVersion = packageJson.version
|
||||
|
||||
// 处理文档中的最低版本标识
|
||||
handleLowestVersion(path.resolve(__dirname, '../docs'), newVersion)
|
||||
|
||||
console.log(`√ bumping version in package.json from ${oldVersion} to ${newVersion}`)
|
||||
const package = require('../src/uni_modules/wot-design-uni/package.json')
|
||||
package.version = version
|
||||
package.version = newVersion
|
||||
writeFileSync(path.resolve(src, 'package.json'), JSON.stringify(package))
|
||||
// 生成制品
|
||||
execSync('pnpm lint')
|
||||
execSync('git add -A ')
|
||||
execSync(`git commit -am "build: compile ${version}"`)
|
||||
execSync(`git tag -a v${version} -am "chore(release): ${version}"`)
|
||||
execSync(`git commit -am "build: compile ${newVersion}"`)
|
||||
execSync(`git tag -a v${newVersion} -am "chore(release): ${newVersion}"`)
|
||||
console.log('√ committing changes')
|
||||
const branch = execSync('git branch --show-current').toString().replace(/\*/g, '').replace(/ /g, '')
|
||||
console.log('🎉 版本发布成功')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user