/** * @module operations */ import { EventEmitter } from 'events'; import type { Operation } from './commands'; export interface OperationExecutionEvent extends EventEmitter { stdout?: EventEmitter; stderr?: EventEmitter; } /** * @summary Execute a set of operations over an image * @function * @public * * @description * This function returns an `EventEmitter` object that emits the following events: * * - `state (Object state)`: When an operation is going to be executed. The state object contains the `operation` and the progress `percentage` (0-100). * - `stdout (String data)`: When an operation prints to stdout. * - `stderr (String data)`: When an operation prints to stderr. * - `burn (String state)`: When the `burn` operation emits progress state. * - `error (Error error)`: When an error happens. * - `end`: When all the operations are completed successfully. * * @param {String} image - path to image * @param {Object[]} operations - array of operations * @param {Object} options - configuration options * * @returns {EventEmitter} * * @example * const execution = operations.execute( * 'foo/bar.img', * [ * { * command: 'copy', * from: { * partition: { * primary: 1 * }, * path: '/bitstreams/parallella_e16_headless_gpiose_7010.bit.bin' * }, * to: { * partition: { * primary: 1 * }, * path: '/parallella.bit.bin' * }, * when: { * coprocessorCore: '16', * processorType: 'Z7010' * } * }, * { * command: 'copy', * from: { * partition: { * primary: 1 * }, * path: '/bistreams/parallella_e16_headless_gpiose_7020.bit.bin' * }, * to: { * partition: { * primary: 1 * }, * path: '/parallella.bit.bin' * }, * when: { * coprocessorCore: '16', * processorType: 'Z7020' * } * } * ], * { * coprocessorCore: '16', * processorType: 'Z7010' * } * ); * * execution.on('stdout', process.stdout.write); * execution.on('stderr', process.stderr.write); * * execution.on('state', function(state) { * console.log(state.operation.command); * console.log(state.percentage); * }); * * execution.on('error', function(error) { * throw error; * }); * * execution.on('end', () => console.log('Finished all operations')); */ export declare const execute: (image: string, operations: Operation[], options?: { os?: string; }) => EventEmitter;