Skip to content

Commit

Permalink
release: 📦 v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MuyianKing committed Dec 12, 2024
1 parent d2db84e commit 554b315
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 100 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [0.2.1](https://github.com/MuyianKing/cli/compare/v0.2.0...v0.2.1) (2024-12-12)


### Bug Fixes

* :bug: 更新web-rsbuild模板 ([93a521a](https://github.com/MuyianKing/cli/commit/93a521ae26c1d15f2a24490795e1bc3fe9b4c970))


### Features

* :sparkles: 去除模板 ([b025716](https://github.com/MuyianKing/cli/commit/b025716172d61599d66758b47282a55ab1054956))
* :sparkles: 项目下载变更为从github仓库拉取 ([d2db84e](https://github.com/MuyianKing/cli/commit/d2db84e498065da27c8a29c2c197b93a04322bb4))



# [0.2.0](https://github.com/MuyianKing/cli/compare/v0.1.2...v0.2.0) (2024-11-14)


Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
- 项目下载变更为从github仓库拉取
- 优化打包
46 changes: 23 additions & 23 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
{
"name": "@muyianking/cli",
"type": "module",
"version": "0.2.0",
"description": "慕易安的脚手架",
"author": "muyianking",
"license": "ISC",
"keywords": [
"cli",
"vue",
"rsbuild"
],
"bin": {
"mu": "./bin/index.js"
},
"dependencies": {
"copy-dir": "^1.3.0",
"fs-extra": "^11.2.0",
"inquirer": "8.2.5",
"mustache": "^4.2.0",
"ora": "^8.1.1",
"yargs": "^17.7.2"
}
}
"name": "@muyianking/cli",
"type": "module",
"version": "0.2.1",
"description": "慕易安的脚手架",
"author": "muyianking",
"license": "ISC",
"keywords": [
"cli",
"vue",
"rsbuild"
],
"bin": {
"mu": "./bin/index.js"
},
"dependencies": {
"copy-dir": "^1.3.0",
"fs-extra": "^11.2.0",
"inquirer": "8.2.5",
"mustache": "^4.2.0",
"ora": "^8.1.1",
"yargs": "^17.7.2"
}
}
83 changes: 42 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
{
"name": "@muyianking/cli",
"type": "module",
"version": "0.2.0",
"private": false,
"scripts": {
"update-dep": "npm-check-updates && ncu -u && pnpm i",
"commit": "git add . && git cz",
"lint": "git add . && lint-staged",
"husky-lint": "git add . && lint-staged",
"prepare": "husky",
"log": "conventional-changelog -p angular -i CHANGELOG.md -s",
"publish": "node ./script/publish.js"
},
"dependencies": {
"download-git-repo": "^3.0.2"
},
"devDependencies": {
"@antfu/eslint-config": "^3.8.0",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint/eslintrc": "^3.1.0",
"cz-git": "^1.10.1",
"eslint": "^9.13.0",
"eslint-plugin-format": "^0.1.2",
"husky": "^9.1.6",
"lint-staged": "^15.2.10"
},
"resolutions": {
"bin-wrapper": "npm:bin-wrapper-china"
},
"config": {
"commitizen": {
"path": "node_modules/cz-git"
}
},
"lint-staged": {
"*.{js,ts,vue}": [
"eslint --fix"
]
}
}
"name": "@muyianking/cli",
"type": "module",
"version": "0.2.1",
"private": false,
"scripts": {
"update-dep": "npm-check-updates && ncu -u && pnpm i",
"commit": "git add . && git cz",
"lint": "git add . && lint-staged",
"husky-lint": "git add . && lint-staged",
"prepare": "husky",
"log": "conventional-changelog -p angular -i CHANGELOG.md -s",
"publish": "node ./script/publish.js"
},
"dependencies": {
"download-git-repo": "^3.0.2",
"fs-extra": "^11.2.0"
},
"devDependencies": {
"@antfu/eslint-config": "^3.8.0",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@eslint/eslintrc": "^3.1.0",
"cz-git": "^1.10.1",
"eslint": "^9.13.0",
"eslint-plugin-format": "^0.1.2",
"husky": "^9.1.6",
"lint-staged": "^15.2.10"
},
"resolutions": {
"bin-wrapper": "npm:bin-wrapper-china"
},
"config": {
"commitizen": {
"path": "node_modules/cz-git"
}
},
"lint-staged": {
"*.{js,ts,vue}": [
"eslint --fix"
]
}
}
28 changes: 28 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 54 additions & 35 deletions script/publish.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,74 @@
import child_process from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import process from 'node:process'
import fsExtra from 'fs-extra'
import { copy } from './utils/file.js'
import getObjectFromJson from './utils/getObjectFromJson.js'
import { exec, getParams } from './utils/tools.js'

const __dirname = fileURLToPath(import.meta.url)
const root = process.cwd()

// 读取版本
function getVersion() {
const package_path = path.resolve(__dirname, `../../cli/package.json`)
// 先从控制台读取
const { v } = getParams()
if (v) {
return {
version: v,
from: 'cmd',
}
}

// 没有再从package.json读取
const package_path = `${root}/package.json`
const _config = getObjectFromJson(package_path)
return _config.version
return {
version: _config.version,
from: 'package',
}
}

function publish() {
// 将README.md拷贝到包中
fs.copyFile('./README.md', '../cli/cli/README.md', () => {

})

// 修改package.json版本号
const _path = `../../package.json`
const package_path = path.resolve(__dirname, _path)
/**
* 覆写版本号
* @param {string} package_path 重写的package.json路径
* @param {string} version 版本号
*/
function reWriteVersion(package_path, version) {
const _config = getObjectFromJson(package_path)
_config.version = getVersion()

_config.version = version
const fileStr = JSON.stringify(_config, '', '\t')
fsExtra.outputFile(
package_path,
fileStr,
'utf-8',
)
}

// 发布入口
async function main() {
// 将README.md拷贝到包中
await copy('./README.md', `${root}/core/README.md`)

// 修改package.json版本号
const { version, from } = getVersion()

// 从命令行读取的版本需要回写package.json
if (from !== 'package') {
reWriteVersion(`${root}/package.json`, version)
}

// 回写core的package.json
reWriteVersion(`${root}/core/package.json`, version)

// 生成changelog.md
child_process.exec('pnpm log', (error) => {
if (!error) {
// 成功
child_process.exec('git add .', () => {
const version = `v${_config.version}`

child_process.exec(`git commit -m"release: :package: ${version}"`, () => {
child_process.exec(`git push && git tag ${version} && git push origin ${version}`, () => {
console.log('\x1B[32m%s\x1B[0m', 'publish success')
})
})
})
} else {
console.log('生成changelog.md失败', error)
}
})
await exec('pnpm log')

const _version = `v${version}`

// git commit
await exec('git add .')
await exec(`git commit -m"release: :package: ${_version}"`)

// git提交并生成版本tag
await exec(`git push && git tag ${_version} && git push origin ${_version}`)
}

publish()
main()
13 changes: 13 additions & 0 deletions script/utils/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import fs from 'node:fs'

export function copy(src, dest) {
return new Promise((resolve, reject) => {
fs.copyFile(src, dest, (e) => {
if (e) {
reject(e)
} else {
resolve('success')
}
})
})
}
29 changes: 29 additions & 0 deletions script/utils/tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import child_process from 'node:child_process'
import process from 'node:process'

// 获取参数
export function getParams() {
const params = {}
process.argv.forEach((item) => {
item = item.split('=')

if (item.length === 2) {
params[item[0]] = item[1]
}
})

return params
}

/**
* 执行指定命令
* @param {string} cmd 命令
* @returns
*/
export function exec(cmd) {
return new Promise((resolve, reject) => {
child_process.exec(cmd, (error) => {
error ? reject(error) : resolve('success')
})
})
}

0 comments on commit 554b315

Please sign in to comment.