UNPKG

@deploystack/docker-to-iac

Version:

Translate docker run and docker compose file to Infrastructure as Code

39 lines (38 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeVolume = normalizeVolume; function normalizeVolume(volumeString) { // Split volume string into parts const parts = volumeString.split(':'); // Replace environment variables with safe defaults const normalizeHostPath = (path) => { // Replace $HOME, ${HOME}, ~/ with ./ return path .replace(/\$HOME/g, '.') .replace(/\${HOME}/g, '.') .replace(/^~\//, './'); }; if (parts.length === 1) { // Single path - use as both host and container path const normalizedPath = normalizeHostPath(parts[0]); return { host: normalizedPath, container: normalizedPath }; } else if (parts.length === 2) { // Host:Container format return { host: normalizeHostPath(parts[0]), container: parts[1] }; } else { // Host:Container:Mode format return { host: normalizeHostPath(parts[0]), container: parts[1], mode: parts[2] }; } }