Exemple #1
0
        public static async Task <string> Run(string tsFilename)
        {
            var existingPath = TsLint.Cache.SingleOrDefault(
                p => tsFilename.Contains(p.Key)
                );

            if (existingPath.Equals(TsLint.DefKeyValuePair))
            {
                // First, check if the project for this file has local installation of tslint.
                var potentialPath = TsLint.TryGetProjectTsLint(tsFilename);

                if (potentialPath.Equals(TsLint.DefKeyValuePair))
                {
                    // Now, check if the solution has local installation of tslint.
                    potentialPath = TsLint.TryGetSolutionTsLint();
                }

                if (potentialPath.Equals(TsLint.DefKeyValuePair))
                {
                    // No project, no solution, check if we can find local installation of tslint "manually".
                    potentialPath = TsLint.TryGetTsLint(tsFilename);
                }

                if (!potentialPath.Equals(TsLint.DefKeyValuePair))
                {
                    existingPath = potentialPath;
                    TsLint.Cache.Add(existingPath.Key, existingPath.Value);
                }
            }

            if (existingPath.Equals(TsLint.DefKeyValuePair))
            {
                return(null);
            }

            var procInfo = new ProcessStartInfo()
            {
                FileName               = existingPath.Value,
                WorkingDirectory       = existingPath.Key,
                Arguments              = $"-t JSON {tsFilename}",
                RedirectStandardOutput = true,
                WindowStyle            = ProcessWindowStyle.Hidden,
                CreateNoWindow         = true,
                UseShellExecute        = false
            };

            var proc = Process.Start(procInfo);

            if (proc == null)
            {
                return(null);
            }

            var reader = proc.StandardOutput;

            await proc.WaitForExitAsync();

            return(await reader.ReadToEndAsync());
        }
Exemple #2
0
        public static async Task <string> Run(string tsFilename)
        {
            var existingPath = TsLint.Cache.SingleOrDefault(
                p => tsFilename.Contains(p.Key)
                );

            if (existingPath.Equals(TsLint.DefKeyValuePair))
            {
                // First, check if the project for this file has local installation of tslint.
                var potentialPath = TsLint.TryGetProjectTsLint(tsFilename);

                if (potentialPath.Equals(TsLint.DefKeyValuePair))
                {
                    // Now, check if the solution has local installation of tslint.
                    potentialPath = TsLint.TryGetSolutionTsLint();
                }

                if (potentialPath.Equals(TsLint.DefKeyValuePair))
                {
                    // No project, no solution, check if we can find local installation of tslint "manually".
                    potentialPath = TsLint.TryGetTsLint(tsFilename);
                }

                if (!potentialPath.Equals(TsLint.DefKeyValuePair))
                {
                    existingPath = potentialPath;
                    TsLint.Cache.Add(existingPath.Key, existingPath.Value);
                }
            }

            if (existingPath.Equals(TsLint.DefKeyValuePair))
            {
                return(null);
            }

            var tscCmdPath    = $"{existingPath.Value}tsc.cmd";
            var tscConfigPath = $"{existingPath.Key}\\tsconfig.json";

            var useTsLintProjectFlag = false;

            if (File.Exists(tscCmdPath) && File.Exists(tscConfigPath))
            {
                useTsLintProjectFlag = true;
            }

            var procInfo = new ProcessStartInfo()
            {
                FileName               = $"{existingPath.Value}tslint.cmd",
                WorkingDirectory       = existingPath.Key,
                Arguments              = $"-t JSON {(useTsLintProjectFlag ? $"--project \"{tscConfigPath}\"" : "")} \"{tsFilename}\"",
                RedirectStandardOutput = true,
                WindowStyle            = ProcessWindowStyle.Hidden,
                CreateNoWindow         = true,
                UseShellExecute        = false
            };

            var proc = Process.Start(procInfo);

            if (proc == null)
            {
                return(null);
            }

            var standardOutput = proc.StandardOutput;
            var output         = await standardOutput.ReadToEndAsync();

            await proc.WaitForExitAsync();

            return(output);
        }