generated from Patitotective/ImTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nakefile.nim
70 lines (58 loc) · 2.37 KB
/
nakefile.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import std/[strformat, sequtils, os]
import nake
import niprefs
const configPath = "config.toml"
const desktop = """
[Desktop Entry]
Name=$name
Exec=AppRun
Comment=$comment
Icon=$name
Type=Application
Categories=$categories
X-AppImage-Name=$name
X-AppImage-Version=$version
X-AppImage-Arch=$arch
"""
let config {.compileTime.} = Toml.decode(static(slurp(configPath)), TomlValueRef)
const name = config["name"].getString()
const version = config["version"].getString()
let arch = if existsEnv("ARCH"): getEnv("ARCH") else: "amd64"
let appimagePath = &"{name}-{version}-{arch}.AppImage"
task "build", "Build AppImage":
discard existsOrCreateDir("AppDir")
if "AppDir/AppRun".needsRefresh("main.nim"):
shell "FLAGS=\"--out:AppDir/AppRun -d:appimage\" nimble buildApp"
writeFile(
&"AppDir/{name}.desktop",
desktop % [
"name", name,
"categories", config["categories"].getArray().mapIt(it.getString()).join(";"),
"version", config["version"].getString(),
"comment", config["comment"].getString(),
"arch", arch
]
)
copyFile(config["iconPath"].getString(), "AppDir/.DirIcon")
copyFile(config["svgIconPath"].getString(), &"AppDir/{name}.svg")
if "appstreamPath" in config:
createDir("AppDir/usr/share/metainfo")
copyFile(config["appstreamPath"].getString(), &"AppDir/usr/share/metainfo/{name}.appdata.xml")
var appimagetoolPath = "appimagetool"
if not silentShell("Checking for appimagetool", appimagetoolPath, "--help"):
appimagetoolPath = "./appimagetool-x86_64.AppImage"
if not fileExists(appimagetoolPath):
direSilentShell &"Dowloading {appimagetoolPath}", "wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage -O ", appimagetoolPath
shell "chmod +x", appimagetoolPath
if "ghRepo" in config:
echo "Building updateable AppImage"
let ghInfo = config["ghRepo"].getString().split('/')
direShell appimagetoolPath, "-u", &"\"gh-releases-zsync|{ghInfo[0]}|{ghInfo[1]}|latest|{name}-*-{arch}.AppImage.zsync\"", "AppDir", appimagePath
else:
echo &"ghRepo key not in {configPath}. Skipping updateable AppImage"
direShell appimagetoolPath, "AppDir", appimagePath
task "run", "Build and run AppImage":
if "AppDir/AppRun".needsRefresh("main.nim"):
runTask("build")
shell &"chmod a+x {appimagePath}" # Make it executable
shell &"./{appimagePath}"