-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into matias-zk-toolbox-update
- Loading branch information
Showing
15 changed files
with
395 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { spawn as _spawn, ChildProcessWithoutNullStreams, type ProcessEnvOptions } from 'child_process'; | ||
|
||
// executes a command in background and returns a child process handle | ||
// by default pipes data to parent's stdio but this can be overridden | ||
export function background({ | ||
command, | ||
stdio = 'inherit', | ||
cwd, | ||
env | ||
}: { | ||
command: string; | ||
stdio: any; | ||
cwd?: ProcessEnvOptions['cwd']; | ||
env?: ProcessEnvOptions['env']; | ||
}): ChildProcessWithoutNullStreams { | ||
command = command.replace(/\n/g, ' '); | ||
console.log(`Running command in background: ${command}`); | ||
return _spawn(command, { stdio: stdio, shell: true, detached: true, cwd, env }); | ||
} | ||
|
||
export function runInBackground({ | ||
command, | ||
components, | ||
stdio, | ||
cwd, | ||
env | ||
}: { | ||
command: string; | ||
components?: string[]; | ||
stdio: any; | ||
cwd?: Parameters<typeof background>[0]['cwd']; | ||
env?: Parameters<typeof background>[0]['env']; | ||
}): ChildProcessWithoutNullStreams { | ||
if (components && components.length > 0) { | ||
command += ` --components=${components.join(',')}`; | ||
} | ||
|
||
return background({ | ||
command, | ||
stdio, | ||
cwd, | ||
env | ||
}); | ||
} | ||
|
||
export function runExternalNodeInBackground({ | ||
components, | ||
stdio, | ||
cwd, | ||
env, | ||
useZkInception | ||
}: { | ||
components?: string[]; | ||
stdio: any; | ||
cwd?: Parameters<typeof background>[0]['cwd']; | ||
env?: Parameters<typeof background>[0]['env']; | ||
useZkInception?: boolean; | ||
}): ChildProcessWithoutNullStreams { | ||
let command = ''; | ||
if (useZkInception) { | ||
command = 'zk_inception external-node run'; | ||
} else { | ||
command = 'zk external-node --'; | ||
|
||
const enableConsensus = process.env.ENABLE_CONSENSUS === 'true'; | ||
if (enableConsensus) { | ||
command += ' --enable-consensus'; | ||
} | ||
} | ||
return runInBackground({ command, components, stdio, cwd, env }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.