davidanthoff / NodeJS.jl
1
module NodeJS
2

3
using Pkg.Artifacts
4
import Base: SHA1
5

6
export nodejs_cmd, npm_cmd
7

8 10
function conditional_nodejs_load()
9 10
    artifact_info = artifact_meta("nodejs_app", joinpath(@__DIR__, "..", "Artifacts.toml"))
10

11 10
    artifact_info === nothing && return nothing
12

13 8
    return artifact_path(SHA1(artifact_info["git-tree-sha1"]))
14
end
15

16
const nodejs_path = conditional_nodejs_load()
17

18
const node_exe_name = Sys.iswindows() ? "node.exe" : "node"
19
const npm_exe_name = Sys.iswindows() ? "npm.cmd" : "npm"
20

21
const node_executable_path = nodejs_path === nothing ? node_exe_name : Sys.iswindows() ? joinpath(nodejs_path, node_exe_name) : joinpath(nodejs_path, "bin", node_exe_name)
22
const npm_executable_path = nodejs_path === nothing ? npm_exe_name : Sys.iswindows() ? joinpath(nodejs_path, npm_exe_name) : joinpath(nodejs_path, "bin", npm_exe_name)
23

24
"""
25
Return the full path of the node command.
26
"""
27 20
function nodejs_cmd()
28 20
    return `$node_executable_path`
29
end
30

31
"""
32
Return the full path of the npm command.
33
"""
34 20
function npm_cmd()
35 20
    if nodejs_path === nothing
36 4
        return `npm`
37 16
    elseif Sys.iswindows()
38 8
        return `$npm_executable_path`
39
    else
40 8
        return `$node_executable_path $npm_executable_path`
41
    end
42
end
43

44
end # module

Read our documentation on viewing source code .

Loading