Skip to content

Commit

Permalink
fix: Fix certs util
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanNabukhotnyi committed Jan 6, 2025
1 parent c8a4996 commit 93e8b54
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions drizzle-kit/src/utils/certs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -33,5 +36,3 @@ export const certs = async () => {
}
return null;
};

certs();

0 comments on commit 93e8b54

Please sign in to comment.