@@ -6,13 +6,23 @@ const executablePath = "./dist/git-stacked-rebase.js";
66fs . chmodSync ( executablePath , "755" ) ;
77execSyncP ( `ls -la ${ executablePath } ` ) ;
88
9- updateShebang ( executablePath ) ;
10- execSyncP ( `cat ${ executablePath } | head -n 2` ) ;
9+ modifyLines ( executablePath ) ;
1110
12- function updateShebang ( path ) {
11+ function modifyLines ( path ) {
1312 const file = fs . readFileSync ( path , { encoding : "utf-8" } ) ;
1413 const lines = file . split ( "\n" ) ;
1514
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 ) {
1626 const oldShebang = "#!/usr/bin/env ts-node-dev" ;
1727 const newShebang = "#!/usr/bin/env node" ;
1828
@@ -22,8 +32,23 @@ function updateShebang(path) {
2232 lines . splice ( 0 , 0 , newShebang ) ;
2333 }
2434
25- const newFile = lines . join ( "\n" ) ;
26- fs . writeFileSync ( path , newFile ) ;
35+ return ( ) => execSyncP ( `cat ${ executablePath } | head -n 2` ) ;
36+ }
2737
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"` ) ;
2954}
0 commit comments