UNPKG

@augment-vir/node

Version:

A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.

46 lines (45 loc) 1.62 kB
import { wrapString } from '@augment-vir/common'; /** * Used for `type` in {@link DockerVolumeMap}. These types are apparently only relevant for running * Docker on macOS and are potentially irrelevant now. It's likely best to leave the `type` property * empty (`undefined`). * * @category Node : Docker : Util * @category Package : @augment-vir/node * @package [`@augment-vir/node`](https://www.npmjs.com/package/@augment-vir/node) */ export var DockerVolumeMappingType; (function (DockerVolumeMappingType) { DockerVolumeMappingType["Cached"] = "cached"; DockerVolumeMappingType["Delegated"] = "delegated"; })(DockerVolumeMappingType || (DockerVolumeMappingType = {})); export function makeVolumeFlags(volumeMapping) { if (!volumeMapping) { return ''; } const parts = volumeMapping.map((volume) => { const mountType = volume.type ? `:${volume.type}` : ''; return `-v '${volume.hostAbsolutePath}':'${volume.containerAbsolutePath}'${mountType}`; }); return parts.join(' '); } export function makePortMapFlags(portMapping) { if (!portMapping) { return ''; } return portMapping .map((portMap) => { return `-p ${portMap.hostPort}:${portMap.containerPort}`; }) .join(' '); } export function makeEnvFlags(envMapping) { if (!envMapping) { return ''; } const flags = Object.entries(envMapping).map(([key, { value, allowInterpolation },]) => { const quote = allowInterpolation ? '"' : "'"; return `-e ${key}=${wrapString({ value, wrapper: quote })}`; }); return flags.join(' '); }