UNPKG

vite-plugin-mkcert

Version:

Provide certificates for vite's https dev service

38 lines (31 loc) 887 B
import child_process, { type ExecFileOptions, type ExecOptions } from 'node:child_process' import process from 'node:process' import util from 'node:util' export const exec = async (cmd: string, options?: ExecOptions) => { return util.promisify(child_process.exec)(cmd, options) } export const execFile = async ( file: string, args: string[] = [], options?: ExecFileOptions ) => { return util.promisify(child_process.execFile)(file, args, options) } export const findCommandFromPath = async (command: string) => { const lookupCmd = process.platform === 'win32' ? `where ${command}` : `command -v ${command}` try { const { stdout } = await exec(lookupCmd) const output = stdout.toString().trim() if (!output) { return undefined } return output.split(/\r?\n/)[0].trim() || undefined } catch (_error) { return undefined } }