Skip to content

Commit

Permalink
fix(release): 从 git 中获取仓库 url
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Feb 19, 2024
1 parent a5393d0 commit b36a68b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"plop": "^4.0.1",
"prettier": "^3.2.5",
"prism-theme-vars": "^0.2.4",
"simple-git": "^3.22.0",
"taze": "^0.13.3",
"terser": "^5.27.0",
"typescript": "^5.3.3",
Expand Down
25 changes: 25 additions & 0 deletions pnpm-lock.yaml

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

24 changes: 19 additions & 5 deletions scripts/release.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ const { createConsola } = require('consola')
const { execSync } = require('child_process')
const { repository } = require('../package.json')
const { gray } = require('kolorist')

const { simpleGit } = require('simple-git')
const logger = createConsola().withTag('release')

/**
* 自动发版
* @param {import('plop').NodePlopAPI} plop
*/
async function release(plop) {
// TODO 从 git 中获取仓库 url
const release = await logger.prompt(`是否发布到 ${gray(repository.url)}`, {
type: 'confirm',
const git = simpleGit()

const remotes = await git.getRemotes(true)

const urls = remotes.map((r) => {
return r.refs.push
.replace('git@github.com:', 'https://github.com/')
.replace('.git', '')
})
if (release) {
let allowRelease = false
if (!urls.includes(repository.url)) {
allowRelease = await logger.prompt(`是否发布到 ${gray(repository.url)}`, {
type: 'confirm',
})
} else {
allowRelease = true
}

if (allowRelease) {
plop.setGenerator('controller', {
description: '自动发版',
prompts: [
Expand Down

0 comments on commit b36a68b

Please sign in to comment.