private void BeforeQueryStatus(object sender, EventArgs e) { var button = (OleMenuCommand)sender; button.Visible = button.Enabled = false; button.Text = "Transpile to JavaScript"; DTE2 dte = VsHelpers.GetService <DTE, DTE2>(); _item = dte.SelectedItems.Item(1).ProjectItem; if (dte.SelectedItems.MultiSelect || !Transpiler.IsProjectSupported(_item.ContainingProject)) { return; } string fileName = _item.FileNames[1]; if (!Transpiler.IsFileSupported(fileName)) { return; } button.Visible = true; if (Transpiler.IsBuildingOrDebugging(dte)) { return; } if (VsHelpers.FileExistAtOrAbove(fileName, Constants.ConfigFileName, out string cwd)) { button.Text = $"Transpile to JavaScript ({Constants.ConfigFileName} found)"; button.Enabled = false; } else { button.Enabled = true; } }
private static TranspilerStatus CanTranspile(this ProjectItem item) { // Already running if (_isProcessing) { return(TranspilerStatus.AlreadyRunning); } string fileName = item.FileNames[1]; try { // Not the right file extension if (!IsFileSupported(fileName)) { return(TranspilerStatus.NotSupported); } // File not in the right project type if (!IsProjectSupported(item.ContainingProject)) { return(TranspilerStatus.NotSupported); } // Don't run while building if (IsBuildingOrDebugging(item.DTE)) { return(TranspilerStatus.NotSupported); } // tsconfig.json doesn't exist if (!VsHelpers.FileExistAtOrAbove(fileName, Constants.ConfigFileName, out string cwd)) { return(TranspilerStatus.NotSupported); } // tsconfig.json is invalid if (!TryGetJsonConfig(cwd, out JObject obj)) { return(TranspilerStatus.ConfigError); } // compileOnSave is set to false if (!IsCompileOnSaveEnabled(obj)) { return(TranspilerStatus.NotSupported); } // Current file not a source file if (!IsSourceFile(obj, cwd, fileName)) { return(TranspilerStatus.NotSupported); } return(TranspilerStatus.Ok); } catch (JsonException) { return(TranspilerStatus.ConfigError); } catch (Exception ex) { Logger.Log(ex); return(TranspilerStatus.Exception); } }