From 1d983c642a52ddfb44fb9814d9136cbdb2149bb0 Mon Sep 17 00:00:00 2001 From: lacastorine Date: Fri, 8 Jun 2018 19:02:44 +0300 Subject: [PATCH] fix windows support ability use module in windows : fix check and install of node modules in windows --- js2py/node_import.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/js2py/node_import.py b/js2py/node_import.py index 30dc1b60..4be99374 100644 --- a/js2py/node_import.py +++ b/js2py/node_import.py @@ -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 = ''' @@ -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(