@@ -72,6 +72,52 @@ function hr() {
7272 return "─" . repeat ( process . stdout . columns ?? 40 ) ;
7373}
7474
75+ function listDatabases ( ) {
76+ const meteorLocalDir = path . join ( 'meteor' , '.meteor' , 'local' ) ;
77+ const dbLink = path . join ( meteorLocalDir , 'db' ) ;
78+
79+ if ( ! fs . existsSync ( meteorLocalDir ) ) {
80+ console . log ( 'No databases found (meteor/.meteor/local does not exist yet)' ) ;
81+ return ;
82+ }
83+
84+ // Get current database
85+ let currentDb = null ;
86+ if ( fs . existsSync ( dbLink ) ) {
87+ const stats = fs . lstatSync ( dbLink ) ;
88+ if ( stats . isSymbolicLink ( ) ) {
89+ const target = fs . readlinkSync ( dbLink ) ;
90+ const match = target . match ( / ^ d b \. ( .+ ) $ / ) ;
91+ if ( match ) {
92+ currentDb = match [ 1 ] ;
93+ }
94+ } else {
95+ currentDb = '(unnamed - real directory)' ;
96+ }
97+ }
98+
99+ // List all db.* directories
100+ const files = fs . readdirSync ( meteorLocalDir ) ;
101+ const dbDirs = files
102+ . filter ( file => file . startsWith ( 'db.' ) && fs . statSync ( path . join ( meteorLocalDir , file ) ) . isDirectory ( ) )
103+ . map ( file => file . substring ( 3 ) ) ;
104+
105+ console . log ( '\nAvailable databases:' ) ;
106+ if ( dbDirs . length === 0 ) {
107+ console . log ( ' (none found)' ) ;
108+ } else {
109+ dbDirs . sort ( ) . forEach ( db => {
110+ const marker = db === currentDb ? ' ← current' : '' ;
111+ console . log ( ` ${ db } ${ marker } ` ) ;
112+ } ) ;
113+ }
114+
115+ if ( currentDb && ! dbDirs . includes ( currentDb ) ) {
116+ console . log ( `\nCurrent: ${ currentDb } ` ) ;
117+ }
118+ console . log ( '' ) ;
119+ }
120+
75121function switchDatabase ( dbName ) {
76122 const meteorLocalDir = path . join ( 'meteor' , '.meteor' , 'local' ) ;
77123 const dbLink = path . join ( meteorLocalDir , 'db' ) ;
@@ -118,6 +164,12 @@ function switchDatabase(dbName) {
118164try {
119165 // Note: This script assumes that install-and-build.mjs has been run before
120166
167+ // List databases if requested
168+ if ( config . dbList ) {
169+ listDatabases ( ) ;
170+ process . exit ( 0 ) ;
171+ }
172+
121173 // Switch database if requested
122174 if ( config . dbName ) {
123175 switchDatabase ( config . dbName ) ;
0 commit comments