Guest User

Untitled

a guest
May 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. # This script allows to maintain a github hosted page
  2. # First: make sure to clone or init your git in the destination directory
  3. # this script will make a backup of the .git directory
  4. # once vuepress has built again (replacing all things in destination directory)
  5. # this script will restore the original .git directory
  6. # Finally you can git add . & commit as you wish
  7. # so .git directory will always be the latest one
  8.  
  9. cls
  10. Write-Host "Vuepress git tool v1.0"
  11. Write-Host "Author: vhanla"
  12.  
  13. function Show-Menu {
  14. param(
  15. [string]$Title = 'Options'
  16. )
  17. Write-Host "================== $Title =================="
  18.  
  19. Write-Host "1: Develop."
  20. Write-Host "2: Build."
  21. Write-Host "3: Deploy."
  22. # Write-Host "Q: Quit."
  23. }
  24.  
  25. function Is-Root {
  26. if(Test-Path -Path ($PWD.Path + '\.vuepress')){
  27. return $true
  28. }
  29. else {
  30. Write-Host 'Wrong directory!'
  31. return $false
  32. }
  33. }
  34.  
  35. function Config-Exists {
  36. if(Test-Path ($PWD.Path + '.\.vuepress\config.js')){
  37. return $true
  38. }
  39. else {
  40. return $false
  41. }
  42. }
  43.  
  44. function Copy-ToEmptyDir($source, $dest){
  45. Delete-Dir $dest
  46.  
  47. if (Test-Path $source){
  48. Create-Dir $dest
  49. Copy-Item $source\* $dest -Recurse -Force
  50. return $true
  51. }else{
  52. Write-Host 'Warning! no GIT repository in ' $source
  53. return $false
  54. }
  55. }
  56.  
  57. function Delete-Dir ($dir){
  58. if(Test-Path $dir){
  59. Get-ChildItem -Path $dir -Force -Recurse | Remove-Item -Force -Recurse
  60. Remove-Item $dir -Force
  61. }
  62. }
  63.  
  64. function Create-Dir ($dir){
  65. New-Item -ItemType Directory -Force -Path $dir
  66. }
  67.  
  68. function Get-DistDir {
  69. # assume it is on root path
  70. if (Config-Exists){
  71. $config = Get-Content -Path ($PWD.Path + '.\.vuepress\config.js')
  72. $json = $config -replace '^(\s)*module.exports(\s)*=(\s)*'
  73. $dist = ''
  74. $dist = (((($json -match '(,)*(\s)*dest(.)*(,)*') -replace '(,)*(\s)*dest(\s)*:') -replace ',').Trim() -replace "'") -replace '"'
  75. if (!$dist.Trim()){
  76. # we should use the default .vuepress/dist folder
  77. $dist = $PWD.Path + '\.vuepress\dist'
  78. }
  79. else{
  80. $dist = $PWD.Path + '\' + $dist
  81. }
  82. return $dist
  83. }
  84. else{
  85. return ($PWD.Path + '\.vuepress\dist')
  86. }
  87. }
  88. function Copy-GitDir {
  89. if (Is-Root){
  90. $dest = Get-DistDir
  91. # we need to copy .git directory, the other files don't matter
  92. Copy-ToEmptyDir ($dest + '\.git') ($PWD.Path + '\.vuepress\git')
  93. Delete-Dir $dest
  94. }
  95. }
  96. function Restore-GitDir {
  97. if (Is-Root){
  98. $dest = Get-DistDir
  99. Copy-ToEmptyDir ($PWD.Path + '\.vuepress\git') ($dest + '\.git')
  100. }
  101. }
  102.  
  103. # do{
  104. Show-Menu
  105. $input = Read-Host "Please make a selection"
  106. switch ($input) {
  107. '1' {
  108. cls
  109. vuepress dev
  110. }
  111. '2' {
  112. Copy-GitDir
  113. vuepress build
  114. Restore-GitDir
  115. }
  116. '3' {
  117. $location = Get-DistDir
  118. Set-Location -Path $location
  119. }
  120. 'q' {
  121. return
  122. }
  123. }
  124. # }
  125. # until ($input -eq 'q')
Add Comment
Please, Sign In to add comment