Skip to content

Commit

Permalink
release: v@yanyu28/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
aibayanyu20 committed Jul 10, 2022
1 parent 22a6c67 commit 8084266
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pnpm-debug.log*
lerna-debug.log*
.cache
.temp
coverage

node_modules
.DS_Store
Expand All @@ -23,4 +24,4 @@ dist-ssr
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ degit mistjs/monorepo-starter myApp

```


## install

```shell

pnpm install

```




## release

You can release your package. You can use `pnpm release` and step into the command line.
Release your package. use `pnpm release` and step into the command line.


```shell
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "monorepo-starter-template",
"version": "1.0.0",
"version": "0.0.1",
"description": "this is monorepo starter template",
"scripts": {
"prepare": "husky install",
"release": "esno ./scripts/release.ts --tag",
"changelog": "conventional-changelog -i CHANGELOG.md -s -r 0 -p angular"
"changelog": "conventional-changelog -i packages/app/CHANGELOG.md -k packages/app/package.json -s -r 0 -p angular --commit-path packages/app"
},
"packageManager": "[email protected]",
"repository": {
Expand Down
7 changes: 6 additions & 1 deletion packages/app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## 1.1.2-next.1 (2022-07-10)
## 1.1.2 (2022-07-10)


### Bug Fixes

* change ([22a6c67](https://github.com/mistjs/monorepo-starter/commit/22a6c67584d2271f8049dd3ec8dec098ec5f5544))


### Features
Expand Down
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app",
"version": "1.1.2-next.1",
"name": "@yanyu28/app",
"version": "1.1.2",
"description": "",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.1.2-next.1'
export default '1.1.2'
2 changes: 1 addition & 1 deletion packages/app/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { describe, expect, it } from 'vitest'

describe('Index', () => {
it('should test', () => {
expect('test').toBe('test 1')
expect('test').toBe('test')
})
})
5 changes: 3 additions & 2 deletions packages/tools/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "tools",
"name": "@yanyu28/tools",
"version": "1.0.5-beta.2",
"description": "",
"main": "dist/index.cjs",
Expand All @@ -14,7 +14,8 @@
},
"scripts": {
"build": "unbuild",
"stub": "unbuild --stub"
"stub": "unbuild --stub",
"test": "vitest run"
},
"keywords": [],
"author": "",
Expand Down
158 changes: 146 additions & 12 deletions scripts/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import type { Project } from 'find-packages'
import findPkgs from 'find-packages'
import prompt from 'prompts'
import chalk from 'chalk'
import type { VersionBumpResults } from 'bumpp'
import { versionBump } from 'bumpp'
import minimist from 'minimist'

const preIncludes = ['prepatch', 'preminor', 'premajor', 'prerelease']

interface Pkg {
dir: string
name: string
packageJson: string
info?: VersionBumpResults
}

const resolvePkgs = (pkgs: Project[]): Pkg[] => {
Expand All @@ -40,16 +41,14 @@ const generateVersionFile = async(version: string, cwd: string) => {
}
}

const args = minimist(process.argv.slice(2))

const main = async() => {
const pkgs = resolvePkgs(await findPkgs(process.cwd()))
let selectPkgs: Pkg[]
if (pkgs.length <= 1) {
selectPkgs = pkgs
}
else {
// 选择要发布的包
// select publish pkg
const sePkgs = await prompt({
type: 'multiselect',
name: 'selectPkgs',
Expand Down Expand Up @@ -134,22 +133,157 @@ const main = async() => {
process.exit(1)
}
// use test
try {
console.log(chalk.magenta('test ...'))
await Promise.all(selectPkgs.map(pkg => execa('pnpm', ['run', 'test'], { cwd: pkg.dir })))
console.log(chalk.green('test success'))
}
catch (e: any) {
console.log(chalk.red('test failed !'))
console.log(e?.stdout)
process.exit(1)
}

// build dist
for (const selectPkg of selectPkgs)
await execa('pnpm', ['run', 'build'], { cwd: selectPkg.dir })
try {
console.log(chalk.magenta('build ...'))
await Promise.all(selectPkgs.map(selectPkg => execa('pnpm', ['run', 'build'], { cwd: selectPkg.dir })))
console.log(chalk.green('build success'))
}
catch (e: any) {
console.log(chalk.red('build failed !'))
console.log(e?.stdout)
process.exit(1)
}

let globalInfo: VersionBumpResults
// change version
for (const selectPkg of selectPkgs) {
const info = await versionBump({
try {
console.log(chalk.magenta('change version ...'))
for (const selectPkg of selectPkgs) {
const info = await versionBump({
release: versionType,
preid: releaseType,
cwd: selectPkg.dir,
})
selectPkg.info = info
// auto generate version file
await generateVersionFile(info.newVersion, selectPkg.dir)
}
// change global version
globalInfo = await versionBump({
release: versionType,
preid: releaseType,
cwd: selectPkg.dir,
cwd: process.cwd(),
})
// 自动在当前的src目录生成一个version.ts的文件
await generateVersionFile(info.newVersion, selectPkg.dir)
console.log(chalk.green('change version success'))
}
catch (e) {
console.log(chalk.red('change version failed !'))
process.exit(1)
}
let commit
// add tag check pkg is single
if (selectPkgs.length === 1) {
const pkg = pkgs[0]
if (pkg.info) {
const tag = `${pkg.name}@${pkg.info.newVersion}`
// add tag
try {
console.log(chalk.magenta('add tag ...'))
await execa('git', ['tag', '-a', tag, '-m', `release: ${tag}`])
await execa('git', ['push', 'origin', tag])
console.log(chalk.green('add tag success'))
commit = `release: v${tag}`
}
catch (e: any) {
console.log(chalk.red('add tag failed !'))
console.log(e?.stdout)
process.exit(1)
}
}
}
else {
// input your tag version
let tagVersion: string
if (pkgs.length !== selectPkgs.length) {
const tagInfoVersion = await prompt({
type: 'text',
name: 'tagVersion',
message: 'input your tag version default is global version',
initial: globalInfo.newVersion,
})
tagVersion = tagInfoVersion.tagVersion
}
else {
tagVersion = globalInfo.newVersion
}
try {
console.log(chalk.magenta('add tag ...'))
await execa('git', ['tag', '-a', tagVersion, '-m', `release: v${tagVersion}`])
await execa('git', ['push', 'origin', tagVersion])
console.log(chalk.green('add tag success'))
commit = `release: v${tagVersion}`
}
catch (e: any) {
console.log(chalk.red('add tag failed !'))
console.log(e?.stdout)
process.exit(1)
}
}

// generate changelog
try {
console.log(chalk.magenta('generate changelog ...'))
for (const selectPkg of selectPkgs) {
await execa('conventional-changelog', [
'-i', resolve(selectPkg.dir, 'CHANGELOG.md'),
'-s', '-r', '0',
'-p', 'angular',
'-k', resolve(selectPkg.dir, 'package.json'),
'--commit-path', selectPkg.dir],
{
cwd: process.cwd(),
})
}
console.log(chalk.green('generate changelog success'))
}
catch (e: any) {
// TODO
console.log(chalk.red('generate changelog failed !'))
console.log(e?.stdout)
process.exit(1)
}
// commit
try {
console.log(chalk.magenta('commit ...'))
await execa('git', ['add', '.'])
await execa('git', ['commit', '-m', commit || 'release: change version'])
console.log(chalk.green('commit success'))
}
catch (e: any) {
console.log(chalk.red('commit failed !'))
console.log(e?.stdout)
process.exit(1)
}

// publish
try {
console.log(chalk.magenta('publish ...'))
const args: string[] = []
if (releaseType) {
args.push('--tag')
args.push(releaseType)
}
args.push('--filter')
args.push('./packages/**')
await execa('pnpm', ['publish', '--no-git-checks', ...args], { cwd: process.cwd() })
console.log(chalk.green('publish success'))
}
catch (e) {
// TODO
console.log(chalk.red('publish failed !'))
}
// add tag
}

main().then(() => {
Expand Down

0 comments on commit 8084266

Please sign in to comment.