private static async Tasks.Task <bool> CompileSingleFileAsync(CompilerOptions options) { try { VsHelpers.CheckFileOutOfSourceControl(options.OutputFilePath); if (options.SourceMap) { VsHelpers.CheckFileOutOfSourceControl(options.OutputFilePath + ".map"); } CompilerResult result = await NodeProcess.ExecuteProcess(options); Logger.Log($"{result.Arguments}"); if (result.HasError) { Logger.Log(result.Error); VsHelpers.WriteStatus($"Error compiling LESS file. See Output Window for details"); } else { AddFilesToProject(options); Minify(options); } return(true); } catch (Exception ex) { Logger.Log(ex); VsHelpers.WriteStatus($"Error compiling LESS file. See Output Window for details"); return(false); } }
public static async Tasks.Task CompileAsync(CompilerOptions options, Project project) { var tf = new JoinableTaskFactory(Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskContext); await tf.SwitchToMainThreadAsync(); if (options == null || project == null || !LessCatalog.Catalog.TryGetValue(project.UniqueName, out ProjectMap map)) { return; } IEnumerable <CompilerOptions> parents = map.LessFiles .Where(l => l.Value.Exists(c => c == options)) .Select(l => l.Key) .Union(new[] { options }) .Distinct(); var sw = new Stopwatch(); sw.Start(); var compilerTaks = new List <Tasks.Task>(); foreach (CompilerOptions parentOptions in parents.Where(p => p.Compile)) { compilerTaks.Add(CompileSingleFileAsync(parentOptions)); } await Tasks.Task.WhenAll(compilerTaks); sw.Stop(); VsHelpers.WriteStatus($"LESS file compiled in {Math.Round(sw.Elapsed.TotalSeconds, 2)} seconds"); }
private async void DocumentSaved(object sender, TextDocumentFileActionEventArgs e) { if (e.FileActionType != FileActionTypes.ContentSavedToDisk || !_project.IsLessCompilationEnabled()) { return; } if (NodeProcess.IsInstalling) { VsHelpers.WriteStatus("The LESS compiler is being installed. Please try again in a few seconds..."); } else if (NodeProcess.IsReadyToExecute()) { CompilerOptions options = await CompilerOptions.Parse(e.FilePath, _view.TextBuffer.CurrentSnapshot.GetText()); if (_view.Properties.TryGetProperty(typeof(LessAdornment), out LessAdornment adornment)) { await adornment.Update(options); } if (options == null || !_project.SupportsCompilation() || !_project.IsLessCompilationEnabled()) { return; } await LessCatalog.UpdateFile(_project, options); if (await LessCatalog.EnsureCatalog(_project)) { await CompilerService.CompileAsync(options, _project); } } }
public static async Tasks.Task CompileProjectAsync(Project project) { if (project == null || !LessCatalog.Catalog.TryGetValue(project.UniqueName, out ProjectMap map)) { return; } var compileTasks = new List <Tasks.Task>(); foreach (CompilerOptions option in map.LessFiles.Keys) { if (option.Compile) { compileTasks.Add(CompileSingleFile(option)); } } await Tasks.Task.WhenAll(compileTasks); VsHelpers.WriteStatus($"LESS files in solution compiled"); }
public static async Tasks.Task CompileProjectAsync(Project project) { var tf = new JoinableTaskFactory(Microsoft.VisualStudio.Shell.ThreadHelper.JoinableTaskContext); await tf.SwitchToMainThreadAsync(); if (project == null || !LessCatalog.Catalog.TryGetValue(project.UniqueName, out ProjectMap map)) { return; } var compileTasks = new List <Tasks.Task>(); foreach (CompilerOptions option in map.LessFiles.Keys) { if (option.Compile) { compileTasks.Add(CompileSingleFileAsync(option)); } } await Tasks.Task.WhenAll(compileTasks); VsHelpers.WriteStatus($"LESS files in solution compiled"); }