Skip to content

Commit

Permalink
fix: ctx runner
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Aug 14, 2024
1 parent 290b10a commit e966543
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions bump.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { defineConfig } from './src/index.mjs'

export default defineConfig({
leading: ['git pull --rebase', 'pnpm i', 'npm run build'],
trailing: [],
trailing: [
"gh pr create --title 'chore: Release v${NEW_VERSION}' --body 'v${NEW_VERSION}' --base main --head dev",
],
publish: true,
changelog: true,
changelog: false,
mode: 'monorepo',
allowedBranches: ['dev/*', 'master', 'main'],
packages: ['test/packages/**'],
Expand Down
2 changes: 1 addition & 1 deletion src/core/resolve-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const resolveConfig = memoReturnValueAsyncFunction(async () => {
const createGitTag = bumpOptions.tag ?? true
const doGitPush = bumpOptions.push ?? true
const commitMessage = bumpOptions.commitMessage || 'release: v${NEW_VERSION}'
const allowedBranches = bumpOptions.allowedBranches
const allowedBranches = bumpOptions.allowedBranches ?? ['main']
const tagPrefix = bumpOptions.tagPrefix || 'v'
const withTags = bumpOptions.withTags ?? false
const remoteTags = bumpOptions.remoteTags ?? false
Expand Down
6 changes: 4 additions & 2 deletions src/core/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const { valid, lte } = semver

type CmdContext = {
nextVersion: string
newVersion: string
}

export async function execCmd(cmds: string[], context: CmdContext) {
const ctxKeys = Object.keys(context)
for (const cmd of cmds) {
const handledCmd = ctxKeys.reduce((cmd, nextKey) => {
return cmd.replace(
`$\{${snakecase(nextKey).toUpperCase()}}`,
return cmd.replaceAll(
`\${${snakecase(nextKey).toUpperCase()}}`,
context[nextKey],
)
}, cmd)
Expand Down Expand Up @@ -184,6 +185,7 @@ export async function runBump(newVersion: string) {

const cmdContext: CmdContext = {
nextVersion: newVersion,
newVersion,
}

await execCmd(leadingHooks, cmdContext)
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"compilerOptions": {
"lib": [
"ES2021"
],
"jsx": "preserve",
"target": "esnext",
"module": "NodeNext",
Expand Down

0 comments on commit e966543

Please sign in to comment.