import { IService } from '../interfaces/interface.service' ; import Logger from '../tools/env.logger' ; import * as os from 'os' ; import * as path from 'path' ; import * as fs from 'fs' ; const CPatches = [ ( logger ) : Promise < void > => { return new Promise ( ( resolve ) => { const oldHome = path . resolve ( os . homedir ( ) , '.logviewer' ) ; const newHome = path . resolve ( os . homedir ( ) , '.chipmunk' ) ; if ( ! fs . existsSync ( oldHome ) || fs . existsSync ( newHome ) ) { return resolve ( ) ; } fs . rename ( oldHome , newHome , ( err ) => { if ( err ) { logger . error ( `Fail to rename "${ oldHome }" into "${ newHome }"` ) ; } resolve ( ) ; } ) ; } ) ; } , ] ; class description class ServicePatchesBefore implements IService { private _logger : Logger = new Logger ( 'ServicePatchesBefore' ) ; returns public init ( ) { return new Promise ( ( resolve , reject ) => { Promise . all ( CPatches . map ( ( patch ) => { return patch ( this . _logger ) ; } ) ) . catch ( ( err ) => { this . _logger . error ( `Error during apply patches: ${ err . message }` ) ; } ) . finally ( ( ) => { resolve ( ) ; } ) ; } ) ; } public destroy ( ) { return new Promise ( ( resolve ) => { resolve ( ) ; } ) ; } public getName ( ) { return 'ServicePatchesBefore' ; } } export default ( new ServicePatchesBefore ( ) ) ;