@@ -30,7 +30,7 @@ function indexAction(options: IndexOptions): void {
30
30
...options ,
31
31
projectRoot,
32
32
environment,
33
- infer : { projectVersionFromCommit : true } ,
33
+ infer : options . infer ?? { projectVersionFromCommit : true } ,
34
34
writeIndex : ( partialIndex : scip . Index ) : void => {
35
35
fs . writeSync ( output , partialIndex . serializeBinary ( ) ) ;
36
36
} ,
@@ -54,55 +54,37 @@ function indexAction(options: IndexOptions): void {
54
54
}
55
55
56
56
function snapshotAction ( snapshotRoot : string , options : SnapshotOptions ) : void {
57
- setQuiet ( options . quiet ) ;
58
- if ( options . showProgressRateLimit !== undefined ) {
59
- setShowProgressRateLimit ( options . showProgressRateLimit ) ;
60
- }
61
-
62
- console . log ( '... Snapshotting ... ' ) ;
63
- const environment = options . environment ? path . resolve ( options . environment ) : undefined ;
64
-
65
- const snapshotOnly = options . only ;
66
-
57
+ const subdir : string = options . only ;
67
58
const inputDirectory = path . resolve ( join ( snapshotRoot , 'input' ) ) ;
68
59
const outputDirectory = path . resolve ( join ( snapshotRoot , 'output' ) ) ;
69
60
70
- // Either read all the directories or just the one passed in by name
71
61
let snapshotDirectories = fs . readdirSync ( inputDirectory ) ;
72
- if ( snapshotOnly ) {
73
- snapshotDirectories = [ snapshotOnly ] ;
62
+ if ( subdir ) {
63
+ console . assert ( snapshotDirectories . find ( ( val ) => val === subdir ) !== undefined ) ;
64
+ snapshotDirectories = [ subdir ] ;
74
65
}
75
66
76
67
for ( const snapshotDir of snapshotDirectories ) {
77
68
let projectRoot = join ( inputDirectory , snapshotDir ) ;
78
- if ( ! fs . lstatSync ( projectRoot ) . isDirectory ( ) ) {
79
- continue ;
80
- }
81
-
82
- projectRoot = path . resolve ( projectRoot ) ;
83
- const originalWorkdir = process . cwd ( ) ;
84
- process . chdir ( projectRoot ) ;
85
-
86
- const scipBinaryFile = path . join ( projectRoot , options . output ) ;
87
- const output = fs . openSync ( scipBinaryFile , 'w' ) ;
88
-
89
- if ( options . index ) {
90
- let indexer = new Indexer ( {
91
- ...options ,
92
- projectRoot,
93
- environment,
94
- infer : { projectVersionFromCommit : false } ,
95
- writeIndex : ( partialIndex : any ) : void => {
96
- fs . writeSync ( output , partialIndex . serializeBinary ( ) ) ;
97
- } ,
98
- } ) ;
99
- indexer . index ( ) ;
100
- fs . close ( output ) ;
101
- }
102
-
103
- const contents = fs . readFileSync ( scipBinaryFile ) ;
104
- const scipIndex = scip . Index . deserializeBinary ( contents ) ;
69
+ console . assert ( fs . lstatSync ( projectRoot ) . isDirectory ( ) ) ;
70
+ console . log ( `Output path = ${ options . output } ` ) ;
71
+
72
+ indexAction ( {
73
+ projectName : options . projectName ,
74
+ projectVersion : options . projectVersion ,
75
+ projectNamespace : options . projectNamespace ,
76
+ environment : options . environment ? path . resolve ( options . environment ) : undefined ,
77
+ dev : options . dev ,
78
+ output : options . output ,
79
+ cwd : projectRoot ,
80
+ targetOnly : options . targetOnly ,
81
+ infer : { projectVersionFromCommit : false } ,
82
+ quiet : options . quiet ,
83
+ showProgressRateLimit : undefined ,
84
+ } ) ;
105
85
86
+ const scipIndexPath = path . join ( projectRoot , options . output ) ;
87
+ const scipIndex = scip . Index . deserializeBinary ( fs . readFileSync ( scipIndexPath ) ) ;
106
88
for ( const doc of scipIndex . documents ) {
107
89
if ( doc . relative_path . startsWith ( '..' ) ) {
108
90
continue ;
@@ -120,8 +102,6 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
120
102
writeSnapshot ( outputPath , obtained ) ;
121
103
}
122
104
}
123
-
124
- process . chdir ( originalWorkdir ) ;
125
105
}
126
106
}
127
107
0 commit comments