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