@travetto/exec
Advanced tools
Comparing version 0.0.32 to 0.0.33
@@ -17,3 +17,3 @@ { | ||
}, | ||
"version": "0.0.32" | ||
"version": "0.0.33" | ||
} |
import { DockerContainer } from './docker'; | ||
import { AppEnv } from '@travetto/base'; | ||
import { spawn } from './util'; | ||
import { ChildProcess } from 'child_process'; | ||
import { ExecutionResult, CommonProcess } from './types'; | ||
@@ -9,2 +8,4 @@ | ||
private _initPromise: Promise<any>; | ||
container: DockerContainer; | ||
@@ -15,2 +16,3 @@ | ||
imageStartCommand?: string; | ||
checkLocal?: () => Promise<boolean>; | ||
imageCommand?: (args: string[]) => string[]; | ||
@@ -21,4 +23,7 @@ processCommand?: (args: string[]) => string[]; | ||
async init() { | ||
if (AppEnv.docker && (this.config.docker === undefined || !!this.config.docker)) { | ||
async _init() { | ||
const canUseDocker = AppEnv.docker && (this.config.docker === undefined || !!this.config.docker); | ||
const useDocker = canUseDocker && (!this.config.checkLocal || (await this.config.checkLocal())); | ||
if (useDocker) { | ||
this.container = new DockerContainer(this.config.image) | ||
@@ -33,3 +38,12 @@ .forceDestroyOnShutdown() | ||
exec(...args: string[]) { | ||
async init() { | ||
if (!this._initPromise) { | ||
this._initPromise = this._init(); | ||
} | ||
return await this._initPromise; | ||
} | ||
async exec(...args: string[]) { | ||
await this.init(); | ||
let exec; | ||
@@ -36,0 +50,0 @@ if (this.container) { |
@@ -7,9 +7,7 @@ import * as child_process from 'child_process'; | ||
import { CommonProcess, ChildOptions, ExecutionResult } from './types'; | ||
import { CommonProcess, ExecutionResult } from './types'; | ||
import { spawn, WithOpts } from './util'; | ||
import { Shutdown, rimraf, isPlainObject } from '@travetto/base'; | ||
import { CpuInfo } from 'os'; | ||
import { Shutdown, rimraf } from '@travetto/base'; | ||
const writeFile = util.promisify(fs.writeFile); | ||
const mkTempDir = util.promisify(fs.mkdtemp); | ||
const mkdir = util.promisify(fs.mkdir); | ||
@@ -16,0 +14,0 @@ |
22609
717