public static TypeScriptDiagonstic Parse(string text)
        {
            // D:/builds/93ef00b2abe44ca8858603bef9fa0c78/5e31664ea2831739542b0607c0183b74f38dbdee78221b5ac944edc52f70a95b.d.ts(103,5)
            // : error TS2300
            // : Duplicate identifier 'jsonp'.

            var parts = text.Split(new[] { ": " }, StringSplitOptions.RemoveEmptyEntries);

            var error = new TypeScriptDiagonstic();

            if (parts.Length < 2)
            {
                error.Message = text;

                return error;
            }

            try
            {
                var fileParts = parts[0].TrimEnd(')').Split('(');
                var positionParts = fileParts[1].Split(',');

                error.FileName = fileParts[0];
                error.Line = int.Parse(positionParts[0]);
                error.Column = int.Parse(positionParts[1]);
                error.Code = parts[1].Replace("error", "");

                if (parts.Length > 2)
                {
                    error.Message = parts[2];
                }
            }
            catch
            {
                throw new Exception(parts.Length + ":" + text);
            }

            return error;
        }
        public static TypeScriptDiagonstic Parse(string text)
        {
            // D:/builds/93ef00b2abe44ca8858603bef9fa0c78/5e31664ea2831739542b0607c0183b74f38dbdee78221b5ac944edc52f70a95b.d.ts(103,5)
            // : error TS2300
            // : Duplicate identifier 'jsonp'.

            var parts = text.Split(splitOn, StringSplitOptions.RemoveEmptyEntries);

            var error = new TypeScriptDiagonstic();

            if (parts.Length < 2)
            {
                error.Message = text;

                return(error);
            }

            try
            {
                var fileParts     = parts[0].TrimEnd(')').Split('(');
                var positionParts = fileParts[1].Split(',');

                error.FileName = fileParts[0];
                error.Line     = int.Parse(positionParts[0]);
                error.Column   = int.Parse(positionParts[1]);
                error.Code     = parts[1].Replace("error", "");

                if (parts.Length > 2)
                {
                    error.Message = parts[2];
                }
            }
            catch
            {
                throw new Exception(parts.Length + ":" + text);
            }

            return(error);
        }
Beispiel #3
0
        private BuildResult Execute()
        {
            var sw = Stopwatch.StartNew();

            var command = TscScriptPath + " " + options.ToString();

            var timeout = TimeSpan.FromSeconds(15);

            var psi = new ProcessStartInfo(NodeExecutable, command)
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                WorkingDirectory       = WorkingDirectory
            };

            var output      = new StringBuilder();
            var error       = new StringBuilder();
            var artifacts   = new List <Artifact>();
            var diagnostics = new DiagnosticList();

            void Watcher_Changed(object sender, FileSystemEventArgs e)
            {
                if (artifacts.Any(r => r.Path == e.FullPath))
                {
                    return;
                }

                if (e.ChangeType == WatcherChangeTypes.Created ||
                    e.ChangeType == WatcherChangeTypes.Changed)
                {
                    artifacts.Add(new Artifact(e.FullPath));
                }
            }

            using (var watcher = new FileSystemWatcher(options.ProjectPath)
            {
                NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName
            })
                using (var process = new Process {
                    StartInfo = psi
                })
                {
                    watcher.Changed += Watcher_Changed;

                    watcher.IncludeSubdirectories = true;
                    watcher.EnableRaisingEvents   = true;

                    process.Start();

                    using (var outputWaitHandle = new AutoResetEvent(false))
                        using (var errorWaitHandle = new AutoResetEvent(false))
                        {
                            process.OutputDataReceived += (sender, e) =>
                            {
                                if (e.Data == null)
                                {
                                    outputWaitHandle.Set();
                                }
                                else
                                {
                                    output.AppendLine(e.Data);
                                }
                            };

                            process.ErrorDataReceived += (sender, e) =>
                            {
                                if (e.Data == null)
                                {
                                    errorWaitHandle.Set();
                                }
                                else
                                {
                                    error.AppendLine(e.Data);
                                }
                            };

                            process.Start();

                            process.BeginOutputReadLine();
                            process.BeginErrorReadLine();

                            if (process.WaitForExit((int)timeout.TotalMilliseconds) &&
                                outputWaitHandle.WaitOne(timeout) &&
                                errorWaitHandle.WaitOne(timeout))
                            {
                                // if there were errors, throw an exception
                                if (error.Length > 0)
                                {
                                    throw new Exception(error.ToString());
                                }

                                var text = output.ToString();

                                string line;

                                using (var reader = new StringReader(text))
                                {
                                    while ((line = reader.ReadLine()) != null)
                                    {
                                        diagnostics.Add(TypeScriptDiagonstic.Parse(line));
                                    }
                                }

                                return(new BuildResult(
                                           status: BuildStatus.Completed,
                                           elapsed: sw.Elapsed,
                                           artifacts: artifacts,
                                           diagnostics: diagnostics
                                           ));
                            }
                            else
                            {
                                throw new BuildTimeout(timeout);
                            }
                        };
                }
        }