@@ -4,25 +4,29 @@ import { access, readFile } from 'fs/promises';
44import { join } from 'path' ;
55import { $ } from 'zx' ;
66
7- const p = envPaths ( 'drizzle-studio' , {
8- suffix : '' ,
9- } ) ;
10-
11- $ . verbose = false ;
12- $ . cwd = p . data ;
13- mkdirSync ( p . data , { recursive : true } ) ;
14-
157export const certs = async ( ) => {
16- const res = await $ `mkcert --help` . nothrow ( ) ;
8+ $ . verbose = false ;
179
18- // ~/.local/share/drizzle-studio
19- const keyPath = join ( p . data , 'localhost-key.pem' ) ;
20- const certPath = join ( p . data , 'localhost.pem' ) ;
10+ const res = await $ `mkcert --help` . nothrow ( ) ;
2111
2212 if ( res . exitCode === 0 ) {
13+ const p = envPaths ( 'drizzle-studio' , {
14+ suffix : '' ,
15+ } ) ;
16+
17+ $ . cwd = p . data ;
18+
19+ // create ~/.local/share/drizzle-studio
20+ mkdirSync ( p . data , { recursive : true } ) ;
21+
22+ const keyPath = join ( p . data , 'localhost-key.pem' ) ;
23+ const certPath = join ( p . data , 'localhost.pem' ) ;
24+
2325 try {
26+ // check if the files exist
2427 await Promise . all ( [ access ( keyPath ) , access ( certPath ) ] ) ;
2528 } catch ( e ) {
29+ // if not create them
2630 await $ `mkcert localhost` . nothrow ( ) ;
2731 }
2832 const [ key , cert ] = await Promise . all ( [
@@ -33,5 +37,3 @@ export const certs = async () => {
3337 }
3438 return null ;
3539} ;
36-
37- certs ( ) ;
0 commit comments