Add exec Node API to FlipperLib
Summary: Changelog: Allow flipper plugins to run "exec" Node API on Flipper server. Reviewed By: mweststrate Differential Revision: D32881149 fbshipit-source-id: 46486a47ee9824ca68897c19fd86b4afc7f8bf1d
This commit is contained in:
committed by
Facebook GitHub Bot
parent
8ca2c59499
commit
e458ae76f9
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
import EventEmitter from 'events';
|
||||
import {Logger} from 'flipper-common';
|
||||
import ServerController from './comms/ServerController';
|
||||
import {CertificateExchangeMedium} from './utils/CertificateProvider';
|
||||
import {AndroidDeviceManager} from './devices/android/androidDeviceManager';
|
||||
@@ -25,6 +24,7 @@ import {
|
||||
FlipperServer,
|
||||
UninitializedClient,
|
||||
FlipperServerConfig,
|
||||
Logger,
|
||||
} from 'flipper-common';
|
||||
import {ServerDevice} from './devices/ServerDevice';
|
||||
import {Base64} from 'js-base64';
|
||||
@@ -43,6 +43,7 @@ import {
|
||||
internGraphGETAPIRequest,
|
||||
internGraphPOSTAPIRequest,
|
||||
} from './fb-stubs/internRequests';
|
||||
import {commandNodeApiExec} from './commands/NodeApiExec';
|
||||
|
||||
export const SERVICE_FLIPPER = 'flipper.oAuthToken';
|
||||
|
||||
@@ -213,6 +214,7 @@ export class FlipperServerImpl implements FlipperServer {
|
||||
}
|
||||
|
||||
private commandHandler: FlipperServerCommands = {
|
||||
'node-api-exec': commandNodeApiExec,
|
||||
'get-config': async () => this.config,
|
||||
'get-changelog': getChangelog,
|
||||
'device-list': async () => {
|
||||
|
||||
39
desktop/flipper-server-core/src/commands/NodeApiExec.tsx
Normal file
39
desktop/flipper-server-core/src/commands/NodeApiExec.tsx
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {ExecError, FlipperServerCommands} from 'flipper-common';
|
||||
import {exec} from 'child_process';
|
||||
import assert from 'assert';
|
||||
|
||||
export const commandNodeApiExec: FlipperServerCommands['node-api-exec'] =
|
||||
async (command, options) =>
|
||||
new Promise((resolve, reject) =>
|
||||
exec(command, options, (error, stdout, stderr) => {
|
||||
assert(typeof stdout === 'string');
|
||||
assert(typeof stderr === 'string');
|
||||
if (error) {
|
||||
const wrappedError: ExecError = {
|
||||
message: error.message,
|
||||
stdout,
|
||||
stderr,
|
||||
cmd: error.cmd,
|
||||
killed: error.killed,
|
||||
code: error.code,
|
||||
stack: error.stack,
|
||||
};
|
||||
reject(wrappedError);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
stdout,
|
||||
stderr,
|
||||
});
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user