import { executeAppBuilder } from "builder-util" import { SpawnOptions } from "child_process" export function executeAppBuilderAsJson(args: Array): Promise { return executeAppBuilder(args).then(rawResult => { if (rawResult === "") { return Object.create(null) as T } try { return JSON.parse(rawResult) as T } catch (e: any) { throw new Error(`Cannot parse result: ${e.message}: "${rawResult}"`) } }) } export function executeAppBuilderAndWriteJson(args: Array, data: any, extraOptions: SpawnOptions = {}): Promise { return executeAppBuilder( args, childProcess => { childProcess.stdin!.end(JSON.stringify(data)) }, { ...extraOptions, stdio: ["pipe", "pipe", process.stdout], } ) } export function objectToArgs(to: Array, argNameToValue: Record): void { for (const name of Object.keys(argNameToValue)) { const value = argNameToValue[name] if (value != null) { to.push(`--${name}`, value) } } }