public PackageConfig(Config config, string packageName) { PackageName = packageName; this.config = config; PackageDirectory = Path.Combine(config.DestinationDirectory, packageName); ContentDirectory = Path.Combine(PackageDirectory, "content"); LibDirectory = Path.Combine(PackageDirectory, "lib"); ToolsDirectory = Path.Combine(PackageDirectory, "tools"); }
static void Main(string[] args) { var config = new Config(); var p = new OptionSet() { { "s|source=", "the source {dir} of the templated project.", v => config.SourceDirectory = v }, { "d|destination=", "the destination {dir} of the outputted NuGet directories", v => config.DestinationDirectory = v }, { "c|config=", "the config {dir} which contains your nuspec files.", v => config.ConfigDirectory = v }, { "h|help", "show this message and exit", v => config.ShowHelp =( v != null )}, { "x|execute=", "execute {NuGet.exe} when creation is complete", v => config.ExecutePath = v } }; List<string> extra; try { extra = p.Parse(args); DisplayBanner(); Console.ForegroundColor = ConsoleColor.Red; if (config.IsValid() == false) { config.ShowHelp = true; } Console.ResetColor(); if (config.ShowHelp) { p.WriteOptionDescriptions(Console.Out); return; } var factory = new PackageFactory(); factory.Build(config); } catch (OptionException e) { Console.Write("OnRamper: "); p.WriteOptionDescriptions(Console.Out); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(e.Message); Console.ResetColor(); return; } }
private void MoveContentInPlace(List<string> selectedContent, PackageConfig pconfig, Config config) { foreach (string item in selectedContent) { var pathFragment = item.Replace(config.SourceDirectory, "").TrimStart('/', '\\'); var destFile = Path.Combine(pconfig.ContentDirectory, pathFragment); string destDirectory = Path.GetDirectoryName(destFile); if (Directory.Exists(destDirectory) == false) Directory.CreateDirectory(destDirectory); using (var rdr = new StreamReader(item)) { string itemExtension = Path.GetExtension(item); if (xmlExtensions.Contains(itemExtension.ToLower())) WriteXmlTransform(destFile, rdr, pconfig, config); else WritePartialFile(destFile, rdr); } } }
public void Build(Config config) { xmlExtensions = new List<string> { ".xml", ".config" }; var configFiles = Directory.GetFiles(config.ConfigDirectory, "*.nuspec"); foreach (var file in configFiles) { var packageName = Path.GetFileNameWithoutExtension(file); var pconfig = new PackageConfig(config, packageName); // Create all the package directories we'll need pconfig.Ensure(); // Move in the nuspec file string nuspecFile = Path.Combine(pconfig.PackageDirectory, Path.GetFileName(file)); File.Copy(file, nuspecFile, true); // Recurse the directories, looking for files which opted into the package var selectedContent = new List<string>(); FilterForFiles(config.SourceDirectory, selectedContent, packageName); // Announce the files AnnounceFiles(pconfig, selectedContent); // Move files from source to destination content MoveContentInPlace(selectedContent, pconfig, config); // Optionally execute NuGet.exe if (config.ShouldExecute) { string args = string.Format(" pack \"{0}\" -o \"{1}\"", Path.GetFullPath(nuspecFile), Path.GetFullPath(config.DestinationDirectory).TrimEnd('\\')); Console.WriteLine(Path.GetFullPath(config.ExecutePath) + " " + args); var p = Process.Start(Path.GetFullPath(config.ExecutePath), args); p.OutputDataReceived += p_OutputDataReceived; p.Start(); p.WaitForExit(); } } }
private void WriteXmlTransform(string destFile, StreamReader rdr, PackageConfig pconfig, Config config) { destFile += ".transform"; var content = rdr.ReadToEnd(); var cExaminer = new ConfigExaminer(); var xDoc = cExaminer.Populate(pconfig.PackageName, content); xDoc.Save(destFile); }