@@ -38,6 +38,7 @@ static class Verbs
3838 public const string Install = "install" ;
3939 public const string New = "new" ;
4040 public const string ClearCache = "clear-cache" ;
41+ public const string InitVSCode = "init-vscode" ;
4142 }
4243
4344 [ STAThread ]
@@ -57,7 +58,8 @@ static void Main(string[] args)
5758 {
5859 case Verbs . Install : Install ( ) ; break ;
5960 case Verbs . New : CreateNew ( args . Length > 1 ? args [ 1 ] : null ) ; break ;
60- case Verbs . ClearCache : ClearCache ( ) ; break ;
61+ case Verbs . ClearCache : ClearCache ( ) ; break ;
62+ case Verbs . InitVSCode : InitVSCode ( ) ; break ;
6163 default : RunScript ( args ) ; break ;
6264 }
6365 }
@@ -251,6 +253,13 @@ static IEnumerable<string> LoadPackages(string scriptPath, out InteractiveAssemb
251253
252254 static void RunScript ( string [ ] args )
253255 {
256+ if ( ! File . Exists ( args [ 0 ] ) )
257+ {
258+ WriteLine ( $ "Script file '{ args [ 0 ] } ' does not exist.", ConsoleColor . Red ) ;
259+ System . Threading . Thread . Sleep ( 5000 ) ;
260+ return ;
261+ }
262+
254263 var scriptPath = Path . GetFullPath ( args [ 0 ] ) ;
255264 var runtimeExt = Path . GetExtension ( Path . GetFileNameWithoutExtension ( scriptPath ) ) ;
256265 if ( ! string . IsNullOrEmpty ( runtimeExt ) )
@@ -390,6 +399,40 @@ static void ClearCache()
390399 WriteLine ( "Cache cleared" , ConsoleColor . Green ) ;
391400 }
392401
402+ static void InitVSCode ( )
403+ {
404+ const string VSCodeDir = ".vscode" ;
405+ const string Filter = ".Templates.vscode." ;
406+
407+ var templates = typeof ( Program ) . Assembly . GetManifestResourceNames ( )
408+ . Select ( x => ( i : x . IndexOf ( Filter ) , s : x ) )
409+ . Where ( x => x . i > - 1 )
410+ . Select ( x => ( name : x . s , File : Path . Combine ( VSCodeDir , x . s . Substring ( x . i + Filter . Length ) ) ) ) ;
411+
412+ var dir = new DirectoryInfo ( VSCodeDir ) ;
413+ if ( ! dir . Exists )
414+ {
415+ dir . Create ( ) ;
416+ // dir.Attributes |= FileAttributes.Hidden;
417+ }
418+
419+ foreach ( var template in templates )
420+ {
421+ if ( File . Exists ( template . File ) )
422+ {
423+ WriteLine ( $ "File '{ template . File } ' already exists.", ConsoleColor . Yellow ) ;
424+ continue ;
425+ }
426+
427+ using ( var stream = typeof ( Program ) . Assembly . GetManifestResourceStream ( template . name ) )
428+ using ( var file = File . OpenWrite ( template . File ) )
429+ {
430+ WriteLine ( $ "Creating file '{ template . File } '...", ConsoleColor . Green ) ;
431+ stream . CopyTo ( file ) ;
432+ }
433+ }
434+ }
435+
393436 static void WriteLine ( string line , ConsoleColor color = ( ConsoleColor ) ( - 1 ) )
394437 {
395438 if ( ( int ) color > - 1 )
0 commit comments