1
1
import * as path from "path" ;
2
2
import * as util from "util" ;
3
3
import { annotate , getValueFromNestedObject } from "../helpers" ;
4
+ import { AnalyticsEventLabelDelimiter } from "../../constants" ;
4
5
5
6
class Hook implements IHook {
6
7
constructor ( public name : string ,
@@ -22,7 +23,8 @@ export class HooksService implements IHooksService {
22
23
private $staticConfig : Config . IStaticConfig ,
23
24
private $injector : IInjector ,
24
25
private $projectHelper : IProjectHelper ,
25
- private $options : IOptions ) { }
26
+ private $options : IOptions ,
27
+ private $performanceService : IPerformanceService ) { }
26
28
27
29
public get hookArgsName ( ) : string {
28
30
return "hookArgs" ;
@@ -93,9 +95,11 @@ export class HooksService implements IHooksService {
93
95
hookArguments = hookArguments || { } ;
94
96
const results : any [ ] = [ ] ;
95
97
const hooks = this . getHooksByName ( directoryPath , hookName ) ;
98
+
96
99
for ( let i = 0 ; i < hooks . length ; ++ i ) {
97
100
const hook = hooks [ i ] ;
98
- this . $logger . info ( "Executing %s hook from %s" , hookName , hook . fullPath ) ;
101
+ const relativePath = path . relative ( directoryPath , hook . fullPath ) ;
102
+ const trackId = relativePath . replace ( new RegExp ( '\\' + path . sep , 'g' ) , AnalyticsEventLabelDelimiter ) ;
99
103
let command = this . getSheBangInterpreter ( hook ) ;
100
104
let inProc = false ;
101
105
if ( ! command ) {
@@ -106,6 +110,7 @@ export class HooksService implements IHooksService {
106
110
}
107
111
}
108
112
113
+ const startTime = this . $performanceService . now ( ) ;
109
114
if ( inProc ) {
110
115
this . $logger . trace ( "Executing %s hook at location %s in-process" , hookName , hook . fullPath ) ;
111
116
const hookEntryPoint = require ( hook . fullPath ) ;
@@ -155,7 +160,11 @@ export class HooksService implements IHooksService {
155
160
if ( output . exitCode !== 0 ) {
156
161
throw new Error ( output . stdout + output . stderr ) ;
157
162
}
163
+
164
+ this . $logger . trace ( "Finished executing %s hook at location %s with environment " , hookName , hook . fullPath , environment ) ;
158
165
}
166
+ const endTime = this . $performanceService . now ( ) ;
167
+ this . $performanceService . processExecutionData ( trackId , startTime , endTime , [ hookArguments ] ) ;
159
168
}
160
169
161
170
return results ;
0 commit comments