Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexibility in process creation #261

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
import yaml from 'yaml'
import mapPorts from './map-ports'

export interface IDockerComposeExecutableOptions {
executablePath: string
options?: string[] | (string | string[])[]
}

export interface IDockerComposeOptions {
cwd?: string
executablePath?: string
executable?: IDockerComposeExecutableOptions
config?: string | string[]
configAsString?: string
log?: boolean
Expand Down Expand Up @@ -156,8 +161,8 @@
* Executes docker-compose command with common options
*/
export const execCompose = (
command,

Check warning on line 164 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Argument 'command' should be typed
args,

Check warning on line 165 in src/index.ts

View workflow job for this annotation

GitHub Actions / Lint

Argument 'args' should be typed
options: IDockerComposeOptions = {}
): Promise<IDockerComposeResult> =>
new Promise((resolve, reject): void => {
Expand All @@ -178,12 +183,21 @@

const cwd = options.cwd
const env = options.env || undefined
const executablePath = options.executablePath || 'docker-compose'
const executable = options.executable || {
executablePath: 'docker-compose'
}

const childProc = childProcess.spawn(executablePath, composeArgs, {
cwd,
env
})
const executableOptions = executable.options || []
const executableArgs = composeOptionsToArgs(executableOptions)

const childProc = childProcess.spawn(
executable.executablePath,
executableArgs.concat(composeArgs),
{
cwd,
env
}
)

childProc.on('error', (err): void => {
reject(err)
Expand Down
16 changes: 12 additions & 4 deletions src/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
import yaml from 'yaml'
import mapPorts from './v2-map-ports'

export interface IDockerComposeExecutableOptions {
executablePath: string
options?: string[] | (string | string[])[]
}

export interface IDockerComposeOptions {
cwd?: string
executablePath?: string
executable?: IDockerComposeExecutableOptions
config?: string | string[]
configAsString?: string
log?: boolean
Expand Down Expand Up @@ -183,8 +188,8 @@
* Executes docker compose command with common options
*/
export const execCompose = (
command,

Check warning on line 191 in src/v2.ts

View workflow job for this annotation

GitHub Actions / Lint

Argument 'command' should be typed
args,

Check warning on line 192 in src/v2.ts

View workflow job for this annotation

GitHub Actions / Lint

Argument 'args' should be typed
options: IDockerComposeOptions = {}
): Promise<IDockerComposeResult> =>
new Promise((resolve, reject): void => {
Expand All @@ -205,11 +210,14 @@

const cwd = options.cwd
const env = options.env || undefined
const executablePath = options.executablePath || 'docker'
const executable = options.executable || { executablePath: 'docker' }

const executableOptions = executable.options || []
const executableArgs = composeOptionsToArgs(executableOptions)

const childProc = childProcess.spawn(
executablePath,
['compose', ...composeArgs],
executable.executablePath,
[...executableArgs, 'compose', ...composeArgs],
{
cwd,
env
Expand Down
Loading