From a0e624833320d9a72c8aba47a689428f81871ac8 Mon Sep 17 00:00:00 2001 From: Armando Rivera Date: Tue, 27 Jul 2021 22:26:45 -0400 Subject: [PATCH] Configured nimble to build/install the bundle binary --- cocoa.nimble | 3 ++- src/bundle.nim | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/test1.nim | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/bundle.nim diff --git a/cocoa.nimble b/cocoa.nimble index d094864..851cac0 100644 --- a/cocoa.nimble +++ b/cocoa.nimble @@ -5,8 +5,9 @@ author = "Armando Rivera" description = "macOS Cocoa GUI package" license = "MIT" srcDir = "src" +bin = @["bundle"] # Dependencies -requires "nim >= 1.4.8" +requires "nim >= 1.4.8, plists" diff --git a/src/bundle.nim b/src/bundle.nim new file mode 100644 index 0000000..54487b2 --- /dev/null +++ b/src/bundle.nim @@ -0,0 +1,55 @@ +import json, os, plists, times + +if paramCount() >= 1: + let fname = paramStr(1) + + let dt = now() + + let appAuthor = "Armando I. Rivera" + let appName = fname + let iconFile = "appIcon.icns" + let bundleIdentifier = "net.binarymagic." & appName + let appVersion = "0.1" + let appInfo = appVersion & " Created by " & appAuthor & " on " & dt.format("MM-dd-yyyy") + let appCopyRight = "Copyright" & dt.format(" yyyy ") & appAuthor & ". All rights reserved." + let appBundle = appName & ".app" + + if fname.len > 0: + var pl = %* + + { "CFBundlePackageType" : "APPL", + "CFBundleInfoDictionaryVersion" : "6.0", + "CFBundleName" : appName, + "CFBundleExecutable" : appName, + "CFBundleIconFile" : iconFile , + "CFBundleIdentifier" : bundleIdentifier , + "CFBundleVersion" : appVersion , + "CFBundleGetInfoString" : appInfo, + "CFBundleShortVersionString" : appVersion , + "NSHumanReadableCopyright" : appCopyRight , + "NSPrincipalClass" : "NSApplication" , + "NSMainNibFile" : "MainMenu" + } + + + createDir(appBundle & "/Contents/MacOS") + createDir(appBundle & "/Contents/Resources") + createDir(appBundle & "/Contents/Frameworks") + + if appName.fileExists: + appName.copyFileWithPermissions(appBundle & "/Contents/MacOS/" & appName) + + if iconFile.fileExists: + iconFile.copyFileWithPermissions(appBundle & "/Contents/Resources/" & iconFile) + + if "Credits.rtf".fileExists: + "Credits.rtf".copyFileWithPermissions(appBundle & "/Contents/Resources/Credits.rtf") + + + pl.writePlist(appBundle & "/Contents/Info.plist") + + discard execShellCmd("touch " & appBundle) + discard execShellCmd("open " & appBundle) +else: + echo "Usage: bundle " + diff --git a/tests/test1.nim b/tests/test1.nim index 86d9a4a..6fed39f 100644 --- a/tests/test1.nim +++ b/tests/test1.nim @@ -7,6 +7,6 @@ import unittest -import nimcocoa +import cocoa test "can add": check add(5, 5) == 10