11import envPaths from 'env-paths' ;
22import { mkdirSync } from 'fs' ;
33import { access , readFile } from 'fs/promises' ;
4+ import { exec , ExecOptions } from 'node:child_process' ;
45import { join } from 'path' ;
5- import { $ } from 'zx' ;
66
7- export const certs = async ( ) => {
8- $ . verbose = false ;
7+ export function runCommand ( command : string , options : ExecOptions = { } ) {
8+ return new Promise < { exitCode : number } > ( ( resolve ) => {
9+ exec ( command , options , ( error ) => {
10+ return resolve ( { exitCode : error ?. code ?? 0 } ) ;
11+ } ) ;
12+ } ) ;
13+ }
914
10- const res = await $ `mkcert --help` . nothrow ( ) ;
15+ export const certs = async ( ) => {
16+ const res = await runCommand ( 'mkcert --help' ) ;
1117
1218 if ( res . exitCode === 0 ) {
1319 const p = envPaths ( 'drizzle-studio' , {
1420 suffix : '' ,
1521 } ) ;
1622
17- $ . cwd = p . data ;
18-
1923 // create ~/.local/share/drizzle-studio
2024 mkdirSync ( p . data , { recursive : true } ) ;
2125
26+ // ~/.local/share/drizzle-studio
2227 const keyPath = join ( p . data , 'localhost-key.pem' ) ;
2328 const certPath = join ( p . data , 'localhost.pem' ) ;
2429
@@ -27,7 +32,7 @@ export const certs = async () => {
2732 await Promise . all ( [ access ( keyPath ) , access ( certPath ) ] ) ;
2833 } catch ( e ) {
2934 // if not create them
30- await $ `mkcert localhost` . nothrow ( ) ;
35+ await runCommand ( `mkcert localhost` , { cwd : p . data } ) ;
3136 }
3237 const [ key , cert ] = await Promise . all ( [
3338 readFile ( keyPath , { encoding : 'utf-8' } ) ,
0 commit comments