diff --git a/src/commands/commit.ts b/src/commands/commit.ts index 28b9126..7a9f7b9 100644 --- a/src/commands/commit.ts +++ b/src/commands/commit.ts @@ -36,22 +36,67 @@ async function findCommitsScript(): Promise { return null } +/** + * Run dev-publish after successful commit+push + */ +async function runDevPublish(cwd: string): Promise { + return new Promise((resolve, reject) => { + console.log(colors.blue('\n[bitch] Running dev-publish...')) + + // Find dev-publish wrapper script + const devPublishScript = join(cwd, '../../scripts/publishing/dev-publish.sh') + + const child = spawn('bash', [devPublishScript, cwd], { + stdio: 'inherit', + env: process.env, + }) + + child.on('close', (code) => { + if (code === 0) { + console.log(colors.green('[bitch] Dev version published successfully')) + resolve() + } else { + console.log(colors.yellow(`[bitch] Dev-publish exited with code ${code}`)) + resolve() // Don't fail the whole command + } + }) + + child.on('error', (err) => { + console.log(colors.yellow(`[bitch] Dev-publish error: ${err.message}`)) + resolve() // Don't fail the whole command + }) + }) +} + /** * Run the commits script with the 'commit' subcommand */ -function runCommit(scriptPath: string, args: string[]): void { - const child = spawn('bash', [scriptPath, 'commit', ...args], { - stdio: 'inherit', - env: process.env, - }) +async function runCommit(scriptPath: string, args: string[], shouldPush: boolean): Promise { + const cwd = process.cwd() - child.on('close', (code) => { - process.exit(code || 0) - }) + return new Promise((resolve, reject) => { + const child = spawn('bash', [scriptPath, 'commit', ...args], { + stdio: 'inherit', + env: process.env, + }) - child.on('error', (err) => { - logError(`Failed to run commit: ${err.message}`) - process.exit(1) + child.on('close', async (code) => { + if (code === 0 && shouldPush) { + // After successful commit+push, run dev-publish + try { + await runDevPublish(cwd) + } catch (err) { + // Dev-publish failure shouldn't fail the commit + console.log(colors.yellow('[bitch] Dev-publish failed, but commit succeeded')) + } + } + process.exit(code || 0) + }) + + child.on('error', (err) => { + logError(`Failed to run commit: ${err.message}`) + process.exit(1) + }) }) } @@ -99,7 +144,8 @@ export function createCommitCommand(): Command { process.exit(1) } - runCommit(scriptPath, args) + const shouldPush = options.push !== false + await runCommit(scriptPath, args, shouldPush) }) return cmd