diff options
author | Tristan Marion <trismarion@gmail.com> | 2018-06-22 15:30:35 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-06-22 15:30:35 +0200 |
commit | 3b595253a2e9f8badc416f85d0b09bf48f344634 (patch) | |
tree | 85939e43b504cf0ff78f69a1912209e90b67ffe5 /src/js/run_node.py | |
parent | 86354a29a40fb97e334f951428239ab8e171e2dd (diff) |
Move `deno2` folder to `src` (#277)
Diffstat (limited to 'src/js/run_node.py')
-rwxr-xr-x | src/js/run_node.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/js/run_node.py b/src/js/run_node.py new file mode 100755 index 000000000..1a69dc502 --- /dev/null +++ b/src/js/run_node.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +""" +gn can only run python scripts. This launches a subprocess Node process. +The working dir of this program is out/Debug/ (AKA root_build_dir) +Before running node, we symlink js/node_modules to out/Debug/node_modules. +""" +import subprocess +import sys +import os + +def symlink(target, name, target_is_dir=False): + if os.name == "nt": + from ctypes import windll, WinError + CreateSymbolicLinkW = windll.kernel32.CreateSymbolicLinkW + flags = 0x02 # SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE + if (target_is_dir): + flags |= 0x01 # SYMBOLIC_LINK_FLAG_DIRECTORY + if not CreateSymbolicLinkW(name.encode('utf-16le'), + target.encode('utf-16le'), + flags): + raise WinError() + else: + os.symlink(target, name) + +js_path = os.path.dirname(os.path.realpath(__file__)) +node_modules_path = os.path.join(js_path, "node_modules") + +if not os.path.exists("node_modules"): + symlink(node_modules_path, "node_modules", True) + +args = ["node"] + sys.argv[1:] +sys.exit(subprocess.call(args)) |