format import os from 'os' ; import { FlipperServerImpl , getGatekeepers , loadLauncherSettings , loadProcessConfig , loadSettings , getEnvironmentInfo , } from 'flipper-server-core' ; import { parseEnvironmentVariables , isTest , Logger , setLoggerInstance , } from 'flipper-common' ; import path from 'path' ; import fs from 'fs' ; export async function startFlipperServer ( rootDir , staticPath ) { if ( os . platform ( ) === 'darwin' ) { electronRequire ( 'mac-ca' ) ; } const execPath = process . execPath ; const appPath = rootDir ; const isProduction = process . env . NODE_ENV !== 'development' && process . env . NODE_ENV !== 'test' ; const env = process . env ; let desktopPath = path . resolve ( os . homedir ( ) , 'Desktop' ) ; if ( ! fs . existsSync ( desktopPath ) ) { console . warn ( 'Failed to find desktop path, falling back to homedir' ) ; desktopPath = os . homedir ( ) ; } const logger = createLogger ( ) ; setLoggerInstance ( logger ) ; let keytar = undefined ; try { if ( ! isTest ( ) ) { keytar = electronRequire ( path . join ( staticPath , 'native-modules' , `keytar-${ process . platform }.node` ) ) ; } } catch ( e ) { console . error ( 'Failed to load keytar:' , e ) ; } const environmentInfo = await getEnvironmentInfo ( appPath , isProduction ) ; return new FlipperServerImpl ( { environmentInfo , env : parseEnvironmentVariables ( process . env ) , gatekeepers : getGatekeepers ( environmentInfo . os . unixname ) , paths : { appPath , homePath : os . homedir ( ) , execPath , staticPath : staticPath , tempPath : os . tmpdir ( ) , desktopPath : desktopPath , } , launcherSettings : await loadLauncherSettings ( ) , processConfig : loadProcessConfig ( env ) , settings : await loadSettings ( ) , validWebSocketOrigins : [ 'localhost:' , 'http://localhost:' ] , } , logger , keytar ) ; } function createLogger ( ) { return { track ( ... _args ) { } , trackTimeSince ( ... _args ) { } , debug ( ... _args ) { } , error ( ... args ) { console . error ( ... args ) ; console . warn ( '(skipped error reporting)' ) ; } , warn ( ... args ) { console . warn ( ... args ) ; console . warn ( '(skipped error reporting)' ) ; } , info ( ... _args ) { } , } ; }