generated from Patitotective/ImTemplate
-
Notifications
You must be signed in to change notification settings - Fork 79
/
nakefile.nim
91 lines (74 loc) · 2.89 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import std/[strformat, sequtils, os]
import nake
import zippy/ziparchives
import niprefs
const configPath = "config.toml"
const binDir = "bin"
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 = fmt"{name}-{version}-{arch}.AppImage"
proc buildWindows() =
let outDir = fmt"{name}-{version}"
createDir outDir
shell fmt"set FLAGS=""--outdir:{outDir}"" && nimble buildBin"
for kind, path in walkDir(binDir):
if kind == pcFile:
copyFileToDir(path, outDir)
createZipArchive(outDir & "/", outDir & ".zip")
proc buildAppImage() =
discard existsOrCreateDir("AppDir")
if "AppDir/AppRun".needsRefresh("main.nim"):
shell "FLAGS=\"--out:AppDir/AppRun -d:appimage\" nimble buildBin"
writeFile(
fmt"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(), fmt"AppDir/{name}.svg")
if "appstreamPath" in config:
createDir("AppDir/usr/share/metainfo")
copyFile(config["appstreamPath"].getString(), fmt"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 fmt"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 fmt"ghRepo key not in {configPath}. Skipping updateable AppImage"
direShell appimagetoolPath, "AppDir", appimagePath
task "build", "Build the AppImage/Exe":
# let winBuild = existsEnv("BUILD") and getEnv("BUILD") == "WIN"
when defined(Windows):
buildWindows()
else:
buildAppImage()
task "run", "Build and run the AppImage":
if "AppDir/AppRun".needsRefresh("main.nim"):
runTask("build")
shell fmt"chmod a+x {appimagePath}" # Make it executable
shell fmt"./{appimagePath}"