@@ -30,7 +30,7 @@ function indexAction(options: IndexOptions): void {
3030            ...options , 
3131            projectRoot, 
3232            environment, 
33-             infer : {  projectVersionFromCommit : true  } , 
33+             infer : options . infer   ??   {  projectVersionFromCommit : true  } , 
3434            writeIndex : ( partialIndex : scip . Index ) : void   =>  { 
3535                fs . writeSync ( output ,  partialIndex . serializeBinary ( ) ) ; 
3636            } , 
@@ -54,55 +54,37 @@ function indexAction(options: IndexOptions): void {
5454} 
5555
5656function  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 ; 
6758    const  inputDirectory  =  path . resolve ( join ( snapshotRoot ,  'input' ) ) ; 
6859    const  outputDirectory  =  path . resolve ( join ( snapshotRoot ,  'output' ) ) ; 
6960
70-     // Either read all the directories or just the one passed in by name 
7161    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 ] ; 
7465    } 
7566
7667    for  ( const  snapshotDir  of  snapshotDirectories )  { 
7768        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+         } ) ; 
10585
86+         const  scipIndexPath  =  path . join ( projectRoot ,  options . output ) ; 
87+         const  scipIndex  =  scip . Index . deserializeBinary ( fs . readFileSync ( scipIndexPath ) ) ; 
10688        for  ( const  doc  of  scipIndex . documents )  { 
10789            if  ( doc . relative_path . startsWith ( '..' ) )  { 
10890                continue ; 
@@ -120,8 +102,6 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
120102                writeSnapshot ( outputPath ,  obtained ) ; 
121103            } 
122104        } 
123- 
124-         process . chdir ( originalWorkdir ) ; 
125105    } 
126106} 
127107
0 commit comments