Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. . .\go-helpers
  2.  
  3. $arguments = $args
  4. $default_launch_profile = "Development"
  5.  
  6. function clean {
  7. info "Cleaning build artifacts"
  8. exec {dotnet clean src -v minimal /nologo}
  9. }
  10.  
  11. function build {
  12. info "Building solution"
  13. exec {dotnet build src /nologo}
  14. }
  15.  
  16. function rebuild {
  17. clean
  18. build
  19. }
  20.  
  21. function run {
  22. $project = $arguments[1]
  23. $parameter = argrest $arguments 2
  24.  
  25. if (!$project) {
  26. error "You must specify which project to run."
  27. return
  28. }
  29.  
  30. info "Running project '$project' with additional parameters '$parameter'"
  31. exec {dotnet run --project "src/$project" --launch-profile "$default_launch_profile" "$parameter"}
  32. }
  33.  
  34. function run-async {
  35. run-self-async "run" (argrest $arguments 1)
  36. }
  37.  
  38. function run-all {
  39. build
  40.  
  41. run-self-async "run" "BotsPotsChef" "--no-build" "--no-restore"
  42. run-self-async "run" "BotsPotsKonzola" "--no-build" "--no-restore"
  43. run-self-async "run" "VirtualRobot" "--no-build" "--no-restore"
  44. }
  45.  
  46. function watch {
  47. $project = $arguments[1]
  48. $parameter = argrest $arguments 2
  49.  
  50. if (!$project) {
  51. error "You must specify which project to run and watch."
  52. return
  53. }
  54.  
  55. info "Running and watching project '$project' with additional parameters '$parameter'"
  56. exec {dotnet watch --project src/$project run --launch-profile "$default_launch_profile" "$parameter"}
  57. }
  58.  
  59. function watch-async {
  60. run-self-async "watch" (argrest $arguments 1)
  61. }
  62.  
  63. function mig {
  64. $sub_command = $arguments[1]
  65.  
  66. function drop {
  67. info "Dropping database"
  68. execute
  69. }
  70.  
  71. function rerun {
  72. info "Recreating database and running database migrations"
  73. execute
  74. }
  75.  
  76. function run {
  77. info "Running database migrations"
  78. execute
  79. }
  80.  
  81. function rollback {
  82. info "Rolling back database migrations"
  83. execute
  84. }
  85.  
  86. function execute {
  87. $parameter = argrest $arguments 2
  88. exec {dotnet run --project src/DatabaseMigrations --launch-profile "$default_launch_profile" -- $sub_command "$parameter"}
  89. }
  90.  
  91. function add {
  92. $now = [System.DateTime]::UtcNow;
  93. $migration_name = argrest $arguments 2
  94.  
  95. if ($migration_name -match " ") {
  96. $migration_name = (Get-Culture).TextInfo.ToTitleCase($migration_name).Replace(" ", "")
  97. }
  98.  
  99. $migration_filename = $now.ToString("yyyy.MM.dd_HH.mm")
  100. $migration_file_path = "src/DatabaseMigrations/Migrations/${migration_filename}_$migration_name.cs"
  101.  
  102. if ([System.IO.File]::Exists($migration_file_path)) {
  103. error "Migration file '$migration_file_path' already exists"
  104. } else {
  105. $template_substitutions = @{
  106. MigrationName = $migration_name
  107. MigrationVersion = $now.ToString("yyyy_MM_dd, HH_mm, ss_fff")
  108. }
  109.  
  110. generate-from-template "src/Migration.cs.template" $migration_file_path $template_substitutions
  111.  
  112. info @"
  113. Successfully added new migration at '$migration_file_path'.
  114.  
  115. By default, newly added migration is configured to automatically try to provide migration rollback logic.
  116. If you want to create a forward-only migration, change the migration base class from AutoReversingMigration to ForwardOnlyMigration.
  117. If you want to manually provide rollback logic, change the base class to Migration and override the Down method.
  118. "@
  119. }
  120. }
  121.  
  122. &$sub_command
  123. }
  124.  
  125. function publish {
  126. info "Deleting 'publish' folder"
  127. remove-folder "./publish"
  128.  
  129. info "Publishing to 'publish' folder"
  130.  
  131. exec {dotnet publish src/BotsPotsChef -c Release -f net461 --self-contained true -o ./publish/BotsPotsChef /nologo}
  132. exec {dotnet publish src/BotsPotsKonzola -c Release -f net461 --self-contained true -o ./publish/BotsPotsKonzola /nologo}
  133.  
  134. info "Packaging BotsBotsChef web application to zip file"
  135. Compress-Archive -Path ./publish/BotsPotsChef/* -DestinationPath ./publish/BotsPotsChef_Publish
  136. }
  137.  
  138. function go {
  139. rebuild
  140. migrate
  141. }
  142.  
  143. main {
  144. $command = $arguments[0]
  145.  
  146. if ($command) {
  147. &$command
  148. } else {
  149. info @"
  150. Available commands:
  151. go
  152.  
  153. clean
  154. build
  155. rebuild
  156.  
  157. run
  158. run-async
  159. run-all
  160.  
  161. watch
  162. watch-async
  163.  
  164. mig run
  165. mig rerun
  166. mig rollback
  167. mig drop
  168. mig add
  169.  
  170. publish
  171. "@
  172. }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement