build.ps1 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Usage: ./scripts/build.ps1
  2. # This is only for local builds.
  3. # For development, setup a proper environment as described here:
  4. # https://github.com/usememos/memos/blob/main/docs/development.md
  5. $projectRoot = (Resolve-Path "$MyInvocation.MyCommand.Path/..").Path
  6. Write-Host "Project root: $projectRoot"
  7. Write-Host "Building frontend..." -f Magenta
  8. Set-Location "$projectRoot/web"
  9. npm install -g pnpm
  10. pnpm i --frozen-lockfile
  11. pnpm build
  12. Write-Host "Backing up frontend placeholder..." -f Magenta
  13. Move-Item "$projectRoot/server/dist" "$projectRoot/server/dist.bak" -Force -ErrorAction Stop
  14. Write-Host "Moving frontend build to /server/dist ..." -f Magenta
  15. Move-Item "$projectRoot/web/dist" "$projectRoot/server/" -Force -ErrorAction Stop
  16. Set-Location $projectRoot
  17. Write-Host "Building backend..." -f Magenta
  18. go build -o ./build/memos.exe ./main.go
  19. Write-Host "Backend built!" -f green
  20. Write-Host "Removing frontend from /server/dist ..." -f Magenta
  21. Remove-Item "$projectRoot/server/dist" -Recurse -Force -ErrorAction SilentlyContinue
  22. Write-Host "Restoring frontend placeholder..." -f Magenta
  23. Move-Item "$projectRoot/server/dist.bak" "$projectRoot/server/dist" -Force -ErrorAction Stop
  24. Write-Host "You can test the build with ./build/memos.exe --mode demo" -f Green
  25. Set-Location -Path $projectRoot