Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
3f82729e
Unverified
Commit
3f82729e
authored
Aug 16, 2023
by
Lincoln Nogueira
Committed by
GitHub
Aug 16, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update build scripts (#2150)
update developer build scripts, bringing feature parity between platforms.
parent
077cfeb8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
277 additions
and
28 deletions
+277
-28
build.ps1
scripts/build.ps1
+132
-22
build.sh
scripts/build.sh
+145
-6
No files found.
scripts/build.ps1
View file @
3f82729e
#
Usage: ./scripts/build.ps1
#
This script builds memos
for
all listed platforms.
#
This i
s only for local builds.
#
It'
s only for local builds.
# For development, setup a proper environment as described here:
# Before using, setup a proper development environment as described here:
# https://github.com/usememos/memos/blob/main/docs/development.md
# * https://usememos.com/docs/contribution/development
# * https://github.com/usememos/memos/blob/main/docs/development.md
$projectRoot
=
(
Resolve-Path
"
$MyInvocation
.MyCommand.Path/.."
)
.Path
# Requirements:
Write-Host
"Project root:
$projectRoot
"
# * go
# * node.js
# * npm
Write-Host
"Building frontend..."
-f Magenta
# Usage:
Set-Location
"
$projectRoot
/web"
# ./scripts/build.ps1
npm
install
-g pnpm
#
# Output: ./build/memos-<os>-<arch>[.exe]
$goBuilds
=
@
(
# "darwin/amd64"
# "darwin/arm64"
# "linux/amd64"
# "linux/arm64"
"windows/amd64"
)
$ldFlags
=
@
(
"-s"
# Omit symbol table and debug information
"-w"
# Omit DWARF symbol table
)
##
foreach
(
$dir
in
@
(
"."
,
"../"
))
{
if
(
Test-Path
(
Join-Path
$dir
".gitignore"
))
{
$repoRoot
=
(
Resolve-Path
$dir
)
.Path
break
}
}
if
([
string
]
::IsNullOrWhiteSpace
(
$repoRoot
))
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not find repository root."
Exit
1
}
Write-Host
"Repository root: "
-NoNewline
Write-Host
$repoRoot
-f Blue
Set-Location
"
$repoRoot
/web"
if
(
-not
(
Get-Command pnpm -ErrorAction SilentlyContinue
))
{
Write-Host
"Installing pnpm..."
-f DarkYellow
npm
install
-g pnpm
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not install pnpm. See above."
Exit
1
}
}
Write-Host
"
`n
Installing frontend dependencies..."
-f DarkYellow
pnpm i --frozen-lockfile
pnpm i --frozen-lockfile
pnpm build
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not install frontend dependencies. See above."
Exit
1
}
Write-Host
"Frontend dependencies installed!"
-f green
Write-Host
"
`n
Building frontend..."
-f DarkYellow
$frontendTime
=
Measure-Command
{
&pnpm build | Out-Host
}
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not build frontend. See above."
Exit
1
}
else
{
Write-Host
"Frontend built!"
-f green
}
Write-Host
"
`n
Backing up frontend placeholder..."
-f Magenta
Move-Item
"
$repoRoot
/server/dist"
"
$repoRoot
/server/dist.bak"
-Force -ErrorAction Stop
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not backup frontend placeholder. See above."
Exit
1
}
Write-Host
"Backing up frontend placeholder..."
-f Magenta
Write-Host
"Moving frontend build to ./server/dist..."
-f Magenta
Move-Item
"
$projectRoot
/server/dist"
"
$projectRoot
/server/dist.bak"
-Force -ErrorAction Stop
Move-Item
"
$repoRoot
/web/dist"
"
$repoRoot
/server/"
-Force -ErrorAction Stop
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not move frontend build to /server/dist. See above."
Exit
1
}
Write-Host
"Moving frontend build to /server/dist ..."
-f Magenta
Set-Location
$repoRoot
Move-Item
"
$projectRoot
/web/dist"
"
$projectRoot
/server/"
-Force -ErrorAction Stop
Write-Host
"
`n
Building backend..."
-f DarkYellow
Set-Location
$projectRoot
$backendTime
=
Measure-Command
{
foreach
(
$build
in
$goBuilds
)
{
$os
,
$arch
=
$build
.Split
(
"/"
)
$Env
:CGO_ENABLED
=
0
$Env
:GOOS
=
$os
$Env
:GOARCH
=
$arch
Write-Host
"Building backend..."
-f Magenta
$output
=
[
IO.Path]::Combine
(
$repoRoot
,
"build"
,
"memos-
$os
-
$arch
"
)
go build -o ./build/memos.exe ./main.go
if
(
$os
-eq
"windows"
)
{
$output
+
=
".exe"
}
Write-Host
"Building
$os
/
$arch
to
$output
..."
-f Blue
&go build -trimpath -o
$output
-ldflags
=
"
$(
$ldFlags
-join
" "
)
"
./main.go | Out-Host
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"'go build' failed for
$build
(
$outputBinary
)!. See above."
continue
}
}
}
Write-Host
"Backend built!"
-f green
Write-Host
"Backend built!"
-f green
Write-Host
"Removing frontend from /server/dist ..."
-f Magenta
Write-Host
"
`n
Frontend build took
$(
$frontendTime
.TotalSeconds
)
seconds."
-f Cyan
Remove-Item
"
$projectRoot
/server/dist"
-Recurse -Force -ErrorAction SilentlyContinue
Write-Host
"Backend builds took
$(
$backendTime
.TotalSeconds
)
seconds."
-f Cyan
Write-Host
"
`n
Removing frontend from ./server/dist ..."
-f Magenta
Remove-Item
"
$repoRoot
/server/dist"
-Recurse -Force -ErrorAction SilentlyContinue
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not remove frontend from /server/dist. See above."
Exit
1
}
Write-Host
"Restoring frontend placeholder..."
-f Magenta
Write-Host
"Restoring frontend placeholder..."
-f Magenta
Move-Item
"
$projectRoot
/server/dist.bak"
"
$projectRoot
/server/dist"
-Force -ErrorAction Stop
Move-Item
"
$repoRoot
/server/dist.bak"
"
$repoRoot
/server/dist"
-Force -ErrorAction Stop
if
(!
$?
)
{
Write-Host
-BackgroundColor red -ForegroundColor white
"Could not restore frontend placeholder. See above."
Exit
1
}
Write-Host
"
`n
Builds:"
-f White
foreach
(
$build
in
$goBuilds
)
{
$output
=
[
IO.Path]::Combine
(
$repoRoot
,
"build"
,
"memos-
$os
-
$arch
"
)
if
(
$os
-eq
"windows"
)
{
$output
=
"
$output
.exe"
}
Write-Host
$output
-f White
}
Write-Host
"You can test the build with ./build/memos.exe --mode demo"
-f Green
Write-Host
-f Green
"
`n
You can test the build with"
-NoNewline
Write-Host
-f White
"
`
./build/memos-<os>-<arch>"
-NoNewline
Write-Host
-f DarkGray
"
`.
exe"
-NoNewline
Write-Host
-f White
" --mode demo"
Set-Location
-Path
$projectRoot
Set-Location
-Path
$repoRoot
\ No newline at end of file
scripts/build.sh
View file @
3f82729e
#!/bin/bash
#!/bin/bash
# This script builds memos for all listed platforms.
# It's only for local builds.
# Usage: ./scripts/build.sh
# Before using, setup a proper development environment as described here:
# * https://usememos.com/docs/contribution/development
# * https://github.com/usememos/memos/blob/main/docs/development.md
set
-e
# Requirements:
# * go
# * node.js
# * npm
cd
"
$(
dirname
"
$0
"
)
/../"
# Usage:
# chmod +x ./scripts/build.sh
# ./scripts/build.sh
#
# Output: ./build/memos-<os>-<arch>[.exe]
echo
"Start building backend..."
goBuilds
=(
# "darwin/amd64"
# "darwin/arm64"
"linux/amd64"
# "linux/arm64"
# "windows/amd64"
)
ldFlags
=(
"-s"
# Omit symbol table and debug information
"-w"
# Omit DWARF symbol table
)
go build
-o
./build/memos ./main.go
##
echo
"Backend built!"
find_repo_root
()
{
# Usage: find_repo_root <file_at_root> <dir1> <dir2> ...
local
looking_for
=
"
${
1
:-
".gitignore"
}
"
shift
local
default_dirs
=(
"."
"../"
)
local dirs
=(
"
${
@
:-${
default_dirs
[@]
}}
"
)
for
dir
in
"
${
dirs
[@]
}
"
;
do
if
[
-f
"
$dir
/
$looking_for
"
]
;
then
echo
$(
realpath
"
$dir
"
)
return
fi
done
}
repo_root
=
$(
find_repo_root
)
if
[
-z
"
$repo_root
"
]
;
then
echo
-e
"
\0
33[0;31mRepository root not found! Exiting.
\0
33[0m"
exit
1
else
echo
-e
"Repository root:
\0
33[0;34m
$repo_root
\0
33[0m"
fi
cd
"
$repo_root
/web"
if
!
command
-v
pnpm &> /dev/null
then
echo
-e
"
\n\0
33[35mInstalling pnpm...
\0
33[0m"
npm
install
-g
pnpm
if
[
$?
-ne
0
]
;
then
echo
-e
"
\0
33[0;31mFailed to install pnpm! Exiting.
\0
33[0m"
exit
1
fi
fi
echo
-e
"
\n\0
33[33mInstalling frontend dependencies...
\0
33[0m"
pnpm i
--frozen-lockfile
if
[
$?
-ne
0
]
;
then
echo
-e
"
\0
33[0;31mFrontend dependencies failed to install! Exiting.
\0
33[0m"
exit
1
fi
echo
-e
"
\0
33[32mFrontend dependencies installed!
\0
33[0m"
echo
-e
"
\n\0
33[33mBuilding frontend...
\0
33[0m"
pnpm build
if
[
$?
-ne
0
]
;
then
echo
-e
"
\0
33[0;31mFrontend build failed! Exiting.
\0
33[0m"
exit
1
fi
echo
-e
"
\0
33[32mFrontend built!
\0
33[0m"
cd
$repo_root
echo
-e
"
\n\0
33[35mBacking up frontend placeholder...
\0
33[0m"
mv
-f
"
$repo_root
/server/dist"
"
$repo_root
/server/dist.bak"
if
[
$?
-ne
0
]
;
then
echo
-e
"
\0
33[0;31mFailed to backup frontend placeholder! Exiting.
\0
33[0m"
exit
1
fi
echo
-e
"
\0
33[35mMoving frontend build to ./server/dist...
\0
33[0m"
mv
-f
"
$repo_root
/web/dist"
"
$repo_root
/server/"
if
[
$?
-ne
0
]
;
then
echo
-e
"
\0
33[0;31mFailed to move frontend build! Exiting.
\0
33[0m"
exit
1
fi
cd
"
$repo_root
"
echo
-e
"
\n\0
33[33mBuilding backend...
\0
33[0m"
for
build
in
"
${
goBuilds
[@]
}
"
;
do
os
=
$(
echo
$build
|
cut
-d
'/'
-f1
)
arch
=
$(
echo
$build
|
cut
-d
'/'
-f2
)
output
=
"
$repo_root
/build/memos-
$os
-
$arch
"
if
[
"
$os
"
=
"windows"
]
;
then
output
=
"
$output
.exe"
fi
CGO_ENABLED
=
0
GOOS
=
$os
GOARCH
=
$arch
go build
-trimpath
-ldflags
=
"
${
ldFlags
[*]
}
"
-o
"
$output
"
./main.go
echo
-e
"
\0
33[34mBuilding
$os
/
$arch
to
$output
...
\0
33[0m"
GOOS
=
$os
GOARCH
=
$arch
go build
-ldflags
=
"
${
ldFlags
[*]
}
"
-o
"./build/memos-
$os
-
$arch
"
./main.go
if
[
$?
-ne
0
]
;
then
echo
-e
"
\0
33[0;31mgo build failed for
$os
/
$arch
(
$output
)! See above.
\0
33[0m"
fi
done
echo
-e
"
\0
33[32mBackend built!
\0
33[0m"
echo
-e
"
\n\0
33[35mRemoving frontend from ./server/dist...
\0
33[0m"
rm
-rf
$repo_root
/server/dist
if
[
$?
-ne
0
]
then
echo
-e
"
\0
33[93mCould not remove frontend from /server/dist.
\0
33[0m"
exit
1
fi
echo
-e
"
\0
33[35mRestoring frontend placeholder...
\0
33[0m"
mv
$repo_root
/server/dist.bak
$repo_root
/server/dist
if
[
$?
-ne
0
]
then
echo
-e
"
\0
33[93mCould not restore frontend placeholder.
\0
33e[0m"
exit
1
fi
echo
-e
"
\n\0
33[37mBuilds:
\0
33[0m"
for
build
in
"
${
goBuilds
[@]
}
"
;
do
os
=
$(
echo
$build
|
cut
-d
'/'
-f1
)
arch
=
$(
echo
$build
|
cut
-d
'/'
-f2
)
output
=
"
$repo_root
/build/memos-
$os
-
$arch
"
if
[
"
$os
"
=
"windows"
]
;
then
output
=
"
$output
.exe"
fi
echo
-e
"
\0
33[37m
$output
\0
33[0m"
done
echo
-e
"
\n\0
33[32mYou can test the build with
\0
33[37m./build/memos-<os>-<arch>
\0
33[0m
\0
33[90m.exe
\0
33[0m
\0
33[37m--mode demo
\0
33[0m"
cd
$repo_root
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment