@@ -6,13 +6,23 @@ const executablePath = "./dist/git-stacked-rebase.js";
6
6
fs . chmodSync ( executablePath , "755" ) ;
7
7
execSyncP ( `ls -la ${ executablePath } ` ) ;
8
8
9
- updateShebang ( executablePath ) ;
10
- execSyncP ( `cat ${ executablePath } | head -n 2` ) ;
9
+ modifyLines ( executablePath ) ;
11
10
12
- function updateShebang ( path ) {
11
+ function modifyLines ( path ) {
13
12
const file = fs . readFileSync ( path , { encoding : "utf-8" } ) ;
14
13
const lines = file . split ( "\n" ) ;
15
14
15
+ const afterUpdateShebang = updateShebang ( lines ) ;
16
+ const afterInjectRelativeBuildDatePrinter = injectRelativeBuildDatePrinter ( lines ) ;
17
+
18
+ const newFile = lines . join ( "\n" ) ;
19
+ fs . writeFileSync ( path , newFile ) ;
20
+
21
+ afterUpdateShebang ( ) ;
22
+ afterInjectRelativeBuildDatePrinter ( ) ;
23
+ }
24
+
25
+ function updateShebang ( lines ) {
16
26
const oldShebang = "#!/usr/bin/env ts-node-dev" ;
17
27
const newShebang = "#!/usr/bin/env node" ;
18
28
@@ -22,8 +32,23 @@ function updateShebang(path) {
22
32
lines . splice ( 0 , 0 , newShebang ) ;
23
33
}
24
34
25
- const newFile = lines . join ( "\n" ) ;
26
- fs . writeFileSync ( path , newFile ) ;
35
+ return ( ) => execSyncP ( `cat ${ executablePath } | head -n 2` ) ;
36
+ }
27
37
28
- return ;
38
+ function injectRelativeBuildDatePrinter ( lines ) {
39
+ const BUILD_DATE_REPLACEMENT_STR = "__BUILD_DATE_REPLACEMENT_STR__" ;
40
+ const targetLineIdx = lines . findIndex ( ( line ) => line . includes ( BUILD_DATE_REPLACEMENT_STR ) ) ;
41
+ const buildDate = new Date ( ) . getTime ( ) ;
42
+ const printRelativeDate =
43
+ "(" + //
44
+ "built " +
45
+ "${" +
46
+ `Math.round((new Date() - ${ buildDate } ) / 1000 / 60)` +
47
+ "}" +
48
+ " mins ago" +
49
+ ")" ;
50
+
51
+ lines [ targetLineIdx ] = lines [ targetLineIdx ] . replace ( BUILD_DATE_REPLACEMENT_STR , printRelativeDate ) ;
52
+
53
+ return ( ) => execSyncP ( `cat ${ executablePath } | grep " mins ago"` ) ;
29
54
}
0 commit comments