Skip to content

Commit d0e6f19

Browse files
feat: adds publish script
1 parent 7107954 commit d0e6f19

File tree

9 files changed

+1145
-1
lines changed

9 files changed

+1145
-1
lines changed

.dmux-hooks/AGENTS.md

Lines changed: 410 additions & 0 deletions
Large diffs are not rendered by default.

.dmux-hooks/CLAUDE.md

Lines changed: 410 additions & 0 deletions
Large diffs are not rendered by default.

.dmux-hooks/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# dmux Hooks
2+
3+
This directory contains hooks that run automatically at key lifecycle events in dmux.
4+
5+
## Quick Start
6+
7+
1. **Read the documentation**:
8+
- `AGENTS.md` - Complete reference (for any AI agent)
9+
- `CLAUDE.md` - Same content (Claude Code looks for this filename)
10+
11+
2. **Check examples**:
12+
- `examples/` directory contains starter templates
13+
14+
3. **Create a hook**:
15+
```bash
16+
touch worktree_created
17+
chmod +x worktree_created
18+
nano worktree_created
19+
```
20+
21+
4. **Test it**:
22+
```bash
23+
export DMUX_ROOT="$(pwd)"
24+
export DMUX_WORKTREE_PATH="$(pwd)"
25+
./worktree_created
26+
```
27+
28+
## Available Hooks
29+
30+
- `before_pane_create` - Before pane creation
31+
- `pane_created` - After pane created
32+
- `worktree_created` - After worktree setup
33+
- `before_pane_close` - Before closing
34+
- `pane_closed` - After closed
35+
- `before_worktree_remove` - Before worktree removal
36+
- `worktree_removed` - After worktree removed
37+
- `pre_merge` - Before merge
38+
- `post_merge` - After merge
39+
- `run_test` - When running tests
40+
- `run_dev` - When starting dev server
41+
42+
## Documentation
43+
44+
See `AGENTS.md` or `CLAUDE.md` for complete documentation including:
45+
- Environment variables
46+
- HTTP callback API
47+
- Common patterns
48+
- Best practices
49+
- Testing strategies
50+
51+
## Note
52+
53+
This directory is **version controlled**. Hooks you create here will be shared with your team.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
# Example: post_merge hook
3+
#
4+
# This hook runs after a successful merge into the target branch.
5+
# Use it to trigger deployments, close issues, notify teams, etc.
6+
7+
set -e
8+
9+
echo "[Hook] Post-merge processing for $DMUX_SLUG$DMUX_TARGET_BRANCH"
10+
11+
cd "$DMUX_ROOT"
12+
13+
# Push to remote if merging to main/master
14+
if [ "$DMUX_TARGET_BRANCH" = "main" ] || [ "$DMUX_TARGET_BRANCH" = "master" ]; then
15+
echo "[Hook] Pushing to origin/$DMUX_TARGET_BRANCH"
16+
git push origin "$DMUX_TARGET_BRANCH"
17+
18+
# Optional: Trigger deployment
19+
# if [ -n "$VERCEL_TOKEN" ]; then
20+
# echo "[Hook] Triggering Vercel deployment..."
21+
# curl -X POST "https://api.vercel.com/v1/deployments" \
22+
# -H "Authorization: Bearer $VERCEL_TOKEN" \
23+
# -H "Content-Type: application/json" \
24+
# -d '{
25+
# "name": "my-project",
26+
# "gitSource": {
27+
# "type": "github",
28+
# "ref": "main"
29+
# }
30+
# }'
31+
# fi
32+
fi
33+
34+
# Close related GitHub issue (if prompt contains #123 format)
35+
ISSUE_NUM=$(echo "$DMUX_PROMPT" | grep -oP '#\K\d+' | head -1)
36+
if [ -n "$ISSUE_NUM" ]; then
37+
echo "[Hook] Closing GitHub issue #$ISSUE_NUM"
38+
if command -v gh &> /dev/null; then
39+
gh issue close "$ISSUE_NUM" \
40+
-c "Resolved in branch $DMUX_SLUG, merged to $DMUX_TARGET_BRANCH" \
41+
2>/dev/null || echo "[Hook] Warning: Failed to close issue (maybe already closed?)"
42+
else
43+
echo "[Hook] GitHub CLI (gh) not found, skipping issue close"
44+
fi
45+
fi
46+
47+
# Send notification to Slack
48+
# if [ -n "$SLACK_WEBHOOK" ]; then
49+
# echo "[Hook] Sending Slack notification"
50+
# curl -s -X POST "$SLACK_WEBHOOK" \
51+
# -H "Content-Type: application/json" \
52+
# -d "{
53+
# \"text\": \"Merged: $DMUX_SLUG → $DMUX_TARGET_BRANCH\",
54+
# \"blocks\": [
55+
# {
56+
# \"type\": \"section\",
57+
# \"text\": {
58+
# \"type\": \"mrkdwn\",
59+
# \"text\": \"*Branch Merged* :rocket:\n\n*From:* \`$DMUX_SLUG\`\n*To:* \`$DMUX_TARGET_BRANCH\`\n*Task:* $DMUX_PROMPT\"
60+
# }
61+
# }
62+
# ]
63+
# }" > /dev/null
64+
# fi
65+
66+
echo "[Hook] Post-merge processing complete"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# Example: run_dev hook
3+
#
4+
# This hook starts a dev server and optionally creates a tunnel for sharing.
5+
# It reports the server URL back to dmux via the HTTP API.
6+
7+
set -e
8+
9+
echo "[Hook] Starting dev server for $DMUX_SLUG"
10+
11+
cd "$DMUX_WORKTREE_PATH"
12+
API_URL="http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/dev"
13+
14+
# Update status: starting
15+
curl -s -X PUT "$API_URL" \
16+
-H "Content-Type: application/json" \
17+
-d '{"status": "running"}' > /dev/null
18+
19+
# Start dev server in background
20+
# Adjust the command for your project (pnpm dev, npm run dev, vite, etc.)
21+
LOG_FILE="/tmp/dmux-dev-$DMUX_PANE_ID.log"
22+
pnpm dev > "$LOG_FILE" 2>&1 &
23+
DEV_PID=$!
24+
25+
# Wait for server to be ready
26+
echo "[Hook] Waiting for dev server to start..."
27+
sleep 5
28+
29+
# Detect port from log output
30+
# Adjust the grep pattern for your dev server's output format
31+
PORT=$(grep -oP '(?<=localhost:)\d+' "$LOG_FILE" | head -1)
32+
33+
if [ -z "$PORT" ]; then
34+
echo "[Hook] Warning: Could not detect port from logs, using default 3000"
35+
PORT=3000
36+
fi
37+
38+
LOCAL_URL="http://localhost:$PORT"
39+
echo "[Hook] Dev server running at $LOCAL_URL"
40+
41+
# Optional: Create a public tunnel (uncomment to enable)
42+
# Requires ngrok, cloudflared, or another tunneling tool
43+
44+
# Example with cloudflared:
45+
# TUNNEL_URL=$(cloudflared tunnel --url "$LOCAL_URL" 2>&1 | \
46+
# grep -oP 'https://[a-z0-9-]+\.trycloudflare\.com' | head -1)
47+
48+
# Example with ngrok:
49+
# TUNNEL_URL=$(ngrok http $PORT --log=stdout 2>&1 | \
50+
# grep -oP 'url=https://[^"]+' | head -1 | cut -d= -f2)
51+
52+
# For now, just use local URL (uncomment tunnel code above to enable)
53+
FINAL_URL="$LOCAL_URL"
54+
55+
# Report status back to dmux
56+
curl -s -X PUT "$API_URL" \
57+
-H "Content-Type: application/json" \
58+
-d "{\"status\": \"running\", \"url\": \"$FINAL_URL\"}" > /dev/null
59+
60+
echo "[Hook] Dev server ready at: $FINAL_URL"
61+
echo "[Hook] Dev server PID: $DEV_PID"
62+
echo "[Hook] Log file: $LOG_FILE"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Example: run_test hook
3+
#
4+
# This hook runs tests and reports the status back to dmux via the HTTP API.
5+
# Status updates appear in real-time in the dmux UI.
6+
7+
set -e
8+
9+
echo "[Hook] Running tests for $DMUX_SLUG"
10+
11+
cd "$DMUX_WORKTREE_PATH"
12+
API_URL="http://localhost:$DMUX_SERVER_PORT/api/panes/$DMUX_PANE_ID/test"
13+
14+
# Update status: running
15+
curl -s -X PUT "$API_URL" \
16+
-H "Content-Type: application/json" \
17+
-d '{"status": "running"}' > /dev/null
18+
19+
echo "[Hook] Running test suite..."
20+
21+
# Capture test output
22+
OUTPUT_FILE="/tmp/dmux-test-$DMUX_PANE_ID.txt"
23+
24+
# Run tests (adjust command for your project)
25+
# Examples:
26+
# - pnpm test
27+
# - npm test
28+
# - vitest run
29+
# - jest
30+
# - pytest
31+
# - cargo test
32+
if pnpm test > "$OUTPUT_FILE" 2>&1; then
33+
STATUS="passed"
34+
echo "[Hook] Tests passed ✓"
35+
else
36+
STATUS="failed"
37+
echo "[Hook] Tests failed ✗"
38+
fi
39+
40+
# Get output (truncate if too long)
41+
OUTPUT=$(head -c 5000 "$OUTPUT_FILE")
42+
43+
# Report results back to dmux
44+
curl -s -X PUT "$API_URL" \
45+
-H "Content-Type: application/json" \
46+
-d "$(jq -n \
47+
--arg status "$STATUS" \
48+
--arg output "$OUTPUT" \
49+
'{status: $status, output: $output}')" > /dev/null
50+
51+
# Cleanup
52+
rm -f "$OUTPUT_FILE"
53+
54+
echo "[Hook] Test results reported to dmux"
55+
56+
# Exit with test status
57+
if [ "$STATUS" = "passed" ]; then
58+
exit 0
59+
else
60+
exit 1
61+
fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Example: worktree_created hook
3+
#
4+
# This hook runs after a new worktree is created and the agent is launched.
5+
# Use it to set up the worktree environment (install deps, copy configs, etc.)
6+
7+
set -e # Exit on error
8+
9+
echo "[Hook] Setting up worktree: $DMUX_SLUG"
10+
11+
cd "$DMUX_WORKTREE_PATH"
12+
13+
# Install dependencies in background (don't block dmux)
14+
if [ -f "pnpm-lock.yaml" ]; then
15+
echo "[Hook] Installing dependencies with pnpm..."
16+
pnpm install --prefer-offline &
17+
elif [ -f "package-lock.json" ]; then
18+
echo "[Hook] Installing dependencies with npm..."
19+
npm install &
20+
elif [ -f "yarn.lock" ]; then
21+
echo "[Hook] Installing dependencies with yarn..."
22+
yarn install &
23+
fi
24+
25+
# Copy environment file if it exists
26+
if [ -f "$DMUX_ROOT/.env.local" ]; then
27+
echo "[Hook] Copying .env.local"
28+
cp "$DMUX_ROOT/.env.local" "$DMUX_WORKTREE_PATH/.env.local"
29+
fi
30+
31+
# Set custom git config for this worktree
32+
echo "[Hook] Configuring git"
33+
git config user.name "dmux-agent/$DMUX_SLUG"
34+
git config user.email "[email protected]"
35+
36+
# Create a log entry
37+
echo "[$(date)] Created worktree: $DMUX_SLUG | Agent: $DMUX_AGENT | Prompt: $DMUX_PROMPT" \
38+
>> "$DMUX_ROOT/.dmux/worktree_history.log"
39+
40+
echo "[Hook] Worktree setup complete!"

