| // Copyright 2024 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import { ChildProcessWithoutNullStreams, spawn } from 'child_process'; |
| import { DataStreamProcess } from './process'; |
| |
| export class Fx { |
| constructor(public fuchsiaDir: string | undefined) { |
| } |
| |
| public runStreaming(args: string[]): ChildProcessWithoutNullStreams | undefined { |
| if (!this.fuchsiaDir) { |
| return; |
| } |
| let env = { ...process.env }; |
| env['PATH'] = `${this.fuchsiaDir}/.jiri_root/bin:${env.PATH}`; |
| const options = { detached: true, cwd: this.fuchsiaDir, env }; |
| return spawn('fx', args, options); |
| } |
| |
| public runAsync( |
| args: string[], |
| onData: (data: Buffer) => void, |
| onError: (data: Buffer) => void): DataStreamProcess | undefined { |
| const process = this.runStreaming(args); |
| if (!process) { |
| return; |
| } |
| return new DataStreamProcess(process, onData, onError); |
| } |
| } |