Skip to content

Commit 29f1ebb

Browse files
committed
enums publishing
1 parent bf506e7 commit 29f1ebb

File tree

4 files changed

+403
-2
lines changed

4 files changed

+403
-2
lines changed

PUBLISH.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
# Publishing Guide
22

3-
## Types Packages
3+
## Automated Publishing (Recommended)
4+
5+
### Types Packages
6+
```bash
7+
pnpm run publish:types
8+
```
9+
10+
This interactive script will:
11+
- Check for uncommitted changes (will error if any exist)
12+
- Let you select which versions to publish (or all)
13+
- Ask for version bump type (patch or minor only)
14+
- Build, prepare, and publish each selected version
15+
- Optionally promote pg17 to latest
16+
17+
### Enums Packages
18+
```bash
19+
pnpm run publish:enums
20+
```
21+
22+
This interactive script will:
23+
- Check for uncommitted changes (will error if any exist)
24+
- Let you select which versions to publish (or all)
25+
- Ask for version bump type (patch or minor only)
26+
- Build, prepare, and publish each selected version
27+
- Optionally promote pg17 to latest
28+
29+
## Manual Publishing
30+
31+
### Types Packages
432

533
```bash
634
# Set the version (e.g. 17, 16, 15, etc.)
@@ -29,6 +57,35 @@ npm dist-tag add @pgsql/types@pg${VERSION} latest
2957
- Transforms `@libpg-query/types16``@pgsql/types` with tag `pg16`
3058
- etc.
3159

60+
### Enums Packages
61+
62+
```bash
63+
# Set the version (e.g. 17, 16, 15, etc.)
64+
VERSION=17
65+
66+
cd enums/${VERSION}
67+
pnpm version patch
68+
git add . && git commit -m "release: bump @pgsql/enums${VERSION} version"
69+
pnpm build
70+
pnpm prepare:enums
71+
pnpm publish --tag pg${VERSION}
72+
```
73+
74+
Promote to latest (optional)
75+
76+
```bash
77+
# Set the version (e.g. 17, 16, 15, etc.)
78+
VERSION=17
79+
80+
# Promote pg${VERSION} tag to latest
81+
npm dist-tag add @pgsql/enums@pg${VERSION} latest
82+
```
83+
84+
### What it does
85+
- Transforms `@libpg-query/enums17``@pgsql/enums` with tag `pg17`
86+
- Transforms `@libpg-query/enums16``@pgsql/enums` with tag `pg16`
87+
- etc.
88+
3289
## Version Packages
3390

3491
### Quick Publish

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"build:types": "node scripts/build-types.js",
1616
"prepare:types": "node scripts/prepare-types.js",
1717
"build:enums": "node scripts/build-enums.js",
18-
"prepare:enums": "node scripts/prepare-enums.js"
18+
"prepare:enums": "node scripts/prepare-enums.js",
19+
"publish:types": "node scripts/publish-types.js",
20+
"publish:enums": "node scripts/publish-enums.js"
1921
},
2022
"devDependencies": {
2123
"@types/node": "^20.0.0",

scripts/publish-enums.js

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/env node
2+
3+
const { execSync } = require('child_process');
4+
const readline = require('readline');
5+
const path = require('path');
6+
const fs = require('fs');
7+
8+
const rl = readline.createInterface({
9+
input: process.stdin,
10+
output: process.stdout
11+
});
12+
13+
const VERSIONS = ['17', '16', '15', '14', '13'];
14+
15+
function checkGitStatus() {
16+
try {
17+
const status = execSync('git status --porcelain', { encoding: 'utf8' });
18+
if (status.trim()) {
19+
console.error('❌ Error: You have uncommitted changes. Please commit or stash them before publishing.');
20+
console.error('Uncommitted files:');
21+
console.error(status);
22+
process.exit(1);
23+
}
24+
} catch (error) {
25+
console.error('❌ Error checking git status:', error.message);
26+
process.exit(1);
27+
}
28+
}
29+
30+
function askQuestion(question) {
31+
return new Promise((resolve) => {
32+
rl.question(question, (answer) => {
33+
resolve(answer.toLowerCase().trim());
34+
});
35+
});
36+
}
37+
38+
async function selectVersions() {
39+
console.log('Available versions:', VERSIONS.join(', '));
40+
const answer = await askQuestion('Which versions do you want to publish? (comma-separated, or "all" for all versions): ');
41+
42+
if (answer === 'all') {
43+
return VERSIONS;
44+
}
45+
46+
const selected = answer.split(',').map(v => v.trim()).filter(v => VERSIONS.includes(v));
47+
if (selected.length === 0) {
48+
console.error('❌ No valid versions selected.');
49+
process.exit(1);
50+
}
51+
52+
return selected;
53+
}
54+
55+
async function selectBumpType() {
56+
const answer = await askQuestion('Version bump type? (patch/minor): ');
57+
58+
if (!['patch', 'minor'].includes(answer)) {
59+
console.error('❌ Invalid bump type. Only "patch" or "minor" are allowed.');
60+
process.exit(1);
61+
}
62+
63+
return answer;
64+
}
65+
66+
async function confirmPublish(versions, bumpType) {
67+
console.log('\n📋 Summary:');
68+
console.log(` - Versions to publish: ${versions.join(', ')}`);
69+
console.log(` - Bump type: ${bumpType}`);
70+
71+
const answer = await askQuestion('\nProceed with publishing? (yes/no): ');
72+
return answer === 'yes' || answer === 'y';
73+
}
74+
75+
function publishVersion(version, bumpType) {
76+
const packageDir = path.join(__dirname, '..', 'enums', version);
77+
78+
console.log(`\n📦 Publishing @libpg-query/enums${version}...`);
79+
80+
try {
81+
// Change to package directory
82+
process.chdir(packageDir);
83+
84+
// Bump version
85+
console.log(` - Bumping ${bumpType} version...`);
86+
execSync(`pnpm version ${bumpType}`, { stdio: 'inherit' });
87+
88+
// Get the new version
89+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
90+
const newVersion = packageJson.version;
91+
92+
// Commit the version bump
93+
console.log(` - Committing version bump...`);
94+
execSync(`git add package.json`, { stdio: 'inherit' });
95+
execSync(`git commit -m "release: bump @libpg-query/enums${version} to ${newVersion}"`, { stdio: 'inherit' });
96+
97+
// Build
98+
console.log(` - Building...`);
99+
execSync('pnpm build', { stdio: 'inherit' });
100+
101+
// Prepare for publishing
102+
console.log(` - Preparing for publish...`);
103+
execSync('pnpm prepare:enums', { stdio: 'inherit' });
104+
105+
// Publish
106+
console.log(` - Publishing to npm with tag pg${version}...`);
107+
execSync(`pnpm publish --tag pg${version} --no-git-checks`, { stdio: 'inherit' });
108+
109+
console.log(`✅ Successfully published @pgsql/enums@${newVersion} with tag pg${version}`);
110+
111+
} catch (error) {
112+
console.error(`❌ Error publishing version ${version}:`, error.message);
113+
throw error;
114+
}
115+
}
116+
117+
async function main() {
118+
console.log('🚀 Enums Package Publisher\n');
119+
120+
// Check git status
121+
checkGitStatus();
122+
123+
// Select versions
124+
const versions = await selectVersions();
125+
126+
// Select bump type
127+
const bumpType = await selectBumpType();
128+
129+
// Confirm
130+
const confirmed = await confirmPublish(versions, bumpType);
131+
if (!confirmed) {
132+
console.log('❌ Publishing cancelled.');
133+
rl.close();
134+
process.exit(0);
135+
}
136+
137+
// Publish each version
138+
for (const version of versions) {
139+
try {
140+
publishVersion(version, bumpType);
141+
} catch (error) {
142+
console.error(`\n❌ Failed to publish version ${version}. Stopping.`);
143+
rl.close();
144+
process.exit(1);
145+
}
146+
}
147+
148+
console.log('\n✅ All versions published successfully!');
149+
150+
// Ask about promoting to latest
151+
if (versions.includes('17')) {
152+
const promoteAnswer = await askQuestion('\nDo you want to promote pg17 to latest? (yes/no): ');
153+
if (promoteAnswer === 'yes' || promoteAnswer === 'y') {
154+
try {
155+
console.log('Promoting pg17 to latest...');
156+
execSync('npm dist-tag add @pgsql/enums@pg17 latest', { stdio: 'inherit' });
157+
console.log('✅ Successfully promoted pg17 to latest');
158+
} catch (error) {
159+
console.error('❌ Error promoting to latest:', error.message);
160+
}
161+
}
162+
}
163+
164+
rl.close();
165+
}
166+
167+
main().catch(error => {
168+
console.error('❌ Unexpected error:', error);
169+
rl.close();
170+
process.exit(1);
171+
});

0 commit comments

Comments
 (0)