()
| 13 | } |
| 14 | |
| 15 | export const certs = async () => { |
| 16 | const res = await runCommand('mkcert --help'); |
| 17 | |
| 18 | if (res.exitCode === 0) { |
| 19 | const p = envPaths('drizzle-studio', { |
| 20 | suffix: '', |
| 21 | }); |
| 22 | |
| 23 | // create ~/.local/share/drizzle-studio |
| 24 | mkdirSync(p.data, { recursive: true }); |
| 25 | |
| 26 | // ~/.local/share/drizzle-studio |
| 27 | const keyPath = join(p.data, 'localhost-key.pem'); |
| 28 | const certPath = join(p.data, 'localhost.pem'); |
| 29 | |
| 30 | try { |
| 31 | // check if the files exist |
| 32 | await Promise.all([access(keyPath), access(certPath)]); |
| 33 | } catch (e) { |
| 34 | // if not create them |
| 35 | await runCommand(`mkcert localhost`, { cwd: p.data }); |
| 36 | } |
| 37 | const [key, cert] = await Promise.all([ |
| 38 | readFile(keyPath, { encoding: 'utf-8' }), |
| 39 | readFile(certPath, { encoding: 'utf-8' }), |
| 40 | ]); |
| 41 | return key && cert ? { key, cert } : null; |
| 42 | } |
| 43 | return null; |
| 44 | }; |
no test coverage detected