From 93e8b5415a02f7416ee82e71ac23e08882ac4f94 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 6 Jan 2025 19:04:50 +0200 Subject: [PATCH] fix: Fix certs util --- drizzle-kit/src/utils/certs.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/drizzle-kit/src/utils/certs.ts b/drizzle-kit/src/utils/certs.ts index b9a6d4de8..e4fd72486 100644 --- a/drizzle-kit/src/utils/certs.ts +++ b/drizzle-kit/src/utils/certs.ts @@ -4,25 +4,28 @@ import { access, readFile } from 'fs/promises'; import { join } from 'path'; import { $ } from 'zx'; -const p = envPaths('drizzle-studio', { - suffix: '', -}); - -$.verbose = false; -$.cwd = p.data; -mkdirSync(p.data, { recursive: true }); - export const certs = async () => { const res = await $`mkcert --help`.nothrow(); - // ~/.local/share/drizzle-studio - const keyPath = join(p.data, 'localhost-key.pem'); - const certPath = join(p.data, 'localhost.pem'); - if (res.exitCode === 0) { + const p = envPaths('drizzle-studio', { + suffix: '', + }); + + $.verbose = false; + $.cwd = p.data; + + // create ~/.local/share/drizzle-studio + mkdirSync(p.data, { recursive: true }); + + const keyPath = join(p.data, 'localhost-key.pem'); + const certPath = join(p.data, 'localhost.pem'); + try { + // check if the files exist await Promise.all([access(keyPath), access(certPath)]); } catch (e) { + // if not create them await $`mkcert localhost`.nothrow(); } const [key, cert] = await Promise.all([ @@ -33,5 +36,3 @@ export const certs = async () => { } return null; }; - -certs();