From 7e66d47e06a2cf04302e466a1870052294977eb8 Mon Sep 17 00:00:00 2001 From: Christoffer Skeppstedt Date: Thu, 22 Nov 2012 00:53:21 +0100 Subject: [PATCH] New NuGet package contents Using a separate assembly for the attributes --- build/T4TS.Attributes.dll | Bin 0 -> 5120 bytes build/T4TS.cs | 53 --------- build/T4TS.tt | 232 +------------------------------------- 3 files changed, 4 insertions(+), 281 deletions(-) create mode 100644 build/T4TS.Attributes.dll delete mode 100644 build/T4TS.cs diff --git a/build/T4TS.Attributes.dll b/build/T4TS.Attributes.dll new file mode 100644 index 0000000000000000000000000000000000000000..023326654f4c7f4f4f0ed513bdad4f3e02fbba09 GIT binary patch literal 5120 zcmeHKU2GiH6+Sb&cI>2Cev%Rbkr~^ekf4n0%|enUz}nt8xQ%1uT|0oR+OxCQ>%p@- zo0-`VgW5VpMWTsN3#d;)f(o_dA!;ijHHumZA$UQe;-OMsDm7A{DplgGsu05c&Y4+z zytdNP$Eeqy@1FmA&Y3$icgLUmDW!-gjcaw4=sIQ|dBI!53e=egZe-~F?oWHKYo|Z$ zEiF2M(eS;hZ`BOjs@J{HC@aHn)(xj_6efyB&8sML=g#f>Q>h#TdUn9 zy?2MUgXkNObVkyiM=%?>^0mS7PLmz3D60gCU2Zd0ZUpZd{3xCmK$$5y^eU;M{cTpz8+FpOCo5!vA6P=r6%F zeXvhYeP0L&kV+&FqDOxid2K%k1^OK+gn$6WMFJrp=x7OqXt^S<;o^6OwKz+z`Fz$K zFdrQ_l0CvncaRIbjIjMbAo>^PH<>PmzEiITY;k#8bbtD%i}WUF-Xi^{rpF4H-vvK_ zEs#{`E2#{{1S_R+IKTY`?@ zIiN`wfjN2=xQl)UJVx&b-7RR)C0d|fL6cshjAl|l{R)1M(Cff}Iw090^e&O#FL;=) zL3>>2?+O;_V@PcJ9JoYZQeI*X369Xq^d!v-Z3)_tEYXV47X{xD{6O%gAZeVNA($7O z7u3F5XRP+zB1KXdCElg5A^&NtfVu)T!ax zLFtv&enc=Ck7GI6rZKP4b1{YK#JE>!y6OokY?%%EL*Kvh(p3+T-D0TUsu-x+w)zgOvU9OR5e=HR8=?^txCZ<$o-YT z=F$K|doTc}FDRZ%s|U)sW}>4r@|k$iMJ&8cQRbZW|!jo~$l z%0KVeDxeXsHsb_NIa%+irc>D*c}DrcmZgn4uG*xGmn}F}weAI>V+T}F=JmFNyXnJI&j-n!%9bmp}ih1aH^y)^Obi|458cQ4M)?9JVL6$Y8K zp=lWqn%syU8Uj5_+TgkItTJ*gag6NA(Yv*8g-Us1(ICs8>GvZXSQ2gc3-&a=;^pC#$$8&q` z@6-9CM)tR7ZS0)cFc${1ZKch6<>zOyO_UX=cAeR%lsT*0Vf=$XL-EM8ekZg9$vHmj zCPhSZBc5My-EqsQlY9e|l5YuHtv*Ob^y^`x&+W?bX^`k%l7}f#ByU}uiMNom5&w30 zCQo!T+VLy`odeELk>-FWX$sUBP0$(eW57|+JpPdW{Hy5u&nxhV<|iX2egnizJQc)h zhAi?C$H7@&A!Z%t7f&qqi&qI+3(^33i$d6W;G*%HbRM~C$SH)C19^3eNc+TQ0Ch)y zIVy7xQ16}aZLM6u>H*GT9H+5iof6K1C9Gl65aiKHWom+A5AJ7IBF+q?KIH3p4#IO_ z?c#NJ!=5YU2tH;DwVeUhz!TQG)p{mXV9mdap29B_jZVX-DiKD|nFcLO1yx!^bfV2N zgRbIXFer*bY~zD^>Zhg_TJX_%<)Kh;O5p8L7czrCyN tJv}NuL+E>ee$;S>U39|0p51si+Wk=e?J - /// Add this attribute to a class to generate a corresponding TypeScript interface. - /// - [GeneratedCode("T4TS", "1.0")] - [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] - public class TypeScriptInterfaceAttribute: Attribute - { - /// - /// Specifies which module the interface should be placed. - /// The default module will be used if not specified. - /// - public string Module { get; set; } - - /// - /// The name of the interface. - /// If not specified, the name of the class will be used. - /// - public string Name { get; set; } - } - - /// - /// Add this attribute to a property to customize the generated interface member - /// - [GeneratedCode("T4TS", "1.0")] - [AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)] - public class TypeScriptMemberAttribute: Attribute - { - /// - /// The member name in the interface. - /// If not specified, the property name will be used. - /// - public string Name { get; set; } - - /// - /// Specify if the member should be optional, ie. "name?: type". - /// If not specified, the default value will be used. - /// - public bool Optional { get; set; } - - /// - /// Specify which type the interface member will have. - /// If not specified, a suitable type will be determined. - /// - public string Type { get; set; } - } -} diff --git a/build/T4TS.tt b/build/T4TS.tt index e32a61a..b814dcd 100644 --- a/build/T4TS.tt +++ b/build/T4TS.tt @@ -1,5 +1,5 @@ -<#@ template language="C#" debug="true" hostspecific="true" -#><#@ output extension=".cs" +<#@ template language="C#" debug="false" hostspecific="true" +#><#@ output extension=".d.ts" #><#@ assembly name="System.Core" #><#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #><#@ assembly name="EnvDTE" @@ -11,8 +11,7 @@ #><#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #><#@ import namespace="Microsoft.VisualStudio.TextTemplating" #><#@ import namespace="EnvDTE" -#><#@ Include File="T4TS.tt.settings.t4" -#><# var manager = Manager.Create(Host, GenerationEnvironment); manager.StartNewFile("T4TS.d.ts"); #> +#> /**************************************************************************** Generated by T4TS.tt - don't make any changes in this file ****************************************************************************/ @@ -31,63 +30,7 @@ } <# } #> <#= module.IsGlobal ? "// -- End global interfaces" : "}" #> -<# } #> -<# manager.EndBlock(); #> - -namespace T4TS -{ - using System; - using System.CodeDom; - using System.CodeDom.Compiler; - - /// - /// Add this attribute to a class to generate a corresponding TypeScript interface. - /// - [GeneratedCode("T4TS", "1.0")] - [AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] - public class TypeScriptInterfaceAttribute: Attribute - { - /// - /// Specifies which module the interface should be placed. - /// The default module will be used if not specified. - /// - public string Module { get; set; } - - /// - /// The name of the interface. - /// If not specified, the name of the class will be used. - /// - public string Name { get; set; } - } - - /// - /// Add this attribute to a property to customize the generated interface member - /// - [GeneratedCode("T4TS", "1.0")] - [AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)] - public class TypeScriptMemberAttribute: Attribute - { - /// - /// The member name in the interface. - /// If not specified, the property name will be used. - /// - public string Name { get; set; } - - /// - /// Specify if the member should be optional, ie. "name?: type". - /// If not specified, the default value will be used. - /// - public bool Optional { get; set; } - - /// - /// Specify which type the interface member will have. - /// If not specified, a suitable type will be determined. - /// - public string Type { get; set; } - } -} -<# -manager.Process(true); +<# } #><#@ Include File="T4TS.tt.settings.t4" #><#+ List GetDataToRender() { @@ -681,171 +624,4 @@ class CodeGenerator return values; } } - -// ------------------------------------------------------------------------------------------ - -// https://raw.github.com/damieng/DamienGKit -// http://damieng.com/blog/2009/11/06/multiple-outputs-from-t4-made-easy-revisited - -// Manager class records the various blocks so it can split them up -class Manager { - private class Block { - public String Name; - public int Start, Length; - } - - private Block currentBlock; - private List files = new List(); - private Block footer = new Block(); - private Block header = new Block(); - private ITextTemplatingEngineHost host; - private StringBuilder template; - protected List generatedFileNames = new List(); - - public static Manager Create(ITextTemplatingEngineHost host, StringBuilder template) { - return (host is IServiceProvider) ? new VSManager(host, template) : new Manager(host, template); - } - - public void StartNewFile(String name) { - if (name == null) - throw new ArgumentNullException("name"); - CurrentBlock = new Block { Name = name }; - } - - public void StartFooter() { - CurrentBlock = footer; - } - - public void StartHeader() { - CurrentBlock = header; - } - - public void EndBlock() { - if (CurrentBlock == null) - return; - CurrentBlock.Length = template.Length - CurrentBlock.Start; - if (CurrentBlock != header && CurrentBlock != footer) - files.Add(CurrentBlock); - currentBlock = null; - } - - public virtual void Process(bool split, bool sync = true) { - if (split) { - EndBlock(); - String headerText = template.ToString(header.Start, header.Length); - String footerText = template.ToString(footer.Start, footer.Length); - String outputPath = Path.GetDirectoryName(host.TemplateFile); - files.Reverse(); - foreach(Block block in files) { - String fileName = Path.Combine(outputPath, block.Name); - String content = headerText + template.ToString(block.Start, block.Length) + footerText; - generatedFileNames.Add(fileName); - CreateFile(fileName, content); - template.Remove(block.Start, block.Length); - } - } - } - - protected virtual void CreateFile(String fileName, String content) { - if (IsFileContentDifferent(fileName, content)) - File.WriteAllText(fileName, content); - } - - public virtual String GetCustomToolNamespace(String fileName) { - return null; - } - - public virtual String DefaultProjectNamespace { - get { return null; } - } - - protected bool IsFileContentDifferent(String fileName, String newContent) { - return !(File.Exists(fileName) && File.ReadAllText(fileName) == newContent); - } - - private Manager(ITextTemplatingEngineHost host, StringBuilder template) { - this.host = host; - this.template = template; - } - - private Block CurrentBlock { - get { return currentBlock; } - set { - if (CurrentBlock != null) - EndBlock(); - if (value != null) - value.Start = template.Length; - currentBlock = value; - } - } - - private class VSManager: Manager { - private EnvDTE.ProjectItem templateProjectItem; - private EnvDTE.DTE dte; - private Action checkOutAction; - private Action> projectSyncAction; - - public override String DefaultProjectNamespace { - get { - return templateProjectItem.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString(); - } - } - - public override String GetCustomToolNamespace(string fileName) { - return dte.Solution.FindProjectItem(fileName).Properties.Item("CustomToolNamespace").Value.ToString(); - } - - public override void Process(bool split, bool sync) { - if (templateProjectItem.ProjectItems == null) - return; - base.Process(split, sync); - if (sync) - projectSyncAction.EndInvoke(projectSyncAction.BeginInvoke(generatedFileNames, null, null)); - } - - protected override void CreateFile(String fileName, String content) { - if (IsFileContentDifferent(fileName, content)) { - CheckoutFileIfRequired(fileName); - File.WriteAllText(fileName, content); - } - } - - internal VSManager(ITextTemplatingEngineHost host, StringBuilder template) - : base(host, template) { - var hostServiceProvider = (IServiceProvider) host; - if (hostServiceProvider == null) - throw new ArgumentNullException("Could not obtain IServiceProvider"); - dte = (EnvDTE.DTE) hostServiceProvider.GetService(typeof(EnvDTE.DTE)); - if (dte == null) - throw new ArgumentNullException("Could not obtain DTE from host"); - templateProjectItem = dte.Solution.FindProjectItem(host.TemplateFile); - checkOutAction = (String fileName) => dte.SourceControl.CheckOutItem(fileName); - projectSyncAction = (IEnumerable keepFileNames) => ProjectSync(templateProjectItem, keepFileNames); - } - - private static void ProjectSync(EnvDTE.ProjectItem templateProjectItem, IEnumerable keepFileNames) { - var keepFileNameSet = new HashSet(keepFileNames); - var projectFiles = new Dictionary(); - var originalFilePrefix = Path.GetFileNameWithoutExtension(templateProjectItem.get_FileNames(0)) + "."; - foreach(EnvDTE.ProjectItem projectItem in templateProjectItem.ProjectItems) - projectFiles.Add(projectItem.get_FileNames(0), projectItem); - - // Remove unused items from the project - foreach(var pair in projectFiles) - if (!keepFileNames.Contains(pair.Key) && !(Path.GetFileNameWithoutExtension(pair.Key) + ".").StartsWith(originalFilePrefix)) - pair.Value.Delete(); - - // Add missing files to the project - foreach(String fileName in keepFileNameSet) - if (!projectFiles.ContainsKey(fileName)) - templateProjectItem.ProjectItems.AddFromFile(fileName); - } - - private void CheckoutFileIfRequired(String fileName) { - var sc = dte.SourceControl; - if (sc != null && sc.IsItemUnderSCC(fileName) && !sc.IsItemCheckedOut(fileName)) - checkOutAction.EndInvoke(checkOutAction.BeginInvoke(fileName, null, null)); - } - } -} #> \ No newline at end of file