Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions js2py/node_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
DID_INIT = False
DIRNAME = os.path.dirname(os.path.abspath(__file__))
PY_NODE_MODULES_PATH = os.path.join(DIRNAME, 'py_node_modules')
OS = os.name.lower()
def _init():
global DID_INIT
if DID_INIT:
return
assert subprocess.call('node -v', shell=True, cwd=DIRNAME)==0, 'You must have node installed! run: brew install node'
assert subprocess.call('cd %s;npm install babel-core babel-cli babel-preset-es2015 babel-polyfill babelify browserify' % repr(DIRNAME), shell=True, cwd=DIRNAME)==0, 'Could not link required node_modules'
assert subprocess.call([
'cd',
DIRNAME if OS == 'nt' else repr(DIRNAME),
'&&',
'npm',
'install',
'babel-core',
'babel-cli',
'babel-preset-es2015',
'babel-polyfill',
'babelify',
'browserify'
], shell=True, cwd=DIRNAME)==0, 'Could not link required node_modules'
DID_INIT = True
DID_INIT = True

ADD_TO_GLOBALS_FUNC = '''
Expand Down Expand Up @@ -58,7 +72,14 @@ def require(module_name, include_polyfill=False, update=False):

pkg_name = module_name.partition('/')[0]
# make sure the module is installed
assert subprocess.call('cd %s;npm install %s' %(repr(DIRNAME), pkg_name), shell=True, cwd=DIRNAME)==0, 'Could not install the required module: ' + pkg_name
assert subprocess.call([
'cd',
DIRNAME if OS == 'nt' else repr(DIRNAME),
'&&',
'npm',
'install',
pkg_name
], shell=True, cwd=DIRNAME)==0, 'Could not install the required module: ' + pkg_name

# convert the module
assert subprocess.call(
Expand Down