88#
99# (c) 2026 George Lemon | MIT License
1010# Made by Humans from OpenPeeps
11- # https://github.com/openpeeps/tim
11+ # https://github.com/openpeeps/denim
1212
1313import std/ [os, osproc, json, strutils]
1414import kapsis/ runtime
@@ -67,14 +67,14 @@ proc buildCommand*(v: Values) =
6767 if not isEmptyDir (addonPathDirectory):
6868 if not v.has (" -y" ):
6969 displayInfo (" Directory is not empty: " & os.splitPath (addonPathDirectory).tail)
70- if promptConfirm (" 👉 Do you want to remove current contents? (y/N)" ):
70+ if promptConfirm (" Do you want to remove current contents? (y/N)" ):
7171 os.removeDir (addonPathDirectory)
7272 else :
7373 display (" Canceled" , indent= 2 , br= " after" )
7474 QuitFailure .quit
7575 else :
7676 os.removeDir (addonPathDirectory)
77- displayInfo (" 🔥 Running Nim Compiler" )
77+ displayInfo (" Running Nim Compiler" )
7878
7979 var args = @ [
8080 " --nimcache:$1" ,
@@ -109,7 +109,7 @@ proc buildCommand*(v: Values) =
109109 ], options= {poStdErrToStdOut, poUsePath})
110110
111111 if v.has (" --cmake" ):
112- displayInfo (" ✨ Building with CMake.js" )
112+ displayInfo (" Building with CMake.js" )
113113
114114 # cmake - add target libs, if any
115115 var denimLinkLibs: seq [string ]
@@ -128,25 +128,36 @@ proc buildCommand*(v: Values) =
128128 )
129129 )
130130 )
131+ # Build the native addon using CMake.js
131132 let cmakeCmd = execCmdEx (" cmake-js compile --runtime node --out " & " denim_build" / " build" )
132133 if cmakeCmd.exitCode != 0 :
133134 display (cmakeCmd.output)
134135 QuitFailure .quit
135136 elif v.has (" --verbose" ):
136137 display (cmakeCmd.output)
137138 else :
138- displayInfo (" ✨ Building with node-gyp" )
139- var
140- gyp = %* {" targets" : [getNodeGypConfig (getNimPath.output.strip, v.has (" -r" ))]}
141- jsonConfigPath = cachePathDirectory / entryFile.replace (" .nim" , " .json" )
142- var
143- jarr = newJArray ()
144- jsonConfigContents = parseJson (readFile (jsonConfigPath))
139+ # When using `node-gyp`, we need to generate a `binding.gyp` file with
140+ # the correct configuration
141+ displayInfo (" Building with node-gyp" )
142+ var gyp = %* {" targets" : [getNodeGypConfig (getNimPath.output.strip, v.has (" -r" ))]}
143+ let jsonConfigPath = cachePathDirectory / entryFile.replace (" .nim" , " .json" )
144+
145+ var jarr = newJArray ()
146+ let jsonConfigContents = parseJson (readFile (jsonConfigPath))
147+
145148 for elem in items (jsonConfigContents[" compile" ].elems):
146149 jarr.add (newJString (elem[0 ].getStr ().replace (addonPathDirectory / " " , " " )))
150+
151+ # Set the source files in the `binding.gyp` configuration
147152 gyp[" targets" ][0 ][" sources" ] = %* jarr
153+
154+ # Write `binding.gyp` file for node-gyp
148155 writeFile (addonPathDirectory / " binding.gyp" , pretty (gyp, 2 ))
156+
157+ # Build the native addon using node-gyp
149158 let gypCmd = execCmdEx (" node-gyp rebuild --directory=" & addonPathDirectory)
159+
160+ # Check if the build was successful
150161 if gypCmd.exitCode != 0 :
151162 display (gypCmd.output)
152163 QuitFailure .quit
@@ -163,10 +174,10 @@ proc buildCommand*(v: Values) =
163174 binaryTargetPath = binDirectory / binName
164175
165176 if fileExists (binaryNodePath) == false :
166- displayError (" 👉 Oups! $1 not found. Try build again" % [binName])
177+ displayError (" Oups! $1 not found. Try build again" % [binName])
167178 QuitFailure .quit
168179 else :
169180 discard existsOrCreateDir (binDirectory) # ensure bin directory exists
170181 moveFile (binaryNodePath, binaryTargetPath) # move .node addon
171- displaySuccess (" 👌 Done! Check your `bin` directory" )
182+ displaySuccess (" Done! Check your `bin` directory" )
172183 displayInfo (binDirectory)
0 commit comments