kibana/packages/kbn-relocate/utils.exec.ts
Gerard Soldevila 0b9179acbd
Sustainable Kibana Architecture: Add scripts/relocate CLI (beta) (#203803)
## Summary

Adds the `node scripts/relocate` functionality, that helps moving
modules to their intended locations, according to the _Sustainable
Kibana Architecture_.

Please refer to the README.md for further details and usage.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2024-12-11 17:10:37 +01:00

35 lines
1.1 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import util from 'util';
import { exec } from 'child_process';
export const execAsync = util.promisify(exec);
export const safeExec = async (command: string, critical = true, log = true) => {
try {
if (log) {
// eslint-disable-next-line no-console
console.log(' >', command);
}
const result = await execAsync(command, { maxBuffer: 1024 * 1024 * 128 });
return result;
} catch (err) {
const message = `Error executing ${command}: ${err}`;
if (critical) {
throw err;
}
return { stdout: '', stderr: message };
}
};
export const quietExec = async (command: string) => {
return await safeExec(command, false, false);
};