@@ -5,8 +5,7 @@ import OptionsService from './services/options';
5
5
import LoggerService from './services/logger' ;
6
6
import ApiService from './services/api' ;
7
7
import * as pipeline from './pipeline' ;
8
- import { AppError } from './errors' ;
9
- import { Logger } from 'winston' ;
8
+ import { AppError , errorLog } from './errors' ;
10
9
import { getCacheFileName } from './helpers/misc' ;
11
10
import DependentsService from './services/dependents' ;
12
11
@@ -23,7 +22,6 @@ export class ServiceDiscovery {
23
22
private configurationService : ConfigurationService ;
24
23
private apiService : ApiService ;
25
24
private hasBeenSetUp = false ;
26
- private logger : Logger ;
27
25
private optionalSteps = [ 'getConfig' , 'getChangelog' , 'getDependents' ] ;
28
26
29
27
// eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -46,34 +44,36 @@ export class ServiceDiscovery {
46
44
* @param options Options to define the service discovery behaviour.
47
45
*/
48
46
async setup ( options : Options ) : Promise < void > {
49
- this . logger = this . loggerService . registerLogger (
50
- options . verbose ? 'debug' : 'info' ,
51
- options . logFile ,
52
- ! options . loggingEnabled ,
53
- ) ;
47
+ this . loggerService . registerLogger ( options . verbose ? 'debug' : 'info' , options . logFile , ! options . loggingEnabled ) ;
54
48
55
49
this . optionsService = OptionsService . getInstance ( ) ;
56
50
this . configurationService = ConfigurationService . getInstance ( ) ;
57
51
this . apiService = ApiService . getInstance ( ) ;
58
52
this . dependentsService = DependentsService . getInstance ( ) ;
59
53
60
54
try {
55
+ this . loggerService . log ( 'info' , 'Running setup' , this . setup ) ;
56
+
61
57
this . optionsService . setOptions ( options ) ;
62
58
await this . configurationService . setup ( ) ;
63
59
64
60
if ( options . forceRun || this . configurationService . shouldInvalidate ( ) ) {
61
+ this . loggerService . log ( 'info' , 'Invalidating cache' , this . setup ) ;
62
+
65
63
await this . configurationService . deleteCachedComponents ( ) ;
66
64
this . configurationService . update ( 'lastInvalidation' , new Date ( ) ) ;
67
65
}
68
66
69
67
if ( ! this . configurationService . config . vfCoreVersion || options . forceRun ) {
68
+ this . loggerService . log ( 'info' , 'Retrieving vf-core version' , this . setup ) ;
69
+
70
70
const vfCoreVersion = await this . apiService . getVfCoreLatestReleaseVersion ( ) ;
71
71
this . configurationService . update ( 'vfCoreVersion' , vfCoreVersion ) ;
72
72
}
73
73
74
74
this . hasBeenSetUp = true ;
75
75
} catch ( error ) {
76
- this . logger . error ( error . message ) ;
76
+ this . loggerService . log ( ' error' , errorLog ( error ) , this . setup ) ;
77
77
throw error ;
78
78
}
79
79
}
@@ -83,20 +83,21 @@ export class ServiceDiscovery {
83
83
* @param reportProgress Whether to report progress in the cli.
84
84
*/
85
85
async run ( reportProgress = false ) : Promise < PipelineItem [ ] > {
86
- if ( ! this . hasBeenSetUp ) {
87
- throw new AppError ( 'The ServiceDiscovery instance has not been set up.' ) ;
88
- }
89
-
90
86
try {
91
- this . logger . debug ( 'Running service discovery' ) ;
87
+ this . loggerService . log ( 'info' , 'Running service discovery' , this . run ) ;
88
+
89
+ if ( ! this . hasBeenSetUp ) {
90
+ throw new AppError ( 'The ServiceDiscovery instance has not been set up.' ) ;
91
+ }
92
92
93
93
this . hasBeenSetUp = false ;
94
94
95
- const rootDirectory = process . cwd ( ) ;
96
95
const options = this . optionsService . getOptions ( ) ;
97
- const disabledSteps : string [ ] = options . disabled . filter ( ( value ) => this . optionalSteps . includes ( value ) ) ;
98
96
const cache = await this . configurationService . getCache ( ) ;
97
+
99
98
const projectType = ( < any > ProjectType ) [ options . dependentsProjectType ] ;
99
+ const rootDirectory = process . cwd ( ) ;
100
+
100
101
const potentialDependents = await this . dependentsService . getPotentialDependents (
101
102
rootDirectory ,
102
103
projectType ,
@@ -112,6 +113,7 @@ export class ServiceDiscovery {
112
113
113
114
const components = await pipeline . getComponents ( context ) ;
114
115
116
+ const disabledSteps : string [ ] = options . disabled . filter ( ( value ) => this . optionalSteps . includes ( value ) ) ;
115
117
const pipelineItems = await pipeline . Pipeline . getInstance ( )
116
118
. addStep ( { fn : pipeline . getExactVersion , enabled : true } )
117
119
. addStep ( { fn : pipeline . getPackageJson , enabled : true } )
@@ -125,7 +127,7 @@ export class ServiceDiscovery {
125
127
return pipelineItems ;
126
128
} catch ( error ) {
127
129
this . hasBeenSetUp = false ;
128
- this . logger . error ( error . message ) ;
130
+ this . loggerService . log ( ' error' , errorLog ( error ) , this . run ) ;
129
131
130
132
if ( error . context ) {
131
133
return error . context ;
0 commit comments