BaseTasks.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using static CakeScript.Startup;
  6. using static CakeScript.CakeAPI;
  7. namespace CakeScript
  8. {
  9. partial class Program
  10. {
  11. bool IsDemo = true;
  12. bool IsRelease = false;
  13. bool IsProfessional = false;
  14. bool IsDebug = false;
  15. string config = Argument("config", "Debug");
  16. string solutionDirectory = Argument("solution-directory", "");
  17. readonly string solutionFilename = Argument("solution-filename", "FastReport.Compat.sln");
  18. readonly string version = Argument("vers", "1.0.0.0");
  19. string outdir = Argument("out-dir", "");
  20. public Program(string[] args)
  21. {
  22. }
  23. public void Init()
  24. {
  25. IsDebug = config.ToLower() == "debug";
  26. IsDemo = config.ToLower() == "demo";
  27. IsRelease = config.ToLower() == "release";
  28. IsProfessional = config.ToLower() == "professional";
  29. Information($"CONFIG: {config}");
  30. }
  31. [DependsOn(nameof(Init))]
  32. public void Prepare()
  33. {
  34. if (String.IsNullOrWhiteSpace(solutionDirectory))
  35. {
  36. var dir = Directory.GetCurrentDirectory();
  37. try
  38. {
  39. for (int i = 0; i < 7; i++)
  40. {
  41. var find_path = Path.Combine(dir, solutionFilename);
  42. if (File.Exists(find_path))
  43. {
  44. solutionDirectory = dir;
  45. break;
  46. }
  47. dir = Path.GetDirectoryName(dir);
  48. }
  49. }
  50. catch
  51. {
  52. }
  53. }
  54. if (String.IsNullOrWhiteSpace(solutionDirectory))
  55. throw new FileNotFoundException($"File `{solutionFilename}` was not found!");
  56. solutionDirectory = Path.GetFullPath(solutionDirectory);
  57. if (!solutionDirectory.EndsWith(Path.DirectorySeparatorChar.ToString()))
  58. solutionDirectory += Path.DirectorySeparatorChar.ToString();
  59. Information($"solutionDirectory: {solutionDirectory}");
  60. }
  61. [DependsOn(nameof(Prepare))]
  62. public void PrepareNuget()
  63. {
  64. if (String.IsNullOrWhiteSpace(outdir))
  65. {
  66. outdir = Path.Combine(solutionDirectory, "fr_nuget");
  67. }
  68. else if (!Path.IsPathRooted(outdir))
  69. {
  70. outdir = Path.Combine(solutionDirectory, outdir);
  71. }
  72. if (!Directory.Exists(outdir))
  73. Directory.CreateDirectory(outdir);
  74. Information($"outdir: {outdir}");
  75. }
  76. public static void Default()
  77. {
  78. Information("Use: ");
  79. Information(" --name=value");
  80. Information("");
  81. Information("|> --target= - change task, see the task with command cake --tree. Core, Plugins, Test-Connectors.");
  82. Information("|> --config= - change config. Debug, Release, Demo.");
  83. Information("|> --vers= - change version");
  84. Information("|> --solution-directory= - change solution directory");
  85. Information("|> --solution-filename= - change solution file name");
  86. Information("|> --out-dir= - change output dir for packages");
  87. Information("");
  88. Information("OR: if you want to run 'Debug' mode, please add [Debug] attribute to your method");
  89. }
  90. }
  91. }