-
Notifications
You must be signed in to change notification settings - Fork 5
/
node_bridge.py
49 lines (35 loc) · 1.16 KB
/
node_bridge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import platform
import sys
from subprocess import Popen, PIPE
if sys.version_info < (3,):
from lib.printer import p
else:
from .lib.printer import p
"""
Modified version of node_bridge from sublime-fixmyjs
"""
IS_OSX = platform.system() == 'Darwin'
IS_WINDOWS = platform.system() == 'Windows'
def node_bridge(bin, args, node_path=None):
env = None
if IS_OSX:
# GUI apps in OS X don't contain .bashrc/.zshrc set paths
env = os.environ.copy()
if not node_path:
node_path = ':/usr/local/bin'
p('Node path: ' + node_path)
env['PATH'] += node_path
try:
cmd = ['node', bin] + args
p('Executing: ', ' '.join(cmd))
proc = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=PIPE, env=env, shell=IS_WINDOWS)
except OSError:
raise Exception('Couldn\'t find Node.js. Make sure it\'s in your $PATH by running `node -v` in your command-line.')
stdout, stderr = proc.communicate(input=''.encode('utf-8'))
stdout = stdout.decode('utf-8')
stderr = stderr.decode('utf-8')
if stderr:
raise Exception('Error: %s' % stderr)
else:
return stdout