1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Text ;
4
3
using System . Linq ;
5
4
using System . IO ;
6
5
using System . Net ;
7
6
using System . Diagnostics ;
8
7
using System . Runtime . InteropServices ;
8
+ using System . Threading . Tasks ;
9
9
using Newtonsoft . Json . Linq ;
10
10
11
- using OneOS . Common ;
12
-
13
11
namespace OneOS . Runtime
14
12
{
15
13
public class Configuration
@@ -21,7 +19,7 @@ public class Configuration
21
19
static string OneOSPath = Path . Combine ( HomePath , ".oneos" ) ;
22
20
public static string DefaultOneOSPath { get => OneOSPath ; }
23
21
24
- static Dictionary < string , string > LanguageMap = new Dictionary < string , string > ( )
22
+ public static Dictionary < string , string > LanguageMap = new Dictionary < string , string > ( )
25
23
{
26
24
{ "csharp" , "dotnet" } ,
27
25
{ "fsharp" , "dotnet" } ,
@@ -110,6 +108,57 @@ public static void CreateOrUpdateConfig(string mountPath = null)
110
108
SaveConfig ( configPath , json ) ;
111
109
}
112
110
111
+ private static void InstallNodeJSDependencies ( string tempDataPath , string dependencies )
112
+ {
113
+ var tcs = new TaskCompletionSource < object > ( ) ;
114
+
115
+ Console . WriteLine ( $ "Installing oneos.js NPM Dependencies") ;
116
+
117
+ var startInfo = new ProcessStartInfo ( ) ;
118
+ startInfo . UseShellExecute = false ;
119
+ startInfo . WorkingDirectory = tempDataPath ;
120
+ startInfo . RedirectStandardInput = true ;
121
+ startInfo . RedirectStandardOutput = true ;
122
+ startInfo . RedirectStandardError = true ;
123
+
124
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
125
+ {
126
+ startInfo . FileName = "cmd" ;
127
+ startInfo . Arguments = "/c npm install " + dependencies ;
128
+ }
129
+ else
130
+ {
131
+ startInfo . FileName = "npm" ;
132
+ startInfo . Arguments = "install " + dependencies ;
133
+ }
134
+
135
+ var npm = new Process ( ) ;
136
+ npm . StartInfo = startInfo ;
137
+ npm . EnableRaisingEvents = true ;
138
+ npm . Exited += ( sender , evt ) =>
139
+ {
140
+ string output ;
141
+ if ( npm . ExitCode != 0 )
142
+ {
143
+ output = npm . StandardError . ReadToEnd ( ) ;
144
+ }
145
+ else
146
+ {
147
+ output = npm . StandardOutput . ReadToEnd ( ) ;
148
+ }
149
+
150
+ tcs . SetResult ( output ) ;
151
+ } ;
152
+
153
+ npm . Start ( ) ;
154
+
155
+ var result = tcs . Task . Result ;
156
+
157
+ Console . WriteLine ( result ) ;
158
+
159
+ return ;
160
+ }
161
+
113
162
// ensures that the OneOS directory exists
114
163
static void CheckOneOSDirectory ( string mountPath )
115
164
{
@@ -155,6 +204,9 @@ static void CheckOneOSDirectory(string mountPath)
155
204
{
156
205
Console . WriteLine ( $ "{ npmPackageJson } file not found. Creating ...") ;
157
206
File . WriteAllText ( npmPackageJson , "{}" ) ;
207
+
208
+ // install oneos.js dependencies
209
+
158
210
}
159
211
160
212
// check node_modules (needed for JavaScript agents)
@@ -461,7 +513,7 @@ static void CreateOrUpdateField(JObject json, string key, string fieldName, stri
461
513
}
462
514
}
463
515
464
- static string LookupVM ( string binaryName )
516
+ public static string LookupVM ( string binaryName )
465
517
{
466
518
Process cmd = new Process ( ) ;
467
519
@@ -480,14 +532,16 @@ static string LookupVM(string binaryName)
480
532
481
533
cmd . WaitForExit ( ) ;
482
534
483
- string result = cmd . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
535
+ string [ ] result = cmd . StandardOutput . ReadToEnd ( ) . Trim ( ) . Split ( '\n ' ) ;
536
+
537
+ if ( result [ 0 ] . Contains ( "Could not find" ) ) throw new NullReferenceException ( ) ;
484
538
485
- if ( result . Contains ( "Could not find" ) ) throw new NullReferenceException ( ) ;
539
+ if ( ! File . Exists ( result [ 0 ] ) ) throw new NullReferenceException ( ) ;
486
540
487
- return result ;
541
+ return result [ 0 ] ;
488
542
}
489
543
490
- static ( int , int ) LookupCores ( )
544
+ public static ( int , int ) LookupCores ( )
491
545
{
492
546
Process cmd = new Process ( ) ;
493
547
cmd . StartInfo . RedirectStandardOutput = true ;
0 commit comments