Skip to content

Commit

Permalink
update kapsis commands
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Apr 8, 2024
1 parent e61effc commit f95011e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
3 changes: 2 additions & 1 deletion denim.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import ospaths
let path = getHomeDir() & ".nimble/bin"

task dev, "Compile denim":
exec "nim c --gc:arc -d:denimcli -o:" & path & "/denim src/denim.nim"
# exec "nim c --gc:arc -d:denimcli -o:" & path & "/denim src/denim.nim"
exec "nimble build -d:denimcli"

task docgenx, "Build documentation website":
exec "nim doc --index:on -d:napibuild --project --git.url:https://github.com/openpeeps/denim --git.commit:main src/denim.nim"
19 changes: 9 additions & 10 deletions src/denim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ elif isMainModule:
# This requires latest version of `node-gyp`
# todo add support for CMake.js
import kapsis
import denimpkg/commands/[newCommand, buildCommand, publishCommand]
import denimpkg/commands/[new, build, publish]

App:
about:
"DENIM 🔥 Native Node/BunJS addons powered by Nim"

commands:
$ "build" `entry` `links` ["release", "cmake", "yes", "verbose"]:
? "Build Nim project to a native NodeJS addon"
$ "publish":
? "Publish addon to NPM (requires npm cli)"
# App:
# about:
# "DENIM 🔥 Native Node/BunJS addons powered by Nim"
commands:
build file(`nim`), bool(-y), bool(--cmake), bool(-r), bool(--verbose):
## Build a native `node` addon from Nim
publish file(`addon`):
## Publish your addon (requires npm cli)
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
endif()
"""

proc runCommand*(v: Values) =
proc buildCommand*(v: Values) =
## Compile project to source code by using Nim compiler
# https://nim-lang.org/docs/nimc.html
let inputFile = v.get("entry")
# let links = v.get("links")
# echo links
let inputFile = v.get("nim").getPath().path
var
currDir = getCurrentDir()
addonPathDirectory = utils.getPath(currDir, "" / "denim_build")
Expand All @@ -52,7 +50,8 @@ proc runCommand*(v: Values) =
QuitFailure.quit

if not isEmptyDir(addonPathDirectory):
if not v.flag("yes"):
echo addonPathDirectory
if not v.has("y"):
display("Directory is not empty: " & os.splitPath(addonPathDirectory).tail, indent=2, br="after")
if promptConfirm("👉 Are you sure you want to remove contents?"):
os.removeDir(addonPathDirectory)
Expand All @@ -65,12 +64,12 @@ proc runCommand*(v: Values) =

var args = @[
"--nimcache:$1",
"-d:napibuild",
"--define:napibuild",
"--compileOnly",
"--noMain",
]

if v.flag("release"):
if v.has("release"):
add args, "-d:release"
add args, "--opt:speed"
else:
Expand All @@ -84,7 +83,7 @@ proc runCommand*(v: Values) =
if nimCmd.exitCode != 0:
display(nimCmd.output)
QuitFailure.quit
elif v.flag("verbose"):
elif v.has("verbose"):
display(nimCmd.output)
var getNimPath = execCmdEx("choosenim show path")
if getNimPath.exitCode != 0:
Expand All @@ -96,19 +95,19 @@ proc runCommand*(v: Values) =
cachePathDirectory
], options={poStdErrToStdOut, poUsePath})

if v.flag("cmake"):
if v.has("cmake"):
display("✨ Building with CMake.js", indent=2, br="after")
writeFile(currDir / "CMakeLists.txt", cMakeListsContent.replace("DENIM_PKG_NAME", entryFile.splitFile.name))
let cmakeCmd = execCmdEx("cmake-js compile --runtime node --out " & "denim_build" / "build")
if cmakeCmd.exitCode != 0:
display(cmakeCmd.output)
QuitFailure.quit
elif v.flag("verbose"):
elif v.has("verbose"):
display(cmakeCmd.output)
else:
display("✨ Building with node-gyp", indent=2, br="after")
var
gyp = %* {"targets": [getNodeGypConfig(getNimPath.output.strip, v.flag("release"))]}
gyp = %* {"targets": [getNodeGypConfig(getNimPath.output.strip, v.has("release"))]}
jsonConfigPath = cachePathDirectory / entryFile.replace(".nim", ".json")
var
jarr = newJArray()
Expand All @@ -121,11 +120,11 @@ proc runCommand*(v: Values) =
if gypCmd.exitCode != 0:
display(gypCmd.output)
QuitFailure.quit
elif v.flag("verbose"):
elif v.has("verbose"):
display(gypCmd.output)
let
defaultBinName =
if v.flag("cmake"):
if v.has("cmake"):
entryFile.splitFile.name
else: "main"
binaryNodePath = utils.getPath(currDir, "" / "denim_build" / "build" / "Release" / defaultBinName & ".node")
Expand All @@ -140,4 +139,4 @@ proc runCommand*(v: Values) =
discard existsOrCreateDir(binDirectory) # ensure bin directory exists
moveFile(binaryNodePath, binaryTargetPath) # move .node addon
display("👌 Done! Check your /bin directory", indent=2, br="after")
QuitSuccess.quit
QuitSuccess.quit
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import kapsis/[cli, runtime]

proc runCommand*(v: Values) =
proc publishCommand*(v: Values) =
## Command to publish a precompiled Node addon to NPM via GitHub Actions
echo "todo"

0 comments on commit f95011e

Please sign in to comment.