///<summary>Creates a settings file for the active solution if one does not exist already, initialized from the current settings.</summary> public static void CreateSolutionSettings() { string path = GetSolutionFilePath(); if (File.Exists(path)) { return; } Save(path); TsWspHelpers.GetSolutionItemsProject().ProjectItems.AddFromFile(path); UpdateStatusBar("created"); }
private static void PrepareOutputFileForCompilation(string sourceFile, string outputFile, string emptyFileConents) { // create a temporary file if it doesnt already exist so we can add to project etc if needed if (!System.IO.File.Exists(outputFile)) { System.IO.File.WriteAllText(outputFile, emptyFileConents); } // ensure output file is in our project TsWspHelpers.AddOutputFileToSourceFilesProject(sourceFile, outputFile); // check it ouf if needed // (this doesnt work for Sourcegear Vault....) if (!TsWspHelpers.CheckOutFileFromSourceControl(outputFile)) { //abort on failed checkout throw new ApplicationException("Failed to check out file " + outputFile); } // make non read only if permitted System.IO.FileInfo fi = new System.IO.FileInfo(outputFile); if (fi.Exists == true && fi.IsReadOnly) { if (TsWspSettings.Instance.OverwriteReadonly == true) { TsWspHelpers.EnsureNotReadonly(outputFile); } fi.Refresh(); if (fi.IsReadOnly) { string msg = $"TsWspCompilation\r\nWill not be able to write file {outputFile}\r\nfrom source {sourceFile}\r\n{outputFile} is read only"; throw new ApplicationException(msg); } } }
public static void Compile(string sourceFile) { if (!TsWspHelpers.IsTypescriptFile(sourceFile)) { return; } // this extension currrently only applies to web site projects bool b = TsWspHelpers.IsFileInWebsiteProject(sourceFile); if (!b) { return; } Window currentActiveWindow = null; Document doc = null; try { var dte = TsWspPackage.DTE; currentActiveWindow = dte.ActiveWindow; doc = dte.ActiveDocument; // if compiled from menu, may not be saved yet var item = dte.Solution.FindProjectItem(sourceFile); if (item != null) { if (item.IsDirty) { item.Save(); } } // check if a typescript file extension (even though specified ContentType attribute....) string outputFile = TypeScriptOutputFileName(sourceFile); string mapFile = outputFile + ".map"; PrepareOutputFileForCompilation(sourceFile, outputFile, "/*empty*/"); if (TsWspSettings.Instance.GenerateSourceMaps) { string contents = EmptyMapFileContents(sourceFile, outputFile); PrepareOutputFileForCompilation(sourceFile, mapFile, contents); } // compile the TypeScript file ExecuteTypeScript(sourceFile, outputFile, TsWspSettings.Instance); if (System.IO.File.Exists(outputFile)) { // now load the output into an editor and explicitly save TsWspHelpers.SaveOutputFileThroughEditorWindow(outputFile); } else { Logger.Log("Output file does not exist = " + outputFile); } if (TsWspSettings.Instance.GenerateSourceMaps) { if (System.IO.File.Exists(mapFile)) { // now load the output into an editor and explicitly save TsWspHelpers.SaveOutputFileThroughEditorWindow(mapFile); } else { Logger.Log("Output file does not exist = " + mapFile); } } return; } catch (Exception ex) { Logger.Log(ex); return; } finally { try { if (currentActiveWindow != null) { currentActiveWindow.Activate(); } } catch { } if (doc != null) { foreach (Window z in doc.Windows) { if (z != null) { if (z.Kind == "Document" || doc.Windows.Count == 1) { z.Activate(); break; } } } } } }
///<summary>Saves the current settings to the specified settings file.</summary> private static void Save(string filename) { TsWspHelpers.CheckOutFileFromSourceControl(filename); TsWspSettings.Instance.WriteJsonFile(filename); UpdateStatusBar("updated"); }