.github/workflows/publish.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Publish to npm
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup pnpm
18+
uses: pnpm/action-setup@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 22
24+
registry-url: 'https://registry.npmjs.org'
25+
cache: 'pnpm'
26+
27+
- name: Update npm to latest
28+
run: npm install -g npm@latest
29+
30+
- name: Install dependencies
31+
run: pnpm install
32+
33+
- name: Build
34+
run: pnpm build
35+
36+
- name: Publish to npm
37+
run: npm publish --provenance --access public
38+
env:
39+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "@formkit/barcode",
33
"version": "1.0.2",
4+
"packageManager": "[email protected]",
45
"description": "Barcode reader input for FormKit.",
56
"type": "module",
67
"main": "dist/index.cjs",
@@ -33,13 +34,15 @@
3334
"build:cleanup": "npx rimraf dist",
3435
"build:js": "rollup -c",
3536
"build:css": "postcss ./src/assets/barcodeReader.css --output ./dist/assets/barcodeReader.css --use autoprefixer postcss-nesting",
36-
"build": "npm run build:cleanup && npm run build:js && npm run build:css"
37+
"build": "npm run build:cleanup && npm run build:js && npm run build:css",
38+
"release": "pnpm build && bumpp --push"
3739
},
3840
"devDependencies": {
3941
"@rollup/plugin-commonjs": "^25.0.3",
4042
"@rollup/plugin-typescript": "^11.1.2",
4143
"@types/node": "^20.3.2",
4244
"autoprefixer": "^10.4.14",
45+
"bumpp": "^9.9.1",
4346
"postcss": "^8.4.27",
4447
"postcss-cli": "^10.1.0",
4548
"postcss-nesting": "^12.0.0",

0 commit comments

Comments
 (0)