@@ -3,9 +3,12 @@ import * as path from 'path';
33import * as fs from 'fs' ;
44import * as bazelmodule from './bazelmodule' ;
55import * as projectparser from './bazelprojectparser' ;
6-
6+ import * as vscodeworkspace from './workspace' ;
77
88export class BazelProject {
9+ private readonly codeWorkspaceExt : string = '.code-workspace' ;
10+ private readonly codeWorkspaceFile : string = 'workspace' + this . codeWorkspaceExt ;
11+
912 sourceWorkspace : string ;
1013 sourceFolder : string ;
1114 targetFolder : string ;
@@ -17,12 +20,14 @@ export class BazelProject {
1720
1821 }
1922
20- openProject ( modules : string [ ] ) {
21- this . buildBazelProject ( modules ) ;
23+ openProject ( modules : bazelmodule . BazelModule [ ] ) {
2224 // this.makeTargetFolder();
25+ // this.buildBazelProject(modules, this.targetFolder);
2326 // this.buildSymlinks(modules);
2427 // this.openFolder(this.targetFolder);
25- this . openFolder ( this . sourceFolder ) ;
28+ this . buildBazelProject ( modules , this . sourceFolder ) ;
29+ this . buildCodeWorkspace ( modules , this . sourceFolder ) ;
30+ this . openFolder ( path . join ( this . sourceFolder , this . codeWorkspaceFile ) ) ;
2631 }
2732
2833 lookupModules ( ) : bazelmodule . BazelModule [ ] {
@@ -47,14 +52,27 @@ export class BazelProject {
4752 return modules ;
4853 }
4954
50- private buildBazelProject ( modules : string [ ] ) {
51- const bazelprojectFile = path . join ( this . sourceFolder , '.bazelproject' ) ;
55+ private buildCodeWorkspace ( modules : bazelmodule . BazelModule [ ] , folder : string ) {
56+ const codeWorkspaceFile : vscodeworkspace . VsCodeWorkspace = new vscodeworkspace . VsCodeWorkspace ( modules ) ;
57+ const vscodeWorkspace = path . join ( folder , this . codeWorkspaceFile ) ;
58+ const content : string = JSON . stringify ( codeWorkspaceFile , null , 2 ) ;
59+
60+ fs . writeFileSync ( vscodeWorkspace , content ) ;
61+ }
62+
63+ private buildBazelProject ( modules : bazelmodule . BazelModule [ ] , folder : string ) {
64+ const bazelprojectFile = path . join ( folder , '.bazelproject' ) ;
5265 if ( modules && modules . length > 0 ) {
5366 if ( fs . existsSync ( bazelprojectFile ) ) {
5467 fs . renameSync ( bazelprojectFile , bazelprojectFile + '.' + Date . now ( ) ) ;
5568 }
5669 let fileContent = 'directories:\n' ;
57- modules . forEach ( ( moduleName ) => { fileContent = fileContent + ' ' + moduleName + '\n' ; } ) ;
70+ modules . //
71+ filter ( ( module ) => true === module . selected ) . //
72+ forEach ( ( module ) => {
73+ const name : string = module . name ;
74+ fileContent = fileContent + ' ' + name + '\n' ;
75+ } ) ;
5876 fs . writeFileSync ( bazelprojectFile , fileContent ) ;
5977 } else if ( fs . existsSync ( bazelprojectFile ) ) {
6078 fs . unlinkSync ( bazelprojectFile ) ;
@@ -81,8 +99,8 @@ export class BazelProject {
8199 const sourceModulePath = path . join ( this . sourceFolder , moduleName ) ;
82100 fs . symlinkSync ( sourceModulePath , targetModulePath ) ;
83101 } ) ;
84- // const targetWorkspaceFile = path.join(this.targetFolder, 'WORKSPACE');
85- // fs.symlinkSync(this.sourceWorkspace, targetWorkspaceFile);
102+ const targetWorkspaceFile = path . join ( this . targetFolder , 'WORKSPACE' ) ;
103+ fs . symlinkSync ( this . sourceWorkspace , targetWorkspaceFile ) ;
86104 }
87105 }
88106}
0 commit comments