Skip to content

Commit 739e532

Browse files
committed
add OOP class usage + test | fix typo in comments
Signed-off-by: George Lemon <georgelemon@protonmail.com>
1 parent b9ef31a commit 739e532

13 files changed

Lines changed: 87 additions & 29 deletions

File tree

src/denim.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
when defined napibuild:
1414
# Denim as a library exporting NAPI bindings

src/denim.nims

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
--passC:"-I/usr/include/node -I/usr/local/include/node"
1+
when not defined(windows):
2+
--passC:"-I/usr/include/node -I/usr/local/include/node"
3+
24
--gc:arc
35
--define:danger
46
--opt:size

src/denimpkg/commands/build.nim

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
import std/[os, osproc, json, strutils]
1414
import 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)

src/denimpkg/commands/new.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
import kapsis/runtime
1414
import kapsis/interactive/prompts

src/denimpkg/commands/publish.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
import kapsis/runtime
1414
import kapsis/interactive/prompts

src/denimpkg/napi/jsnative_api.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
type
1414
napi_env* {.header:"<node_api.h>".} = pointer

src/denimpkg/napi/node_bindings.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
import std/macros
1414

src/denimpkg/napi/utils.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
iterator enumerate*[T](open: openarray[T]): (int, T) =
1414
var ct = 0

src/denimpkg/nodeapi.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
import std/[macros, strutils, sequtils, tables]
1414
import std/json except `%*`

src/denimpkg/utils.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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

1313
import std/[os, sequtils]
1414

0 commit comments

Comments
 (0)