示例#1
0
    private async Task RunAsync(ILoggerFactory loggerFactory, CancellationToken token)
    {
        if (_args.CommonConfig.Debugging)
        {
            ProxyOptions options = _args.CommonConfig.ToProxyOptions();
            _ = Task.Run(() => DebugProxyHost.RunDebugProxyAsync(options, Array.Empty <string>(), loggerFactory, token), token)
                .ConfigureAwait(false);
        }

        Dictionary <string, string> envVars = new();

        if (_args.CommonConfig.HostProperties.EnvironmentVariables is not null)
        {
            foreach (KeyValuePair <string, string> kvp in _args.CommonConfig.HostProperties.EnvironmentVariables)
            {
                envVars[kvp.Key] = kvp.Value;
            }
        }

        foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
        {
            if (de.Key is not null && de.Value is not null)
            {
                envVars[(string)de.Key] = (string)de.Value;
            }
        }

        var runArgsJson = new RunArgumentsJson(applicationArguments: _args.AppArgs,
                                               runtimeArguments: _args.CommonConfig.RuntimeArguments,
                                               environmentVariables: envVars,
                                               forwardConsole: _args.ForwardConsoleOutput ?? false,
                                               debugging: _args.CommonConfig.Debugging);

        runArgsJson.Save(Path.Combine(_args.CommonConfig.AppPath, "runArgs.json"));

        (ServerURLs serverURLs, IWebHost host) = await StartWebServerAsync(_args.CommonConfig.AppPath,
                                                                           _args.ForwardConsoleOutput ?? false,
                                                                           _args.CommonConfig.HostProperties.WebServerPort,
                                                                           token);

        string[] fullUrls = BuildUrls(serverURLs,
                                      _args.UseQueryStringToPassArguments ? _args.AppArgs : Array.Empty <string>());
        Console.WriteLine();
        foreach (string url in fullUrls)
        {
            Console.WriteLine($"App url: {url}");
        }

        await host.WaitForShutdownAsync(token);
    }
示例#2
0
    private async Task <int> RunAsync()
    {
        string[] engineArgs = Array.Empty <string>();

        string engineBinary = _args.Host switch
        {
            WasmHost.V8 => "v8",
            WasmHost.JavaScriptCore => "jsc",
            WasmHost.SpiderMonkey => "sm",
            WasmHost.NodeJS => "node",
            _ => throw new CommandLineException($"Unsupported engine {_args.Host}")
        };

        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            if (engineBinary.Equals("node"))
            {
                engineBinary = FindEngineInPath(engineBinary + ".exe"); // NodeJS ships as .exe rather than .cmd
            }
            else
            {
                engineBinary = FindEngineInPath(engineBinary + ".cmd");
            }
        }

        if (_args.CommonConfig.Debugging)
        {
            throw new CommandLineException($"Debugging not supported with {_args.Host}");
        }

        var runArgsJson = new RunArgumentsJson(applicationArguments: Array.Empty <string>(),
                                               runtimeArguments: _args.CommonConfig.RuntimeArguments);

        runArgsJson.Save(Path.Combine(_args.CommonConfig.AppPath, "runArgs.json"));

        var args = new List <string>();

        if (_args.Host == WasmHost.V8)
        {
            // v8 needs this flag to enable WASM support
            args.Add("--expose_wasm");
        }

        args.Add(_args.JSPath !);

        args.AddRange(engineArgs);
        if (_args.Host is WasmHost.V8 or WasmHost.JavaScriptCore)
        {
            // v8/jsc want arguments to the script separated by "--", others don't
            args.Add("--");
        }

        args.AddRange(_args.AppArgs);

        ProcessStartInfo psi = new()
        {
            FileName         = engineBinary,
            WorkingDirectory = _args.CommonConfig.AppPath
        };

        foreach (string?arg in args)
        {
            psi.ArgumentList.Add(arg !);
        }

        int exitCode = await Utils.TryRunProcess(psi,
                                                 _logger,
                                                 msg => { if (msg != null)
                                                          {
                                                              _logger.LogInformation(msg);
                                                          }
                                                 },
                                                 msg => { if (msg != null)
                                                          {
                                                              _logger.LogInformation(msg);
                                                          }
                                                 });

        return(exitCode);
    }