1- import * as micromatch from "micromatch" ;
21import { execSync } from "node:child_process" ;
32import { existsSync } from "node:fs" ;
43import { resolve } from "node:path" ;
4+ import * as micromatch from "micromatch" ;
55
66import { Options , Path } from "../types" ;
77
88export type History = Path [ ] ;
99
1010export default class GitHistory {
11- private options : Options ;
12-
13- public readonly history : History ;
14- public readonly files : Path [ ] ;
15-
16- public static build ( options : Options ) {
17- return new GitHistory ( options ) ;
18- }
11+ #options: Options ;
12+ history : History ;
13+ files : Path [ ] ;
1914
20- private constructor ( options : Options ) {
21- this . options = options ;
15+ constructor ( options : Options ) {
16+ this . # options = options ;
2217
23- this . history = this . buildHistory ( ) ;
24- this . files = this . listFiles ( ) ;
18+ this . history = this . # buildHistory( ) ;
19+ this . files = this . # listFiles( ) ;
2520 }
2621
27- private buildGitLogCommand ( ) : string {
22+ # buildGitLogCommand( ) : string {
2823 const isWindows = process . platform === "win32" ;
2924
3025 return [
3126 "git" ,
32- `-C ${ this . options . directory } ` ,
27+ `-C ${ this . # options. directory } ` ,
3328 `log` ,
3429 `--follow` ,
3530
3631 // Windows CMD handle quotes differently than linux, this is why we should put empty string as said in:
3732 // https://github.com/git-for-windows/git/issues/3131
3833 `--format=${ isWindows ? "" : "''" } ` ,
3934 `--name-only` ,
40- this . options . since ? `--since="${ this . options . since } "` : "" ,
41- this . options . until ? `--until="${ this . options . until } "` : "" ,
35+ this . # options. since ? `--since="${ this . # options. since } "` : "" ,
36+ this . # options. until ? `--until="${ this . # options. until } "` : "" ,
4237
4338 // Windows CMD handle quotes differently
4439 isWindows ? "*" : "'*'" ,
@@ -47,42 +42,42 @@ export default class GitHistory {
4742 . join ( " " ) ;
4843 }
4944
50- private buildHistory ( ) : Path [ ] {
51- const gitLogCommand = this . buildGitLogCommand ( ) ;
52- const stdout = this . executeGitLogCommand ( gitLogCommand ) ;
45+ # buildHistory( ) : Path [ ] {
46+ const gitLogCommand = this . # buildGitLogCommand( ) ;
47+ const stdout = this . # executeGitLogCommand( gitLogCommand ) ;
5348 return stdout
5449 . split ( "\n" )
5550 . filter ( ( line ) => {
5651 if ( line . trim ( ) . length === 0 ) {
5752 return false ;
5853 }
59- if ( ! this . pathStillExists ( line ) ) {
54+ if ( ! this . # pathStillExists( line ) ) {
6055 return false ;
6156 }
62- if ( ! this . filterMatches ( line ) ) {
57+ if ( ! this . # filterMatches( line ) ) {
6358 return false ;
6459 }
6560 return true ;
6661 } )
6762 . sort ( ) ;
6863 }
6964
70- private executeGitLogCommand ( gitLogCommand : string ) : string {
71- const maxBuffer = this . options . maxBuffer ?? 32_000_000 ;
65+ # executeGitLogCommand( gitLogCommand : string ) : string {
66+ const maxBuffer = this . # options. maxBuffer ?? 32_000_000 ;
7267 return execSync ( gitLogCommand , { encoding : "utf8" , maxBuffer } ) ;
7368 }
7469
75- private listFiles ( ) : string [ ] {
70+ # listFiles( ) : string [ ] {
7671 return [ ...new Set ( this . history ) ] ;
7772 }
7873
79- private pathStillExists ( fileName : string ) {
80- return existsSync ( resolve ( this . options . directory , fileName ) ) ;
74+ # pathStillExists( fileName : string ) {
75+ return existsSync ( resolve ( this . # options. directory , fileName ) ) ;
8176 }
8277
83- private filterMatches ( file : string ) {
84- if ( this . options . filter && this . options . filter . length ) {
85- return this . options . filter . every ( ( f ) => micromatch . isMatch ( file , f ) ) ;
78+ # filterMatches( file : string ) {
79+ if ( this . # options. filter && this . # options. filter . length ) {
80+ return this . # options. filter . every ( ( f ) => micromatch . isMatch ( file , f ) ) ;
8681 }
8782 return true ;
8883 }
0 commit comments