import { readFileSync } from 'fs'; import { platform } from 'os'; let __isMeInDocker: boolean = null; // https://stackoverflow.com/questions/20010199/determining-if-a-process-runs-inside-lxc-docker/20010626 export function isMeInDocker(): boolean { if (platform() !== 'linux') { return false; } if (__isMeInDocker === null) { __isMeInDocker = readFileSync('/proc/1/cgroup').indexOf('/docker/') !== -1; } return __isMeInDocker; } let colorEnabled: boolean = null; export function isColorEnabled(): boolean { if (colorEnabled === null) { if (isMeInDocker() === true) { colorEnabled = false; } else { colorEnabled = process.stderr.isTTY || false; } } return colorEnabled; }