22/// <reference path="../types.d.ts"/>
33
44namespace ts . server . typingsInstaller {
5- export function log ( s : string ) {
6- require ( "fs" ) . appendFileSync ( "E:\\sources\\git\\installer.txt" , s + "\r\n" ) ;
7- }
85 const DefaultTsdSettings = JSON . stringify ( {
96 version : "v4" ,
107 repo : "DefinitelyTyped/DefinitelyTyped" ,
@@ -22,15 +19,13 @@ namespace ts.server.typingsInstaller {
2219 if ( ! this . isTsdInstalled ) {
2320 this . isTsdInstalled = this . installPackage ( "tsd" ) ;
2421 }
25- log ( `start ${ this . isTsdInstalled } ` ) ;
2622 }
2723
2824 install ( req : InstallTypingsRequest ) {
2925 if ( ! this . isTsdInstalled ) {
3026 return ;
3127 }
3228
33- log ( `install ${ JSON . stringify ( req ) } ` ) ;
3429 const discoverTypingsResult = JsTyping . discoverTypings (
3530 this . getInstallTypingHost ( ) ,
3631 req . fileNames ,
@@ -40,7 +35,6 @@ namespace ts.server.typingsInstaller {
4035 req . typingOptions ,
4136 req . compilerOptions ) ;
4237
43- log ( `install ${ JSON . stringify ( discoverTypingsResult ) } ` ) ;
4438 // respond with whatever cached typings we have now
4539 this . sendResponse ( this . createResponse ( req , discoverTypingsResult . cachedTypingPaths ) ) ;
4640 // start watching files
@@ -51,7 +45,6 @@ namespace ts.server.typingsInstaller {
5145
5246 private installTypings ( req : InstallTypingsRequest , currentlyCachedTypings : string [ ] , typingsToInstall : string [ ] ) {
5347 typingsToInstall = filter ( typingsToInstall , x => ! hasProperty ( this . missingTypings , x ) ) ;
54- log ( `install ${ JSON . stringify ( typingsToInstall ) } ` ) ;
5548 if ( typingsToInstall . length === 0 ) {
5649 return ;
5750 }
@@ -60,18 +53,28 @@ namespace ts.server.typingsInstaller {
6053 const host = this . getInstallTypingHost ( ) ;
6154 const tsdPath = combinePaths ( req . cachePath , "tsd.json" ) ;
6255 if ( ! host . fileExists ( tsdPath ) ) {
56+ this . ensureDirectoryExists ( req . cachePath , host ) ;
6357 host . writeFile ( tsdPath , DefaultTsdSettings ) ;
6458 }
6559
6660 this . runTsd ( req . cachePath , typingsToInstall , installedTypings => {
6761 // TODO: record new missing package names
6862 // TODO: watch project directory
6963 installedTypings = installedTypings . map ( x => getNormalizedAbsolutePath ( x , req . cachePath ) ) ;
70- log ( `include ${ JSON . stringify ( installedTypings ) } ` ) ;
7164 this . sendResponse ( this . createResponse ( req , currentlyCachedTypings . concat ( installedTypings ) ) ) ;
7265 } ) ;
7366 }
7467
68+ private ensureDirectoryExists ( directory : string , host : InstallTypingHost ) : void {
69+ const directoryName = getDirectoryPath ( directory ) ;
70+ if ( ! host . directoryExists ( directoryName ) ) {
71+ this . ensureDirectoryExists ( directoryName , host ) ;
72+ }
73+ if ( ! host . directoryExists ( directory ) ) {
74+ host . createDirectory ( directory ) ;
75+ }
76+ }
77+
7578 private watchFiles ( files : string [ ] ) {
7679 // TODO: start watching files
7780 }
0 commit comments