private void GenerateCore(IEnumerable <string> fileNames, string libFile) { var output = Path.Combine(Common.Paths.BaseAppFolder, "output"); if (Directory.Exists(output)) { Directory.Delete(output, recursive: true); } var json = JsonConvert.SerializeObject(new { fileNames, libFile, outputFolder = output }); var argumentsJson = Path.Combine(Common.Paths.BaseAppFolder, "TypeScriptAnalyzerArguments.json"); File.WriteAllText(argumentsJson, json); var analyzerJs = Path.Combine(Common.Paths.BaseAppFolder, @"TypeScriptSupport\analyzer.js"); var arguments = string.Format("\"{0}\" {1}", analyzerJs, argumentsJson); ProcessLaunchService.ProcessRunResult result; try { using (Disposable.Timing("Calling Node.js to process TypeScript")) { result = new ProcessLaunchService().RunAndRedirectOutput("node", arguments); } } catch (Win32Exception) { Log.Write("Warning: Node.js is required to generate TypeScript files. Skipping generation. Download Node.js from https://nodejs.org.", ConsoleColor.Yellow); Log.Exception("Node.js is not installed."); return; } using (Disposable.Timing("Generating TypeScript files")) { foreach (var file in Directory.GetFiles(output)) { if (Path.GetFileNameWithoutExtension(file) == "ok") { continue; } if (Path.GetFileNameWithoutExtension(file) == "error") { var errorContent = File.ReadAllText(file); Log.Exception(DateTime.Now.ToString() + " " + errorContent); return; } var text = File.ReadAllText(file); AnalyzedFile analysis = JsonConvert.DeserializeObject <AnalyzedFile>(text); EnsureFileGeneratedAndGetUrl(analysis); } } }
public void EnsureFileGeneratedAndGetUrl(AnalyzedFile analysis) { string localFileSystemPath = analysis.fileName; localFileSystemPath = Path.GetFullPath(localFileSystemPath); string destinationFilePath = GetDestinationFilePath(localFileSystemPath); if (!File.Exists(destinationFilePath)) { Generate(localFileSystemPath, destinationFilePath, analysis.syntacticClassifications, analysis.semanticClassifications); } }