private void BuildApp(ISingleCallChallenge challenge) { // place the challenge var templatePath = System.IO.Path.Combine(_npmConfig.Prefix, "templates/HomeTemplate.js"); var template = System.IO.File.ReadAllText(templatePath); var targetPath = System.IO.Path.Combine(_npmConfig.Prefix, "src/Home.js"); System.IO.File.WriteAllText(targetPath, template .Replace("//_}*1*{_", challenge.ChallengeFunction)); // npm build using var process = new Process(); process.StartInfo.FileName = "npm"; process.StartInfo.Arguments = $"run --prefix \"{_npmConfig.Prefix}\" build-silent"; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.Start(); // wait until npm build is done, throw if not done in 30 seconds if (!process.WaitForExit(1000 * 30)) { throw new TimeoutException("Npm took too long to run"); } _logger.LogError(process.StandardError.ReadToEnd()); }
public void SaveChallenge(ISingleCallChallenge challenge, string userName, Guid appId) => _challenges[new UserAppPair(userName, appId)] = challenge;