public static async Task <CompilerOptions> Parse(string lessFilePath, string lessContent = null) { if (!File.Exists(lessFilePath) || ProjectMap.ShouldIgnore(lessFilePath)) { return(null); } lessContent = lessContent ?? await VsHelpers.ReadFileAsync(lessFilePath); var options = new CompilerOptions(lessFilePath); // Compile if (Path.GetFileName(lessFilePath).StartsWith("_", StringComparison.Ordinal) || lessContent.IndexOf("no-compile", StringComparison.OrdinalIgnoreCase) > -1) { options.Compile = false; } // Minify if (lessContent.IndexOf("no-minify", StringComparison.OrdinalIgnoreCase) > -1) { options.Minify = false; } // Arguments Match argsMatch = _regex.Match(lessContent, 0, Math.Min(500, lessContent.Length)); if (argsMatch.Success) { string inFile = Path.GetFileName(options.InputFilePath); options.Arguments = $"\"{inFile}\" {argsMatch.Groups["args"].Value.TrimEnd('*', '/').Trim()}"; } // Source map options.SourceMap = options.Arguments.IndexOf("--source-map", StringComparison.OrdinalIgnoreCase) > -1; // OutputFileName Match outMatch = _outFile.Match(options.Arguments); if (argsMatch.Success && outMatch.Success) { string relative = outMatch.Groups["out"].Value.Replace("/", "\\"); options.OutputFilePath = Path.Combine(Path.GetDirectoryName(lessFilePath), relative); } else { options.OutputFilePath = Path.ChangeExtension(lessFilePath, ".css"); if (argsMatch.Success) { options.Arguments += $" \"{Path.GetFileName(options.OutputFilePath)}\""; } } // Trim the argument list options.Arguments = options.Arguments.Trim(); return(options); }
private async Task AddFile(string lessFilePath) { if (LessFiles.Keys.Any(c => c.InputFilePath == lessFilePath)) { return; } string lessContent = await VsHelpers.ReadFileAsync(lessFilePath); CompilerOptions options = await CompilerOptions.Parse(lessFilePath, lessContent); LessFiles.Add(options, new List <CompilerOptions>()); await AddOption(options, lessContent); }