11import * as fs from 'fs' ;
22import * as path from 'path' ;
3- import * as child_process from 'child_process' ;
43
54import { scip } from './scip' ;
65import { diffSnapshot , formatSnapshot , writeSnapshot } from './lib' ;
@@ -24,39 +23,23 @@ function indexAction(options: IndexOptions): void {
2423 const projectRoot = workspaceRoot ;
2524 process . chdir ( workspaceRoot ) ;
2625
27- // TODO: use setup.py / poetry to determine better projectName
28- const projectName = options . projectName ;
29-
30- // TODO: Use setup.py / poetry to determine better projectVersion
31- // for now, the current hash works OK
32- let projectVersion = options . projectVersion ;
33- if ( ! projectVersion || projectVersion === '' ) {
34- // Default to current git hash
35- try {
36- projectVersion = child_process . execSync ( 'git rev-parse HEAD' ) . toString ( ) . trim ( ) ;
37- } catch ( e ) {
38- projectVersion = '' ;
39- }
40- }
41-
4226 const outputFile = path . join ( projectRoot , options . output ) ;
4327 const output = fs . openSync ( outputFile , 'w' ) ;
4428
45- sendStatus ( `Indexing ${ projectRoot } with version ${ projectVersion } ` ) ;
46-
4729 try {
4830 let indexer = new Indexer ( {
4931 ...options ,
5032 workspaceRoot,
5133 projectRoot,
52- projectName,
53- projectVersion,
5434 environment,
35+ infer : { projectVersionFromCommit : true } ,
5536 writeIndex : ( partialIndex : scip . Index ) : void => {
5637 fs . writeSync ( output , partialIndex . serializeBinary ( ) ) ;
5738 } ,
5839 } ) ;
5940
41+ sendStatus ( `Indexing ${ projectRoot } with version ${ indexer . scipConfig . projectVersion } ` ) ;
42+
6043 indexer . index ( ) ;
6144 } catch ( e ) {
6245 console . warn (
@@ -95,8 +78,6 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
9578 }
9679
9780 console . log ( '... Snapshotting ... ' ) ;
98- const projectName = options . projectName ;
99- const projectVersion = options . projectVersion ;
10081 const environment = options . environment ? path . resolve ( options . environment ) : undefined ;
10182
10283 const snapshotOnly = options . only ;
@@ -127,9 +108,8 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
127108 ...options ,
128109 workspaceRoot : projectRoot ,
129110 projectRoot,
130- projectName,
131- projectVersion,
132111 environment,
112+ infer : { projectVersionFromCommit : false } ,
133113 writeIndex : ( partialIndex : any ) : void => {
134114 fs . writeSync ( output , partialIndex . serializeBinary ( ) ) ;
135115 } ,
0 commit comments