diff --git a/AppVeyor-Build.ps1 b/AppVeyor-Build.ps1 index cb46add77..801769101 100644 --- a/AppVeyor-Build.ps1 +++ b/AppVeyor-Build.ps1 @@ -32,19 +32,33 @@ If ($env:appveyor_repo_tag -eq $True) Set-AppveyorBuildVariable 'releaseDescription' $description } -# build nupkg - mkdir artifacts -mkdir chocoTemp\tools -move tools\chocolatey\pretzel.nuspec chocoTemp\pretzel.nuspec -move tools\chocolatey\chocolateyInstall.ps1 chocoTemp\tools\chocolateyInstall.ps1 +# build Pretzel nupkg +mkdir chocoTemp\Pretzel\tools -(gc chocoTemp\tools\chocolateyInstall.ps1).replace('{{version}}',$version).replace('{{tag}}',$tag)|sc chocoTemp\tools\chocolateyInstall.ps1 +move tools\chocolatey\Pretzel\pretzel.nuspec chocoTemp\Pretzel\pretzel.nuspec +move tools\chocolatey\Pretzel\chocolateyInstall.ps1 chocoTemp\Pretzel\tools\chocolateyInstall.ps1 +move tools\chocolatey\Pretzel\chocolateyUninstall.ps1 chocoTemp\Pretzel\tools\chocolateyUninstall.ps1 -nuget pack chocoTemp\pretzel.nuspec -OutputDirectory artifacts -Version $version -NoPackageAnalysis +(gc chocoTemp\Pretzel\tools\chocolateyInstall.ps1).replace('{{version}}',$version).replace('{{tag}}',$tag)|sc chocoTemp\Pretzel\tools\chocolateyInstall.ps1 -# create zip +nuget pack chocoTemp\Pretzel\pretzel.nuspec -OutputDirectory artifacts -Version $version -NoPackageAnalysis +# create Pretzel zip 7z a Pretzel.$version.zip $env:appveyor_build_folder\src\Pretzel\bin\Release\Pretzel.exe* -7z a Pretzel.$version.zip ReleaseNotes.md \ No newline at end of file +7z a Pretzel.$version.zip ReleaseNotes.md + +# build Pretzel.ScriptCs nupkg +mkdir chocoTemp\Pretzel.ScriptCs\tools +move tools\chocolatey\Pretzel.ScriptCs\pretzel.scriptcs.nuspec chocoTemp\Pretzel.ScriptCs\pretzel.scriptcs.nuspec +move tools\chocolatey\Pretzel.ScriptCs\chocolateyInstall.ps1 chocoTemp\Pretzel.ScriptCs\tools\chocolateyInstall.ps1 +move tools\chocolatey\Pretzel.ScriptCs\chocolateyUninstall.ps1 chocoTemp\Pretzel.ScriptCs\tools\chocolateyUninstall.ps1 +(gc chocoTemp\Pretzel.ScriptCs\tools\chocolateyInstall.ps1).replace('{{version}}',$version).replace('{{tag}}',$tag)|sc chocoTemp\Pretzel.ScriptCs\tools\chocolateyInstall.ps1 +nuget pack chocoTemp\Pretzel.ScriptCs\pretzel.scriptcs.nuspec -OutputDirectory artifacts -Version $version -NoPackageAnalysis + +# create Pretzel.ScriptCs zip +get-childitem src\Pretzel.ScriptCs\bin\Release -filter *.dll | % { $_.Name } | out-file artifacts\Pretzel.ScriptCs.Files.txt + +7z a Pretzel.ScriptCs.$version.zip $env:appveyor_build_folder\src\Pretzel.ScriptCs\bin\Release\*.dll +7z a Pretzel.ScriptCs.$version.zip $env:appveyor_build_folder\artifacts\Pretzel.ScriptCs.Files.txt \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 2f38ffb04..e3793ed5a 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -33,16 +33,22 @@ artifacts: - path: artifacts\Pretzel.*.nupkg name: Pretzel.nupkg + - path: artifacts\Pretzel.ScriptCs.*.nupkg + name: Pretzel.ScriptCs.nupkg + - path: coverage.xml - path: Pretzel.*.zip name: Pretzel.zip + + - path: Pretzel.ScriptCs.*.zip + name: Pretzel.ScriptCs.zip deploy: - provider: GitHub auth_token: secure: piWk1xd/YxJK+HJOFwJyBORP+Go1p4XO6148zeePdyVEGPxk4wGXk5tP2jYkM4eU - artifact: Pretzel.zip + artifact: Pretzel.zip, Pretzel.ScriptCs.zip description: $(releaseDescription) on: appveyor_repo_tag: true @@ -52,6 +58,6 @@ deploy: api_key: secure: 2GBJF71EQfU+kIL5NHVM4wYoCRcFf/gM/voNIgud8vDWUE+uA1ye/hRWjJPQWA5w skip_symbols: true - artifact: Pretzel.nupkg + artifact: /.*\.nupkg/ on: appveyor_repo_tag: true diff --git a/src/Pretzel.Logic/Commands/BaseParameters.cs b/src/Pretzel.Logic/Commands/BaseParameters.cs new file mode 100644 index 000000000..ad6fd9018 --- /dev/null +++ b/src/Pretzel.Logic/Commands/BaseParameters.cs @@ -0,0 +1,66 @@ +using NDesk.Options; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.IO.Abstractions; +using System.Linq; + +namespace Pretzel.Logic.Commands +{ + public sealed class BaseParameters + { + public OptionSet Options { get; private set; } + + public string CommandName { get; private set; } + + public bool Help { get; private set; } + + public bool Debug { get; private set; } + + public bool Safe { get; private set; } + + [Export("SourcePath")] + public string Path { get; private set; } + + [Export] + public IFileSystem FileSystem { get; private set; } + + public List CommandArgs { get; private set; } + + private BaseParameters(string[] arguments, IFileSystem fileSystem) + { + Options = new OptionSet + { + {"help", "Display help mode", p => Help = true}, + {"debug", "Enable debugging", p => Debug = true}, + { "safe", "Disable custom plugins", v => Safe = true }, + { "d|directory=", "[Obsolete, use --source instead] The path to site directory", p => Path = p }, + { "s|source=", "The path to the source site (default current directory)", p => Path = p} + }; + + FileSystem = fileSystem; + + CommandName = arguments.Take(1).FirstOrDefault(); + + CommandArgs = Options.Parse(arguments.Skip(1)); + + SetPath(CommandArgs.FirstOrDefault()); + } + + public static BaseParameters Parse(string[] arguments, IFileSystem fileSystem) + { + return new BaseParameters(arguments, fileSystem); + } + + private void SetPath(string firstArgument) + { + // take the first argument after the command + if (firstArgument != null && !firstArgument.StartsWith("-") && !firstArgument.StartsWith("/")) + { + Path = FileSystem.Path.IsPathRooted(firstArgument) + ? firstArgument + : FileSystem.Path.Combine(FileSystem.Directory.GetCurrentDirectory(), firstArgument); + } + Path = string.IsNullOrWhiteSpace(Path) ? FileSystem.Directory.GetCurrentDirectory() : FileSystem.Path.GetFullPath(Path); + } + } +} diff --git a/src/Pretzel.Logic/Commands/CommandParameters.cs b/src/Pretzel.Logic/Commands/CommandParameters.cs index 3d1c7f5ad..b02758308 100644 --- a/src/Pretzel.Logic/Commands/CommandParameters.cs +++ b/src/Pretzel.Logic/Commands/CommandParameters.cs @@ -27,18 +27,15 @@ public CommandParameters([ImportMany] IEnumerable commandL Settings = new OptionSet { { "t|template=", "The templating engine to use", v => Template = v }, - { "d|directory=", "[Obsolete, use --source instead] The path to site directory", p => Path = p }, { "p|port=", "The port to test the site locally", p => decimal.TryParse(p, out port) }, { "i|import=", "The import type", v => ImportType = v }, { "f|file=", "Path to import file", v => ImportPath = v }, - { "s|source=", "The path to the source site (default current directory)", p => Path = p}, { "destination=", "The path to the destination site (default _site)", d => DestinationPath = d}, { "drafts", "Add the posts in the drafts folder", v => IncludeDrafts = true }, { "nobrowser", "Do not launch a browser", v => LaunchBrowser = false }, { "withproject", "Includes a layout VS Solution, to give intellisense when editing razor layout files", v => WithProject = (v!=null) }, { "wiki", "Creates a wiki instead of a blog (razor template only)", v => Wiki = (v!=null) }, - { "cleantarget", "Delete the target directory (_site by default)", v => CleanTarget = true }, - { "safe", "Disable custom plugins", v => Safe = true } + { "cleantarget", "Delete the target directory (_site by default)", v => CleanTarget = true } }; // Allow extensions to register command line args @@ -48,7 +45,8 @@ public CommandParameters([ImportMany] IEnumerable commandL } } - public string Path { get; private set; } + [Import("SourcePath")] + public string Path { get; internal set; } public string Template { get; private set; } @@ -66,8 +64,6 @@ public CommandParameters([ImportMany] IEnumerable commandL public bool LaunchBrowser { get; private set; } - public bool Safe { get; private set; } - public string DestinationPath { get; private set; } private decimal port; @@ -87,17 +83,6 @@ public void Parse(IEnumerable arguments) Settings.Parse(argumentList); - var firstArgument = argumentList.FirstOrDefault(); - - if (firstArgument != null && !firstArgument.StartsWith("-") && !firstArgument.StartsWith("/")) - { - Path = fileSystem.Path.IsPathRooted(firstArgument) - ? firstArgument - : fileSystem.Path.Combine(fileSystem.Directory.GetCurrentDirectory(), firstArgument); - } - - Path = string.IsNullOrWhiteSpace(Path) ? fileSystem.Directory.GetCurrentDirectory() : fileSystem.Path.GetFullPath(Path); - if (string.IsNullOrEmpty(DestinationPath)) { DestinationPath = "_site"; diff --git a/src/Pretzel.Logic/Pretzel.Logic.csproj b/src/Pretzel.Logic/Pretzel.Logic.csproj index afc894218..c9c009cdc 100644 --- a/src/Pretzel.Logic/Pretzel.Logic.csproj +++ b/src/Pretzel.Logic/Pretzel.Logic.csproj @@ -10,10 +10,11 @@ Properties Pretzel.Logic Pretzel.Logic - v4.0 + v4.5 512 ..\..\src\ true + true @@ -23,6 +24,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -31,6 +33,7 @@ TRACE prompt 4 + false @@ -39,23 +42,25 @@ False - ..\packages\CommonMark.NET.0.8.5\lib\net40-client\CommonMark.dll + ..\packages\CommonMark.NET.0.8.5\lib\net45\CommonMark.dll ..\packages\DotlessClientOnly.1.4.1.0\lib\dotless.ClientOnly.dll - - ..\packages\DotLiquid.1.8.0\lib\NET40\DotLiquid.dll + + False + ..\packages\DotLiquid.1.8.0\lib\NET45\DotLiquid.dll - - ..\packages\HtmlAgilityPack.1.4.9\lib\Net40\HtmlAgilityPack.dll + + False + ..\packages\HtmlAgilityPack.1.4.9\lib\Net45\HtmlAgilityPack.dll ..\packages\NDesk.Options.0.2.1\lib\NDesk.Options.dll False - ..\packages\RazorEngine.3.6.0\lib\net40\RazorEngine.dll + ..\packages\RazorEngine.3.6.0\lib\net45\RazorEngine.dll @@ -65,9 +70,9 @@ False ..\packages\System.IO.Abstractions.2.0.0.104\lib\net40\System.IO.Abstractions.dll - - True - ..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll + + False + ..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll @@ -81,6 +86,7 @@ + diff --git a/src/Pretzel.Logic/Properties/AssemblyInfo.cs b/src/Pretzel.Logic/Properties/AssemblyInfo.cs index 09146c99a..cf471abf6 100644 --- a/src/Pretzel.Logic/Properties/AssemblyInfo.cs +++ b/src/Pretzel.Logic/Properties/AssemblyInfo.cs @@ -1,7 +1,8 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Pretzel.Logic")] @@ -12,8 +13,8 @@ [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. // The following GUID is for the ID of the typelib if this project is exposed to COM @@ -22,13 +23,13 @@ // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] - [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: InternalsVisibleTo("Pretzel.Tests")] diff --git a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs index 3480d64a6..5d0d1efc2 100644 --- a/src/Pretzel.Logic/Templating/JekyllEngineBase.cs +++ b/src/Pretzel.Logic/Templating/JekyllEngineBase.cs @@ -24,10 +24,10 @@ public abstract class JekyllEngineBase : ISiteEngine #pragma warning restore 0649 - [ImportMany(AllowRecomposition = true)] + [ImportMany] public IEnumerable Filters { get; set; } - [ImportMany(AllowRecomposition = true)] + [ImportMany] public IEnumerable Tags { get; set; } public abstract void Initialize(); diff --git a/src/Pretzel.Logic/packages.config b/src/Pretzel.Logic/packages.config index d4bf28d3d..581486590 100644 --- a/src/Pretzel.Logic/packages.config +++ b/src/Pretzel.Logic/packages.config @@ -1,14 +1,13 @@  - + - - - - + + + - + - \ No newline at end of file + diff --git a/src/Pretzel.ScriptCs/Pretzel.ScriptCs.csproj b/src/Pretzel.ScriptCs/Pretzel.ScriptCs.csproj new file mode 100644 index 000000000..6897204f9 --- /dev/null +++ b/src/Pretzel.ScriptCs/Pretzel.ScriptCs.csproj @@ -0,0 +1,126 @@ + + + + + Debug + AnyCPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7} + Library + Properties + Pretzel.ScriptCs + Pretzel.ScriptCs + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Autofac.3.3.1\lib\net40\Autofac.dll + + + ..\packages\Autofac.Mef.3.0.3\lib\net40\Autofac.Integration.Mef.dll + + + ..\packages\Common.Logging.2.1.2\lib\net40\Common.Logging.dll + + + ..\packages\ICSharpCode.NRefactory.5.3.0\lib\Net40\ICSharpCode.NRefactory.dll + + + ..\packages\ICSharpCode.NRefactory.5.3.0\lib\Net40\ICSharpCode.NRefactory.CSharp.dll + + + ..\packages\ICSharpCode.NRefactory.5.3.0\lib\Net40\ICSharpCode.NRefactory.Xml.dll + + + ..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll + + + ..\packages\Mono.Cecil.0.9.5.2\lib\net40\Mono.Cecil.dll + + + ..\packages\Mono.Cecil.0.9.5.2\lib\net40\Mono.Cecil.Mdb.dll + + + ..\packages\Mono.Cecil.0.9.5.2\lib\net40\Mono.Cecil.Pdb.dll + + + ..\packages\Mono.Cecil.0.9.5.2\lib\net40\Mono.Cecil.Rocks.dll + + + ..\packages\Mono.CSharp.3.6.1\lib\net40\Mono.CSharp.dll + + + False + ..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll + + + False + ..\packages\NuGet.Core.2.8.2\lib\net40-Client\NuGet.Core.dll + + + ..\packages\Roslyn.Compilers.Common.1.2.20906.2\lib\net45\Roslyn.Compilers.dll + + + ..\packages\Roslyn.Compilers.CSharp.1.2.20906.2\lib\net45\Roslyn.Compilers.CSharp.dll + + + False + ..\packages\ScriptCs.ComponentModel.Composition.0.1.2\lib\net45\ScriptCs.ComponentModel.Composition.dll + + + ..\packages\ScriptCs.Contracts.0.14.0\lib\net45\ScriptCs.Contracts.dll + + + ..\packages\ScriptCs.Core.0.14.0\lib\net45\ScriptCs.Core.dll + + + ..\packages\ScriptCs.Engine.Mono.0.14.0\lib\net45\ScriptCs.Engine.Mono.dll + + + ..\packages\ScriptCs.Engine.Roslyn.0.14.0\lib\net45\ScriptCs.Engine.Roslyn.dll + + + ..\packages\ScriptCs.Hosting.0.14.0\lib\net45\ScriptCs.Hosting.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Pretzel.ScriptCs/Properties/AssemblyInfo.cs b/src/Pretzel.ScriptCs/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..0b4f63897 --- /dev/null +++ b/src/Pretzel.ScriptCs/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Pretzel.ScriptCs")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Pretzel.ScriptCs")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7a228aba-e84a-46ca-bda3-3cfacd13530b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Pretzel.ScriptCs/ScriptCsPluginsEngine.cs b/src/Pretzel.ScriptCs/ScriptCsPluginsEngine.cs new file mode 100644 index 000000000..1ca69aeb3 --- /dev/null +++ b/src/Pretzel.ScriptCs/ScriptCsPluginsEngine.cs @@ -0,0 +1,14 @@ +using ScriptCs.ComponentModel.Composition; +using System; +using System.ComponentModel.Composition.Primitives; + +namespace Pretzel.ScriptCs +{ + public sealed class ScriptCsCatalogFactory + { + public static ComposablePartCatalog CreateScriptCsCatalog(string pluginsFolderPath, Type[] references) + { + return new ScriptCsCatalog(pluginsFolderPath, new ScriptCsCatalogOptions { References = references }); + } + } +} diff --git a/src/Pretzel.ScriptCs/packages.config b/src/Pretzel.ScriptCs/packages.config new file mode 100644 index 000000000..7dec8c6e6 --- /dev/null +++ b/src/Pretzel.ScriptCs/packages.config @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Pretzel.Tests/Commands/BaseParameterTests.cs b/src/Pretzel.Tests/Commands/BaseParameterTests.cs new file mode 100644 index 000000000..679f9c698 --- /dev/null +++ b/src/Pretzel.Tests/Commands/BaseParameterTests.cs @@ -0,0 +1,163 @@ +using Pretzel.Logic.Commands; +using System.Collections.Generic; +using System.IO; +using System.IO.Abstractions; +using System.IO.Abstractions.TestingHelpers; +using Xunit; + +namespace Pretzel.Tests +{ + public class BaseParameterTests + { + private const string ExpectedPath = @"D:\Code"; + + private readonly IFileSystem FileSystem = new MockFileSystem(); + + public BaseParameters GetBaseParameter(string[] args) + { + return BaseParameters.Parse(args, FileSystem); + } + + [Fact] + public void WriteOptions_WithNoParametersSpecified_DisplaysAll() + { + var writer = new StringWriter(); + + var subject = GetBaseParameter(new string[0]); + + subject.Options.WriteOptionDescriptions(writer); + + var output = writer.ToString(); + + Assert.True(output.Contains("--directory=")); + Assert.True(output.Contains("--source=")); + Assert.True(output.Contains("--debug")); + Assert.True(output.Contains("--help")); + Assert.True(output.Contains("--safe")); + } + + [Fact] + public void Parse_CommandName_IsTheFirstParameter() + { + var subject = GetBaseParameter(new[] { "bake" }); + Assert.Equal("bake", subject.CommandName); + Assert.Empty(subject.CommandArgs); + } + + [Fact] + public void Parse_WhenNoParametersSet_MapsPathToCurrentDirectory() + { + var subject = GetBaseParameter(new[] { "bake" }); + Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path); + } + + [Fact] + public void Parse_WhenOneParameterSet_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingPathUsingShortParameter_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "--d", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingPathUsingFullParameter_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "--directory", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingPathUsingShortParameterSingleDash_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "-d", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingPathUsingFullParameterSingleDash_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "-directory", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingAllParameters_ResultIsCorrect() + { + var subject = GetBaseParameter(new[] { "bake", @"-directory=c:\mysite", "-safe", "-help", "-debug" }); + + Assert.Equal(@"c:\mysite", subject.Path); + Assert.True(subject.Safe); + Assert.True(subject.Help); + Assert.True(subject.Debug); + Assert.Equal("bake", subject.CommandName); + Assert.Empty(subject.CommandArgs); + } + + [Fact] + public void Parse_WhenSpecifyingNoParameters_DefaultVeluesResultIsCorrect() + { + var args = new List(); + + var subject = GetBaseParameter(new[] { "bake" }); + + Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path); + Assert.False(subject.Safe); + Assert.False(subject.Help); + Assert.False(subject.Debug); Assert.Equal("bake", subject.CommandName); + Assert.Empty(subject.CommandArgs); + } + + [Fact] + public void Parse_WhenOneParameterSet_MapsToPath_RelativePath() + { + var subject = GetBaseParameter(new[] { "bake", "mySite" }); + + Assert.Equal(FileSystem.Path.Combine(FileSystem.Directory.GetCurrentDirectory(), "mySite"), subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingShortParameter_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "--s", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingFullParameter_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "--source", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingShortParameterSingleDash_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "-s", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingSourcePathUsingFullParameterSingleDash_MapsToPath() + { + var subject = GetBaseParameter(new[] { "bake", "-source", ExpectedPath }); + Assert.Equal(ExpectedPath, subject.Path); + } + + [Fact] + public void Parse_WhenSpecifyingExtraParams_ThereShouldBeInCommandArgs() + { + var subject = GetBaseParameter(new[] { "bake", "-cleantarget", "-safe", "-nobrowser", "-p=8888" }); + Assert.NotNull(subject.CommandArgs); + Assert.Equal(3, subject.CommandArgs.Count); + Assert.Equal("-cleantarget", subject.CommandArgs[0]); + Assert.Equal("-nobrowser", subject.CommandArgs[1]); + Assert.Equal("-p=8888", subject.CommandArgs[2]); + } + } +} diff --git a/src/Pretzel.Tests/CommandParameterOutputTests.cs b/src/Pretzel.Tests/Commands/CommandParameterOutputTests.cs similarity index 81% rename from src/Pretzel.Tests/CommandParameterOutputTests.cs rename to src/Pretzel.Tests/Commands/CommandParameterOutputTests.cs index d2686b2c1..ad6b0df2b 100644 --- a/src/Pretzel.Tests/CommandParameterOutputTests.cs +++ b/src/Pretzel.Tests/Commands/CommandParameterOutputTests.cs @@ -27,17 +27,12 @@ public void WriteOptions_WithNoParametersSpecified_DisplaysAll() Assert.True(output.Contains("-t")); Assert.True(output.Contains("--template=")); - Assert.True(output.Contains("-d")); - Assert.True(output.Contains("--directory=")); - Assert.True(output.Contains("-p")); Assert.True(output.Contains("--port=")); Assert.True(output.Contains("-i")); Assert.True(output.Contains("--import=")); Assert.True(output.Contains("-f")); Assert.True(output.Contains("--file=")); Assert.True(output.Contains("--cleantarget")); - Assert.True(output.Contains("--safe")); - Assert.True(output.Contains("--source")); Assert.True(output.Contains("--destination")); } @@ -59,8 +54,6 @@ public void WriteOptions_WithOneParameterSpecified_IgnoresOthers() var output = writer.ToString(); - Assert.False(output.Contains("-d")); - Assert.False(output.Contains("--directory=")); Assert.False(output.Contains("-p")); Assert.False(output.Contains("--port=")); Assert.False(output.Contains("-i")); @@ -72,25 +65,23 @@ public void WriteOptions_WithOneParameterSpecified_IgnoresOthers() [Fact] public void WriteOptions_WithTwoParameterSpecified_DisplaysSelection() { - subject.WriteOptions(writer, "-t", "-d"); + subject.WriteOptions(writer, "-t", "-p"); var output = writer.ToString(); Assert.True(output.Contains("-t")); Assert.True(output.Contains("--template=")); - Assert.True(output.Contains("-d")); - Assert.True(output.Contains("--directory=")); + Assert.True(output.Contains("-p")); + Assert.True(output.Contains("--port=")); } [Fact] public void WriteOptions_WithTwoParameterSpecified_IgnoresOthers() { - subject.WriteOptions(writer, "-t", "-d"); + subject.WriteOptions(writer, "-t", "-p"); var output = writer.ToString(); - Assert.False(output.Contains("-p")); - Assert.False(output.Contains("--port=")); Assert.False(output.Contains("-i")); Assert.False(output.Contains("--import=")); Assert.False(output.Contains("-f")); diff --git a/src/Pretzel.Tests/CommandParameterTests.cs b/src/Pretzel.Tests/Commands/CommandParameterTests.cs similarity index 76% rename from src/Pretzel.Tests/CommandParameterTests.cs rename to src/Pretzel.Tests/Commands/CommandParameterTests.cs index 9f54bcaf0..97513697f 100644 --- a/src/Pretzel.Tests/CommandParameterTests.cs +++ b/src/Pretzel.Tests/Commands/CommandParameterTests.cs @@ -27,24 +27,7 @@ public class CommandParameterTests public CommandParameterTests() { - subject = new CommandParameters(Enumerable.Empty(), FileSystem); - } - - [Fact] - public void Parse_WhenNoParametersSet_MapsPathToCurrentDirectory() - { - var args = new List(); - subject.Parse(args); - Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path); - Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); - } - - [Fact] - public void Parse_WhenOneParameterSet_MapsToPath() - { - var args = new List { ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); + subject = new CommandParameters(Enumerable.Empty(), FileSystem) { Path = ExpectedPath }; } [Fact] @@ -79,38 +62,6 @@ public void Parse_WhenSpecifyingTemplateUsingFullParameterSingleDash_MapsToPath( Assert.Equal(ExpectedTemplate, subject.Template); } - [Fact] - public void Parse_WhenSpecifyingPathUsingShortParameter_MapsToPath() - { - var args = new List { "--d", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - - [Fact] - public void Parse_WhenSpecifyingPathUsingFullParameter_MapsToPath() - { - var args = new List { "--directory", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - - [Fact] - public void Parse_WhenSpecifyingPathUsingShortParameterSingleDash_MapsToPath() - { - var args = new List { "-d", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - - [Fact] - public void Parse_WhenSpecifyingPathUsingFullParameterSingleDash_MapsToPath() - { - var args = new List { "-directory", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - [Fact] public void Parse_WhenSpecifyingPortWithoutParamerers_IsGreaterThanZero() { @@ -288,12 +239,11 @@ public void LaunchBrowser_WhenNotSpecifyingCleanTarget_IsFalse() [Fact] public void CommandParameters_WhenSpecifyingAllParameters_ResultIsCorrect() { - var args = new List { "-template=jekyll", @"-directory=c:\mysite", "-port=8182", "-import=blogger", "-file=BloggerExport.xml", "-drafts", "-nobrowser", "-withproject", "-wiki", "-cleantarget", "-safe" }; + var args = new List { "-template=jekyll", "-port=8182", "-import=blogger", "-file=BloggerExport.xml", "-drafts", "-nobrowser", "-withproject", "-wiki", "-cleantarget" }; subject.Parse(args); Assert.Equal("jekyll", subject.Template); - Assert.Equal(@"c:\mysite", subject.Path); Assert.Equal(8182, subject.Port); Assert.Equal("blogger", subject.ImportType); Assert.Equal("BloggerExport.xml", subject.ImportPath); @@ -302,8 +252,7 @@ public void CommandParameters_WhenSpecifyingAllParameters_ResultIsCorrect() Assert.True(subject.WithProject); Assert.True(subject.Wiki); Assert.True(subject.CleanTarget); - Assert.True(subject.Safe); - Assert.Equal(@"c:\mysite\_site", subject.DestinationPath); + Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); } [Fact] @@ -316,7 +265,6 @@ public void CommandParameters_WhenSpecifyingNoParameters_DefaultVeluesResultIsCo Assert.Equal(8080, subject.Port); Assert.True(subject.LaunchBrowser); Assert.Null(subject.Template); - Assert.Equal(FileSystem.Directory.GetCurrentDirectory(), subject.Path); Assert.Null(subject.ImportType); Assert.Null(subject.ImportPath); Assert.False(subject.IncludeDrafts); @@ -338,7 +286,7 @@ public void CommandParameters_WhenSpecifyingCommandExtension_ExtensionParameterI options.Add("newOption=", "description", v => NewOption = v); }); - var subject = new CommandParameters(new List { extension }, new MockFileSystem()); + var subject = new CommandParameters(new List { extension }, new MockFileSystem()) { Path = ExpectedPath }; var args = new List { "-newOption=test" }; subject.Parse(args); @@ -348,17 +296,6 @@ public void CommandParameters_WhenSpecifyingCommandExtension_ExtensionParameterI protected string NewOption { get; set; } - [Fact] - public void Parse_WhenOneParameterSet_MapsToPath_RelativePath() - { - var args = new List { "mySite" }; - - subject.Parse(args); - - Assert.Equal(FileSystem.Path.Combine(FileSystem.Directory.GetCurrentDirectory(), "mySite"), subject.Path); - Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); - } - [Fact] public void DetectFromDirectory_WhenSpecifyingNoSiteEngines_DefaultValueIsLiquid() { @@ -450,62 +387,6 @@ public void DetectFromDirectory_WhenSpecifyingPretzelConfigSimpleValue_DefaultVa Assert.Equal("liquid", subject.Template); } - [Fact] - public void LaunchBrowser_WhenSpecifyingSafetDoubleDash_IsTrue() - { - var args = new List { "--safe" }; - subject.Parse(args); - Assert.True(subject.Safe); - } - - [Fact] - public void LaunchBrowser_WhenSpecifyingSafeSingleDash_IsTrue() - { - var args = new List { "-safe" }; - subject.Parse(args); - Assert.True(subject.Safe); - } - - [Fact] - public void LaunchBrowser_WhenNotSpecifyingSafe_IsFalse() - { - var args = new List(); - subject.Parse(args); - Assert.False(subject.Safe); - } - - [Fact] - public void Parse_WhenSpecifyingSourcePathUsingShortParameter_MapsToPath() - { - var args = new List { "--s", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - - [Fact] - public void Parse_WhenSpecifyingSourcePathUsingFullParameter_MapsToPath() - { - var args = new List { "--source", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - - [Fact] - public void Parse_WhenSpecifyingSourcePathUsingShortParameterSingleDash_MapsToPath() - { - var args = new List { "-s", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - - [Fact] - public void Parse_WhenSpecifyingSourcePathUsingFullParameterSingleDash_MapsToPath() - { - var args = new List { "-source", ExpectedPath }; - subject.Parse(args); - Assert.Equal(ExpectedPath, subject.Path); - } - [Fact] public void Parse_WhenSpecifyingDestinationPathUsingFullParameter_MapsToPath() { @@ -527,7 +408,7 @@ public void Parse_WhenNoParametersSet_MapsDestinationPathTo_siteInCurrentDirecto { var args = new List(); subject.Parse(args); - Assert.Equal(FileSystem.Path.Combine(FileSystem.Directory.GetCurrentDirectory(), "_site"), subject.DestinationPath); + Assert.Equal(FileSystem.Path.Combine(subject.Path, "_site"), subject.DestinationPath); } } } diff --git a/src/Pretzel.Tests/Pretzel.Tests.csproj b/src/Pretzel.Tests/Pretzel.Tests.csproj index 2b6753ff3..258f22008 100644 --- a/src/Pretzel.Tests/Pretzel.Tests.csproj +++ b/src/Pretzel.Tests/Pretzel.Tests.csproj @@ -11,11 +11,12 @@ Properties Pretzel.Tests Pretzel.Tests - v4.0 + v4.5 512 ..\..\src\ true 374fc472 + true @@ -25,6 +26,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -33,13 +35,15 @@ TRACE prompt 4 + false ..\packages\dotless.1.4.1.0\lib\dotless.Core.dll - - ..\packages\DotLiquid.1.8.0\lib\NET40\DotLiquid.dll + + False + ..\packages\DotLiquid.1.8.0\lib\NET45\DotLiquid.dll False @@ -47,7 +51,7 @@ False - ..\packages\NSubstitute.1.8.1.0\lib\net40\NSubstitute.dll + ..\packages\NSubstitute.1.8.1.0\lib\net45\NSubstitute.dll @@ -73,8 +77,9 @@ - - + + + diff --git a/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs b/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs index 1440b156e..74b7637cc 100644 --- a/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs +++ b/src/Pretzel.Tests/Templating/Jekyll/LiquidEngineTests.cs @@ -1242,6 +1242,7 @@ public override LiquidEngine Given() { var engine = new LiquidEngine(); engine.Initialize(); + engine.Tags = new List { new PostUrlTag() }; return engine; } diff --git a/src/Pretzel.Tests/app.config b/src/Pretzel.Tests/app.config index 802165d40..34c3bce98 100644 --- a/src/Pretzel.Tests/app.config +++ b/src/Pretzel.Tests/app.config @@ -1,11 +1,11 @@ - + - - + + - \ No newline at end of file + diff --git a/src/Pretzel.Tests/packages.config b/src/Pretzel.Tests/packages.config index 8018eaa4d..40ef33cc6 100644 --- a/src/Pretzel.Tests/packages.config +++ b/src/Pretzel.Tests/packages.config @@ -1,9 +1,9 @@  - + - + diff --git a/src/Pretzel.sln b/src/Pretzel.sln index 407fdf7d1..6c17a4229 100644 --- a/src/Pretzel.sln +++ b/src/Pretzel.sln @@ -11,27 +11,68 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pretzel.Tests", "Pretzel.Te EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5F558191-21D9-40C6-9173-C416DCEFDA21}" ProjectSection(SolutionItems) = preProject + ..\AppVeyor-Build.ps1 = ..\AppVeyor-Build.ps1 + ..\appveyor.yml = ..\appveyor.yml ..\build.proj = ..\build.proj + ..\README.md = ..\README.md EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pretzel.ScriptCs", "Pretzel.ScriptCs\Pretzel.ScriptCs.csproj", "{23308D48-7EBF-4082-BFDA-B62C9404E9C7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Debug|Any CPU.ActiveCfg = Debug|x86 + {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Debug|Mixed Platforms.Build.0 = Debug|x86 {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Debug|x86.ActiveCfg = Debug|x86 {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Debug|x86.Build.0 = Debug|x86 + {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Release|Any CPU.ActiveCfg = Release|x86 + {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Release|Mixed Platforms.Build.0 = Release|x86 {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Release|x86.ActiveCfg = Release|x86 {198E7970-CBF7-4BD8-8E36-4E07BB29C3AF}.Release|x86.Build.0 = Release|x86 + {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|x86.ActiveCfg = Debug|Any CPU {F2E6664D-75AC-4830-8A55-E572027DF710}.Debug|x86.Build.0 = Debug|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|Any CPU.Build.0 = Release|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|Mixed Platforms.Build.0 = Release|Any CPU {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|x86.ActiveCfg = Release|Any CPU {F2E6664D-75AC-4830-8A55-E572027DF710}.Release|x86.Build.0 = Release|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Debug|x86.ActiveCfg = Debug|Any CPU {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Debug|x86.Build.0 = Debug|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Release|Any CPU.Build.0 = Release|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Release|Mixed Platforms.Build.0 = Release|Any CPU {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Release|x86.ActiveCfg = Release|Any CPU {B90C3F82-7B38-49E9-80D5-F9752F7B2C67}.Release|x86.Build.0 = Release|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Debug|x86.ActiveCfg = Debug|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Release|Any CPU.Build.0 = Release|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {23308D48-7EBF-4082-BFDA-B62C9404E9C7}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Pretzel/Commands/BakeCommand.cs b/src/Pretzel/Commands/BakeCommand.cs index 88f4e0c86..f695a4c62 100644 --- a/src/Pretzel/Commands/BakeCommand.cs +++ b/src/Pretzel/Commands/BakeCommand.cs @@ -75,7 +75,7 @@ public void Execute(IEnumerable arguments) public void WriteHelp(TextWriter writer) { - parameters.WriteOptions(writer, "-t", "-p", "-d", "-cleantarget"); + parameters.WriteOptions(writer, "-t", "-p", "-d", "-cleantarget", "-s", "-destination"); } } } diff --git a/src/Pretzel/Commands/RecipeCommand.cs b/src/Pretzel/Commands/RecipeCommand.cs index b6593b705..ae3740f0b 100644 --- a/src/Pretzel/Commands/RecipeCommand.cs +++ b/src/Pretzel/Commands/RecipeCommand.cs @@ -1,13 +1,13 @@ -using System; +using Pretzel.Logic.Commands; +using Pretzel.Logic.Extensibility; +using Pretzel.Logic.Extensions; +using Pretzel.Logic.Recipe; +using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.IO; using System.IO.Abstractions; using System.Linq; -using Pretzel.Logic.Commands; -using Pretzel.Logic.Extensibility; -using Pretzel.Logic.Extensions; -using Pretzel.Logic.Recipe; namespace Pretzel.Commands { @@ -15,12 +15,19 @@ namespace Pretzel.Commands [CommandInfo(CommandName = "create")] public sealed class RecipeCommand : ICommand { - readonly static List TemplateEngines = new List(new[] { "Liquid", "Razor" }); + private static readonly List TemplateEngines = new List(new[] { "Liquid", "Razor" }); #pragma warning disable 649 - [Import] IFileSystem fileSystem; - [Import] CommandParameters parameters; - [ImportMany] IEnumerable additionalIngredients; + + [Import] + private IFileSystem fileSystem; + + [Import] + private CommandParameters parameters; + + [ImportMany] + private IEnumerable additionalIngredients; + #pragma warning restore 649 public void Execute(IEnumerable arguments) @@ -47,7 +54,7 @@ public void Execute(IEnumerable arguments) public void WriteHelp(TextWriter writer) { - parameters.WriteOptions(writer, "-t", "-d", "withproject", "wiki"); + parameters.WriteOptions(writer, "-t", "-d", "withproject", "wiki", "-s"); } } -} \ No newline at end of file +} diff --git a/src/Pretzel/Commands/TasteCommand.cs b/src/Pretzel/Commands/TasteCommand.cs index 8dcddb1cc..f64c86085 100644 --- a/src/Pretzel/Commands/TasteCommand.cs +++ b/src/Pretzel/Commands/TasteCommand.cs @@ -132,7 +132,7 @@ private void WatcherOnChanged(string file) public void WriteHelp(TextWriter writer) { - parameters.WriteOptions(writer, "-t", "-d", "-p", "--nobrowser", "-cleantarget"); + parameters.WriteOptions(writer, "-t", "-d", "-p", "--nobrowser", "-cleantarget", "-s", "-destination"); } } } diff --git a/src/Pretzel/Pretzel.csproj b/src/Pretzel/Pretzel.csproj index 4b0deb4d0..fc7e73a3c 100644 --- a/src/Pretzel/Pretzel.csproj +++ b/src/Pretzel/Pretzel.csproj @@ -10,7 +10,7 @@ Properties Pretzel Pretzel - v4.0 + v4.5 512 @@ -26,6 +26,7 @@ DEBUG;TRACE prompt 4 + false x86 @@ -35,11 +36,15 @@ TRACE prompt 4 + false pretzel.ico + + ..\packages\DotLiquid.1.8.0\lib\NET45\DotLiquid.dll + ..\packages\Firefly.0.6.3\lib\Firefly.dll @@ -61,9 +66,9 @@ ..\packages\System.IO.Abstractions.2.0.0.104\lib\net40\System.IO.Abstractions.dll - + + ..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll True - ..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll @@ -173,5 +178,4 @@ - - + \ No newline at end of file diff --git a/src/Pretzel/Program.cs b/src/Pretzel/Program.cs index 81d6bba70..e7713e5e0 100644 --- a/src/Pretzel/Program.cs +++ b/src/Pretzel/Program.cs @@ -1,10 +1,12 @@ using NDesk.Options; using Pretzel.Commands; using Pretzel.Logic.Commands; +using Pretzel.Logic.Extensibility; using Pretzel.Logic.Extensions; using System; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; +using System.ComponentModel.Composition.Primitives; using System.Diagnostics; using System.IO; using System.IO.Abstractions; @@ -18,39 +20,30 @@ internal class Program [Import] private CommandCollection Commands { get; set; } - private AggregateCatalog catalog; - - private CompositionContainer container; - private static void Main(string[] args) { Tracing.Logger.SetWriter(Console.Out); Tracing.Logger.AddCategory("info"); Tracing.Logger.AddCategory("error"); - var debug = false; - var help = false; - var defaultSet = new OptionSet - { - {"help", "Display help mode", p => help = true}, - {"debug", "Enable debugging", p => debug = true} - }; - defaultSet.Parse(args); + var parameters = BaseParameters.Parse(args, new FileSystem()); - if (debug) + if (parameters.Debug) + { Tracing.Logger.AddCategory("debug"); + } var program = new Program(); Tracing.Info("starting pretzel..."); - program.Compose(); + program.Compose(parameters); - if (help || !args.Any()) + if (parameters.Help || !args.Any()) { - program.ShowHelp(defaultSet); + program.ShowHelp(parameters.Options); return; } - program.Run(args, defaultSet); + program.Run(args, parameters); } private void ShowHelp(OptionSet defaultSet) @@ -59,20 +52,16 @@ private void ShowHelp(OptionSet defaultSet) WaitForClose(); } - private void Run(string[] args, OptionSet defaultSet) + private void Run(string[] args, BaseParameters baseParameters) { - var commandName = args[0]; - var commandArgs = args.Skip(1).ToArray(); - - if (Commands[commandName] == null) + if (Commands[baseParameters.CommandName] == null) { - Console.WriteLine(@"Can't find command ""{0}""", commandName); - Commands.WriteHelp(defaultSet); + Console.WriteLine(@"Can't find command ""{0}""", baseParameters.CommandName); + Commands.WriteHelp(baseParameters.Options); return; } - LoadPlugins(commandArgs); - Commands[commandName].Execute(commandArgs); + Commands[baseParameters.CommandName].Execute(baseParameters.CommandArgs); WaitForClose(); } @@ -90,33 +79,19 @@ public void WaitForClose() } } - private void LoadPlugins(string[] commandArgs) + public void Compose(BaseParameters parameters) { - var parameters = container.GetExport().Value; - parameters.Parse(commandArgs); - - if (!parameters.Safe) + try { - var pluginsPath = Path.Combine(parameters.Path, "_plugins"); + var catalog = new AggregateCatalog(new AssemblyCatalog(Assembly.GetExecutingAssembly())); - if (Directory.Exists(pluginsPath)) - { - catalog.Catalogs.Add(new DirectoryCatalog(pluginsPath)); - } - } - } + LoadPlugins(catalog, parameters); - public void Compose() - { - try - { - var first = new AssemblyCatalog(Assembly.GetExecutingAssembly()); - catalog = new AggregateCatalog(first); - container = new CompositionContainer(catalog); + var container = new CompositionContainer(catalog); var batch = new CompositionBatch(); - batch.AddExportedValue(new FileSystem()); batch.AddPart(this); + batch.AddPart(parameters); container.Compose(batch); } catch (ReflectionTypeLoadException ex) @@ -127,5 +102,52 @@ public void Compose() throw; } } + + private void LoadPlugins(AggregateCatalog catalog, BaseParameters parameters) + { + if (!parameters.Safe) + { + var pluginsPath = Path.Combine(parameters.Path, "_plugins"); + + if (Directory.Exists(pluginsPath)) + { + catalog.Catalogs.Add(new DirectoryCatalog(pluginsPath)); + AddScriptCs(catalog, pluginsPath); + } + } + } + + private void AddScriptCs(AggregateCatalog mainCatalog, string pluginsPath) + { + var pretzelScriptCsPath = Assembly.GetEntryAssembly().Location.Replace("Pretzel.exe", "Pretzel.ScriptCs.dll"); + if (File.Exists(pretzelScriptCsPath)) + { + var pretzelScriptcsAssembly = Assembly.LoadFile(pretzelScriptCsPath); + if (pretzelScriptcsAssembly != null) + { + var factoryType = pretzelScriptcsAssembly.GetType("Pretzel.ScriptCs.ScriptCsCatalogFactory"); + if (factoryType != null) + { + var scriptCsCatalogMethod = factoryType.GetMethod("CreateScriptCsCatalog"); + if (scriptCsCatalogMethod != null) + { + var catalog = (ComposablePartCatalog)scriptCsCatalogMethod.Invoke(null, new object[] { pluginsPath, new[] { typeof(DotLiquid.Tag), typeof(ITag) } }); + mainCatalog.Catalogs.Add(catalog); + } + else + { + Tracing.Debug("Assembly 'Pretzel.ScriptCs.dll' detected and loaded, type 'Pretzel.ScriptCs.ScriptCsCatalogFactory' found but method 'CreateScriptCsCatalog' not found."); + } + } + { + Tracing.Debug("Assembly 'Pretzel.ScriptCs.dll' detected and loaded but type 'Pretzel.ScriptCs.ScriptCsCatalogFactory' not found."); + } + } + else + { + Tracing.Debug("Assembly 'Pretzel.ScriptCs.dll' detected but not loaded."); + } + } + } } } diff --git a/src/Pretzel/app.config b/src/Pretzel/app.config index aebdca3af..06b2e49db 100644 --- a/src/Pretzel/app.config +++ b/src/Pretzel/app.config @@ -1,7 +1,7 @@  - + @@ -18,4 +18,4 @@ - \ No newline at end of file + diff --git a/src/Pretzel/packages.config b/src/Pretzel/packages.config index 26338eadd..beb4a6db4 100644 --- a/src/Pretzel/packages.config +++ b/src/Pretzel/packages.config @@ -1,9 +1,10 @@  + - + diff --git a/tools/chocolatey/Pretzel.ScriptCs/chocolateyInstall.ps1 b/tools/chocolatey/Pretzel.ScriptCs/chocolateyInstall.ps1 new file mode 100644 index 000000000..5def96285 --- /dev/null +++ b/tools/chocolatey/Pretzel.ScriptCs/chocolateyInstall.ps1 @@ -0,0 +1,7 @@ +$packageName = 'Pretzel.ScriptCs' +$url = 'https://github.com/Code52/Pretzel/releases/download/{{tag}}/Pretzel.ScriptCs.{{version}}.zip' + +$binRoot = Get-BinRoot +$pretzelPath = "$binRoot\Pretzel" + +Install-ChocolateyZipPackage "$packageName" "$url" $pretzelPath \ No newline at end of file diff --git a/tools/chocolatey/Pretzel.ScriptCs/chocolateyUninstall.ps1 b/tools/chocolatey/Pretzel.ScriptCs/chocolateyUninstall.ps1 new file mode 100644 index 000000000..8c29fa718 --- /dev/null +++ b/tools/chocolatey/Pretzel.ScriptCs/chocolateyUninstall.ps1 @@ -0,0 +1,10 @@ +Write-Debug "Uninstall Pretzel.ScriptCs" + +$binRoot = Get-BinRoot +$pretzelPath = "$binRoot\Pretzel" + +# Remove folder +If (Test-Path $pretzelPath){ + gc $pretzelPath\Pretzel.ScriptCs.Files.txt | foreach ($_) { If (($_) -And (Test-Path $pretzelPath\$_)) { Remove-Item $pretzelPath\$_ } } + Remove-Item $pretzelPath\Pretzel.ScriptCs.Files.txt +} \ No newline at end of file diff --git a/tools/chocolatey/Pretzel.ScriptCs/pretzel.scriptcs.nuspec b/tools/chocolatey/Pretzel.ScriptCs/pretzel.scriptcs.nuspec new file mode 100644 index 000000000..0ad6616da --- /dev/null +++ b/tools/chocolatey/Pretzel.ScriptCs/pretzel.scriptcs.nuspec @@ -0,0 +1,16 @@ + + + + pretzel.scriptcs + $version$ + Pretzel.ScriptCs + Code52 + Code52 + https://github.com/Code52/pretzel + https://cdn.rawgit.com/Code52/pretzel/master/pretzel.png + https://github.com/Code52/pretzel/blob/master/LICENSE.md + false + An addin for Pretzel allowing to add plugin from a ScriptCs script. + Pretzel ScriptCs plugin + + \ No newline at end of file diff --git a/tools/chocolatey/Pretzel/chocolateyInstall.ps1 b/tools/chocolatey/Pretzel/chocolateyInstall.ps1 new file mode 100644 index 000000000..0fcf033bb --- /dev/null +++ b/tools/chocolatey/Pretzel/chocolateyInstall.ps1 @@ -0,0 +1,8 @@ +$packageName = 'Pretzel' +$url = 'https://github.com/Code52/Pretzel/releases/download/{{tag}}/Pretzel.{{version}}.zip' + +$binRoot = Get-BinRoot +$pretzelPath = "$binRoot\$packageName" + +Install-ChocolateyZipPackage "$packageName" "$url" $pretzelPath +Install-ChocolateyPath $pretzelPath \ No newline at end of file diff --git a/tools/chocolatey/Pretzel/chocolateyUninstall.ps1 b/tools/chocolatey/Pretzel/chocolateyUninstall.ps1 new file mode 100644 index 000000000..a43d90a4f --- /dev/null +++ b/tools/chocolatey/Pretzel/chocolateyUninstall.ps1 @@ -0,0 +1,30 @@ +Write-Debug "Uninstall Pretzel" + +$binRoot = Get-BinRoot +$installDir = Join-Path $binRoot "Pretzel" + +# Remove folder +If (Test-Path $installDir){ + Remove-Item $installDir -Recurse +} + +# Remove path + +#get the PATH variable +$envPath = $env:PATH +$pathType = [System.EnvironmentVariableTarget]::User + +if ($envPath.ToLower().Contains($installDir.ToLower())) +{ + $statementTerminator = ";" + Write-Debug "PATH environment variable contains old pretzel path $installDir. Removing..." + $actualPath = [System.Collections.ArrayList](Get-EnvironmentVariable -Name 'Path' -Scope $pathType).split($statementTerminator) + + $actualPath.Remove($installDir) + $newPath = $actualPath -Join $statementTerminator + + Set-EnvironmentVariable -Name 'Path' -Value $newPath -Scope $pathType + +} else { + Write-Debug " The path to uninstall `'$installDir`' was not found in the `'$pathType`' PATH. Could not remove." +} \ No newline at end of file diff --git a/tools/chocolatey/pretzel.nuspec b/tools/chocolatey/Pretzel/pretzel.nuspec similarity index 77% rename from tools/chocolatey/pretzel.nuspec rename to tools/chocolatey/Pretzel/pretzel.nuspec index 20b439f1a..ecc3da719 100644 --- a/tools/chocolatey/pretzel.nuspec +++ b/tools/chocolatey/Pretzel/pretzel.nuspec @@ -7,8 +7,8 @@ Code52 Code52 https://github.com/Code52/pretzel - https://cdn.rawgit.com/Code52/pretzel/master/pretzel.png - https://github.com/Code52/pretzel/blob/master/LICENSE.md + https://cdn.rawgit.com/Code52/pretzel/master/pretzel.png + https://github.com/Code52/pretzel/blob/master/LICENSE.md false A simple, pluggable site generation tool for .NET developers and Windows users Jekyll Liquid Razor Markdown blog hmtl static site engine diff --git a/tools/chocolatey/chocolateyInstall.ps1 b/tools/chocolatey/chocolateyInstall.ps1 deleted file mode 100644 index 509bf2a22..000000000 --- a/tools/chocolatey/chocolateyInstall.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -$packageName = 'Pretzel' -$url = 'https://github.com/Code52/Pretzel/releases/download/{{tag}}/Pretzel.{{version}}.zip' - -Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" \ No newline at end of file