Skip to content

Commit 8232e65

Browse files
authored
feat(pdk): add config file support (#1759)
1 parent b79bb93 commit 8232e65

16 files changed

Lines changed: 1688 additions & 281 deletions

infra/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
"test:watch": "vitest",
1313
"coverage": "vitest run --coverage",
1414
"format": "pnpm prettier --write .",
15-
"release": "pdk release --tag-prefix 'pdk@' --push-tag --build --ignore-scripts --auto-create-release-branch",
16-
"release:dryrun": "pdk release --tag-prefix 'pdk@' --push-tag --build --ignore-scripts --auto-create-release-branch --dry-run",
17-
"release:canary": "pdk release --tag-prefix 'pdk@' --canary --push-tag --build --ignore-scripts --auto-create-release-branch",
18-
"release:full": "pdk release --tag-prefix 'pdk@' --push-tag --build --ignore-scripts --create-github-release",
15+
"release": "pdk release ",
16+
"release:dryrun": "pdk release --dry-run",
17+
"release:canary": "pdk release --canary",
18+
"release:full": "pdk release --create-github-release",
1919
"github-release": "pdk github-release",
2020
"github-release:dryrun": "pdk github-release --dry-run",
2121
"changelog": "pdk changelog",

infra/pdk.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'pnpm-dev-kit'
2+
3+
export default defineConfig({
4+
autoCreateReleaseBranch: true,
5+
build: true,
6+
tagPrefix: 'pdk@',
7+
pushTag: true,
8+
ignoreScripts: true,
9+
});

infra/pdk/README.md

Lines changed: 140 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,128 +5,184 @@
55
<a href="https://www.npmjs.com/package/pnpm-dev-kit"><img src="https://img.shields.io/npm/dm/pnpm-dev-kit.svg?style=flat-square" alt="npm downloads"></a>
66
<a href="https://github.com/license"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="license"></a>
77
</p>
8-
<p align="center">PDK - PNPM Dev Kit, An efficient PNPM workspace development and publishing tool.</p>
8+
<p align="center">Efficient PNPM workspace development and publishing toolkit</p>
99
</p>
1010

1111
## Features
1212

13-
- 💻 **Dev Mode**: Quickly launch on-demand development builds for monorepo packages
14-
- 🚀 **Release Management**: Automated version bumping and publishing
15-
- 🔧 **Patch System**: Repair failed package publications
16-
- 📝 **Changelog Generation**: Automatic, customizable changelog creation
17-
- 🏷️ **GitHub Release**: Automatic GitHub release creation with changelog extraction
13+
- **Dev Mode**: On-demand builds with file watching
14+
- **Release**: Automated versioning and publishing
15+
- **Patch**: Targeted fixes for failed releases
16+
- **Changelog**: AI-powered or conventional changelog generation
17+
- **GitHub Release**: Automatic GitHub releases with changelog
1818

19-
## Install
19+
## Quick Start
2020

2121
```bash
22-
# Using npm
23-
npm install --save-dev pnpm-dev-kit
22+
npm install -D pnpm-dev-kit
23+
```
2424

25-
# Using yarn
26-
yarn add --dev pnpm-dev-kit
25+
### Basic Usage
2726

28-
# Using pnpm
29-
pnpm add -D pnpm-dev-kit
27+
```bash
28+
# Development mode
29+
pdk dev
30+
31+
# Release with changelog and GitHub release
32+
pdk release --push-tag --create-github-release
33+
34+
# Generate changelog
35+
pdk changelog --use-ai --provider openai --model gpt-4o
36+
37+
# Fix failed release
38+
pdk patch --version 1.0.0 --tag latest
3039
```
3140

32-
For global installation:
41+
## Configuration
3342

34-
```bash
35-
npm install -g pnpm-dev-kit
43+
Create `pdk.config.ts` in your project root:
44+
45+
```typescript
46+
import { defineConfig } from 'pnpm-dev-kit';
47+
48+
export default defineConfig({
49+
// Core options
50+
tagPrefix: 'v',
51+
dryRun: false,
52+
runInBand: false,
53+
ignoreScripts: false,
54+
55+
// AI changelog
56+
useAi: true,
57+
model: 'gpt-4o',
58+
provider: 'openai',
59+
apiKey: process.env.OPENAI_API_KEY,
60+
61+
// Changelog filters
62+
filterTypes: ['feat', 'fix', 'perf'],
63+
filterScopes: ['core', 'ui', 'api'],
64+
65+
// Release defaults
66+
changelog: true,
67+
pushTag: true,
68+
createGithubRelease: true,
69+
autoCreateReleaseBranch: false,
70+
71+
// Dev mode
72+
exclude: ['@scope/package-to-exclude'],
73+
packages: ['@scope/package-to-start'],
74+
});
3675
```
3776

38-
## Usage
77+
### Configuration Options
3978

40-
### Development Mode
79+
#### Core Options
4180

42-
Quickly start development mode to build packages on demand when files change:
81+
| Option | Type | Default | Description |
82+
|--------|------|---------|-------------|
83+
| `cwd` | `string` | `process.cwd()` | Working directory |
84+
| `dryRun` | `boolean` | `false` | Preview mode without changes |
85+
| `runInBand` | `boolean` | `false` | Publish packages sequentially |
86+
| `ignoreScripts` | `boolean` | `false` | Skip npm scripts |
87+
| `tagPrefix` | `string` | `'v'` | Git tag prefix |
4388

44-
```bash
45-
# Using the CLI
46-
pdk dev
89+
#### AI Options
4790

48-
# Or with npm script
49-
npm run dev
50-
```
91+
| Option | Type | Default | Description |
92+
|--------|------|---------|-------------|
93+
| `useAi` | `boolean` | `false` | Enable AI changelog generation |
94+
| `model` | `string` | `'gpt-4o'` | LLM model |
95+
| `provider` | `string` | `'openai'` | LLM provider |
96+
| `apiKey` | `string` | - | API key (use env var) |
97+
| `baseURL` | `string` | - | Custom API endpoint |
5198

52-
**Interactive Features:**
99+
#### Filter Options
53100

54-
- Type `n` to select a package to build manually
55-
- Type `ps` to list running processes
56-
- Type package name to build a specific package
101+
| Option | Type | Default | Description |
102+
|--------|------|---------|-------------|
103+
| `filterTypes` | `string[]` | `['feat', 'fix']` | Commit types to include |
104+
| `filterScopes` | `string[]` | `[]` | Scopes to include (empty = all) |
57105

58-
### Release Process
106+
#### Command-Specific Options
59107

60-
**Standard Release:**
61-
```bash
62-
# Complete release (recommended)
63-
pdk release --push-tag --create-github-release
108+
**Development (`dev`)**:
109+
- `exclude`: Packages to exclude from startup
110+
- `packages`: Packages to start by default
64111

65-
# Canary release for CI/CD
66-
pdk release --canary
67-
```
112+
**Release (`release`)**:
113+
- `changelog`: Generate changelog (default: `true`)
114+
- `build`: Build before publishing (`false` or script name)
115+
- `pushTag`: Push git tags (default: `false`)
116+
- `canary`: Canary release (default: `false`)
117+
- `createGithubRelease`: Create GitHub release (default: `false`)
118+
- `autoCreateReleaseBranch`: Auto-create release branch (default: `false`)
68119

69-
**Release Flow:**
70-
1. Select version type (patch/minor/major/prerelease)
71-
2. Choose NPM tag (latest/next/beta)
72-
3. Update workspace dependencies
73-
4. Publish packages to NPM
74-
5. Create git tag and push to remote
75-
6. Generate CHANGELOG.md
76-
7. Create GitHub Release
120+
**Changelog (`changelog`)**:
121+
- `version`: Target version
122+
- `beautify`: Format markdown (default: `false`)
123+
- `commit`: Git commit changelog (default: `false`)
124+
- `gitPush`: Push commit (default: `false`)
125+
- `attachAuthor`: Include author info (default: `false`)
126+
- `authorNameType`: Author format (`'name'` or `'email'`, default: `'name'`)
77127

78-
**Failed Release Recovery:**
79-
```bash
80-
pdk patch --version 1.0.0 --tag latest
81-
```
128+
**Patch (`patch`)**:
129+
- `version`: Version to patch
130+
- `tag`: Distribution tag
82131

83-
**Changelog Generation:**
84-
```bash
85-
# Standard changelog
86-
pdk changelog --version 1.0.0 --beautify --commit --git-push
132+
**GitHub Release (`github-release`)**:
133+
- `version`: Release version
87134

88-
# AI-powered changelog
89-
pdk changelog --version 1.0.0 --use-ai --provider openai --model gpt-4o
90-
```
135+
## Configuration vs CLI
91136

92-
**GitHub Release:**
93-
```bash
94-
pdk github-release --version 1.0.0
95-
pdk github-release --dry-run # Preview
96-
```
137+
### Use Config File For
97138

98-
**Key Options:**
99-
- `--dry-run`: Preview without changes
100-
- `--run-in-band`: Publish packages in series
101-
- `--build`: Custom build script before release
102-
- `--ignore-scripts`: Skip npm scripts
103-
- `--auto-create-release-branch`: Auto-create release branch
104-
- `--filter-scopes`: Filter by scope (default: tars,agent,tarko,o-agent,tars-stack,browser,infra,mcp,all)
105-
- `--filter-types`: Filter by commit type (default: feat,fix)
139+
- **Project conventions**: `tagPrefix`, `filterTypes`, `filterScopes`
140+
- **Team preferences**: `useAi`, `model`, `provider`, `runInBand`
141+
- **Workflow defaults**: `changelog`, `pushTag`, `createGithubRelease`
106142

107-
## Configuration
143+
### Use CLI For
144+
145+
- **Environment-specific**: `dryRun`, `cwd`, `version`
146+
- **One-time operations**: `exclude`, `packages`, `build`, `canary`
147+
- **Sensitive data**: `apiKey` (use environment variables)
148+
149+
### Priority Order
150+
151+
1. CLI arguments
152+
2. Environment variables
153+
3. Configuration file
154+
4. Default values
155+
156+
## API Usage
157+
158+
```typescript
159+
import { loadPDKConfig, dev, release } from 'pnpm-dev-kit';
160+
161+
// Load configuration
162+
const config = await loadPDKConfig({ cwd: './my-project' });
163+
164+
// Use with commands
165+
await dev(config.resolved);
166+
await release(config.resolved);
167+
```
168+
169+
## package.json Scripts
108170

109-
**package.json Scripts:**
110171
```json
111172
{
112173
"scripts": {
113174
"dev": "pdk dev",
114-
"release": "pdk release --push-tag",
175+
"release": "pdk release",
115176
"release:full": "pdk release --push-tag --create-github-release",
116177
"release:canary": "pdk release --canary",
117-
"github-release": "pdk github-release",
118178
"changelog": "pdk changelog",
119179
"patch": "pdk patch --version $(node -p \"require('./package.json').version\") --tag latest"
120180
}
121181
}
122182
```
123183

124-
**Workspace Setup:**
125-
- Uses `pnpm-workspace.yaml` for package discovery
126-
- Follows conventional commit standards
127-
- Auto-updates internal workspace dependencies
184+
## CI/CD Integration
128185

129-
**CI/CD Integration:**
130186
```yaml
131187
# .github/workflows/release.yml
132188
name: Release
@@ -150,14 +206,14 @@ jobs:
150206
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
151207
```
152208
153-
**Best Practices:**
154-
- Always release from latest main branch
155-
- Ensure clean working directory
156-
- Run tests before release
209+
## Best Practices
210+
211+
- Always release from clean `main` branch
157212
- Use `--dry-run` for testing
158213
- Canary format: `{version}-canary-{commitHash}-{timestamp}`
159-
- Auto-rollback on publish failure
214+
- Keep sensitive data in environment variables
215+
- Review config changes in pull requests
160216

161217
## License
162218

163-
This project is licensed under the Apache License 2.0.
219+
Apache License 2.0

infra/pdk/bin/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env node
22

3-
require('../dist/cli').bootstrapCli();
3+
require('../dist/index').bootstrapCli();

infra/pdk/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"description": "PDK (pnpm dev kit), an efficient pnpm workspace development and publishing tool",
44
"version": "0.0.5",
55
"main": "dist/index.js",
6-
"module": "dist/index.mjs",
76
"types": "dist/index.d.ts",
87
"publishConfig": {
98
"access": "public",
@@ -19,9 +18,11 @@
1918
"scripts": {
2019
"dev": "rslib build --watch",
2120
"build": "rslib build",
21+
"test": "vitest run",
2222
"prepublishOnly": "pnpm run build"
2323
},
2424
"dependencies": {
25+
"@tarko/config-loader": "0.3.0",
2526
"@tarko/model-provider": "0.3.0",
2627
"boxen": "4",
2728
"cac": "^6.5.10",
@@ -47,6 +48,7 @@
4748
"@types/string-width": "^4.0.1",
4849
"@types/text-table": "^0.2.0",
4950
"rimraf": "4.1.0",
50-
"typescript": "5.8.3"
51+
"typescript": "5.8.3",
52+
"vitest": "3.2.4"
5153
}
5254
}

0 commit comments

Comments
 (0)