import _ from 'lodash' ; import { RawWorkspace } from './types' ; export const NEVER = new Promise < never > ( ( ) => { } ) ; export interface PortForwardingCommandLineArgs { type : 'LocalForward' | 'RemoteForward' ; source : string ; target : string ; flag : 'L' | 'R' ; value : string ; } export interface GroupWorkspaceProjectConfigsResult { configs : string [ ] ; forwards : PortForwardingCommandLineArgs [ ] ; } export function groupWorkspaceProjectConfigs ( { projects , } ) { let configs = _ . union ( ... projects . map ( project => ( project . ssh && project . ssh . configs ) || [ ] ) ) ; let nonForwardingConfigs = [ ] ; let forwards = [ ] ; for ( let config of configs ) { let groups = /^(LocalForward|RemoteForward)\s+((?:[^:]+:)?\d+)\s+([^:]+:\d+)\s*(?:$|#)/ . exec ( config ) ; if ( groups ) { let [ , type , source , target ] = groups ; forwards . push ( { type : type as 'LocalForward' | 'RemoteForward' , source , target , flag : type [ 0 ] as 'L' | 'R' , value : `${ source }:${ target }` , } ) ; } else { nonForwardingConfigs . push ( config ) ; } } return { configs : nonForwardingConfigs , forwards , } ; }