Skip to content

Commit

Permalink
Merge pull request #2734 from kravetsone/replace-zx-with-child-process
Browse files Browse the repository at this point in the history
Replace `zx` with native `child_process`
  • Loading branch information
AlexBlokh authored Jan 16, 2025
2 parents 8e428d1 + f9ee2aa commit bd7c23e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions drizzle-kit/src/utils/certs.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import envPaths from 'env-paths';
import { mkdirSync } from 'fs';
import { access, readFile } from 'fs/promises';
import { exec, ExecOptions } from 'node:child_process';
import { join } from 'path';
import { $ } from 'zx';

export const certs = async () => {
$.verbose = false;
export function runCommand(command: string, options: ExecOptions = {}) {
return new Promise<{ exitCode: number }>((resolve) => {
exec(command, options, (error) => {
return resolve({ exitCode: error?.code ?? 0 });
});
});
}

const res = await $`mkcert --help`.nothrow();
export const certs = async () => {
const res = await runCommand('mkcert --help');

if (res.exitCode === 0) {
const p = envPaths('drizzle-studio', {
suffix: '',
});

$.cwd = p.data;

// create ~/.local/share/drizzle-studio
mkdirSync(p.data, { recursive: true });

// ~/.local/share/drizzle-studio
const keyPath = join(p.data, 'localhost-key.pem');
const certPath = join(p.data, 'localhost.pem');

Expand All @@ -27,7 +32,7 @@ export const certs = async () => {
await Promise.all([access(keyPath), access(certPath)]);
} catch (e) {
// if not create them
await $`mkcert localhost`.nothrow();
await runCommand(`mkcert localhost`, { cwd: p.data });
}
const [key, cert] = await Promise.all([
readFile(keyPath, { encoding: 'utf-8' }),
Expand Down

0 comments on commit bd7c23e

Please sign in to comment.