11import * as vscode from 'vscode' ;
22import * as path from 'path' ;
33import * as fs from 'fs' ;
4+ import * as bazelmodule from './bazelmodule' ;
5+ import * as projectparser from './bazelprojectparser' ;
46
5- export class BazelStructure {
7+
8+ export class BazelProject {
69 sourceWorkspace : string ;
710 sourceFolder : string ;
811 targetFolder : string ;
@@ -16,17 +19,29 @@ export class BazelStructure {
1619
1720 openProject ( modules : string [ ] ) {
1821 this . buildBazelProject ( modules ) ;
19- this . openFolder ( ) ;
22+ // this.makeTargetFolder();
23+ // this.buildSymlinks(modules);
24+ // this.openFolder(this.targetFolder);
25+ this . openFolder ( this . sourceFolder ) ;
2026 }
2127
22- lookupModules ( ) : string [ ] {
23- let modules : string [ ] = [ ] ;
28+ lookupModules ( ) : bazelmodule . BazelModule [ ] {
29+ const parser : projectparser . BazelProjectParser = new projectparser . BazelProjectParser ( ) ;
30+ parser . readBazelProject ( this . sourceFolder ) ;
31+ const selectedModules : string [ ] = parser . getModules ( ) ;
32+ let modules : bazelmodule . BazelModule [ ] = [ ] ;
2433 if ( fs . existsSync ( this . sourceFolder ) ) {
2534 const files : string [ ] = fs . readdirSync ( this . sourceFolder , { withFileTypes : true } ) . //
2635 filter ( file => ( ( ! file . name . startsWith ( '.' ) ) && file . isDirectory ( ) ) ) . //
2736 map ( file => file . name ) ;
2837 files . forEach ( file => {
29- modules . push ( file ) ;
38+ const selected = selectedModules . find ( ( name ) => name === file ) ;
39+ let exist : boolean = false ;
40+ if ( selected ) {
41+ exist = true ;
42+ }
43+ const module : bazelmodule . BazelModule = new bazelmodule . BazelModule ( file , exist ) ;
44+ modules . push ( module ) ;
3045 } ) ;
3146 }
3247 return modules ;
@@ -36,39 +51,38 @@ export class BazelStructure {
3651 const bazelprojectFile = path . join ( this . sourceFolder , '.bazelproject' ) ;
3752 if ( modules && modules . length > 0 ) {
3853 if ( fs . existsSync ( bazelprojectFile ) ) {
39- fs . truncateSync ( bazelprojectFile ) ;
54+ fs . renameSync ( bazelprojectFile , bazelprojectFile + '.' + Date . now ( ) ) ;
4055 }
4156 let fileContent = 'directories:\n' ;
42- modules . forEach ( ( moduleName ) => { fileContent = fileContent + ' ' + moduleName + '\n' } ) ;
57+ modules . forEach ( ( moduleName ) => { fileContent = fileContent + ' ' + moduleName + '\n' ; } ) ;
4358 fs . writeFileSync ( bazelprojectFile , fileContent ) ;
4459 } else if ( fs . existsSync ( bazelprojectFile ) ) {
4560 fs . unlinkSync ( bazelprojectFile ) ;
4661 }
4762 }
4863
49- private openFolder ( ) {
50- const uri : vscode . Uri = vscode . Uri . file ( this . sourceFolder ) ;
64+ private openFolder ( folder : string ) {
65+ const uri : vscode . Uri = vscode . Uri . file ( folder ) ;
5166 vscode . commands . executeCommand ( 'vscode.openFolder' , uri ) ;
5267 }
5368
5469 private makeTargetFolder ( ) {
5570 const targetPath = path . resolve ( this . targetFolder ) ;
5671 if ( ! fs . existsSync ( targetPath ) ) {
57- fs . vmkdirSync ( targetPath ) ;
72+ fs . mkdirSync ( targetPath ) ;
5873 }
5974 }
6075
61- private buildSymlinks ( ) {
62- const modules : string [ ] = this . lookupModules ( ) ;
76+ private buildSymlinks ( modules : string [ ] ) {
6377 if ( modules && modules . length > 0 ) {
6478 modules . forEach ( ( sourceModule ) => {
6579 const moduleName : string = path . basename ( sourceModule ) ;
6680 const targetModulePath = path . join ( this . targetFolder , moduleName ) ;
6781 const sourceModulePath = path . join ( this . sourceFolder , moduleName ) ;
6882 fs . symlinkSync ( sourceModulePath , targetModulePath ) ;
6983 } ) ;
70- const targetWorkspaceFile = path . join ( this . targetFolder , 'WORKSPACE' ) ;
71- fs . symlinkSync ( this . sourceWorkspace , targetWorkspaceFile ) ;
84+ // const targetWorkspaceFile = path.join(this.targetFolder, 'WORKSPACE');
85+ // fs.symlinkSync(this.sourceWorkspace, targetWorkspaceFile);
7286 }
7387 }
7488}
0 commit comments