Commits

Chris Topaloudis committed 425a049

Check for package.json updates similar to pip

Comments (0)

Files changed (1)

 FILE_LIB = '%s.zip' % DIR_LIB
 FILE_REQUIREMENTS = 'requirements.txt'
 FILE_BOWER = 'bower.json'
+FILE_PACKAGE = 'package.json'
 FILE_PIP_GUARD = os.path.join(DIR_TEMP, 'pip.guard')
+FILE_NPM_GUARD = os.path.join(DIR_TEMP, 'npm.guard')
 FILE_BOWER_GUARD = os.path.join(DIR_TEMP, 'bower.guard')
 
 DIR_BIN = os.path.join(DIR_NODE_MODULES, '.bin')
       os.path.getmtime(FILE_REQUIREMENTS)
 
 
+def check_npm_should_run():
+  if not os.path.exists(FILE_NPM_GUARD):
+    return True
+  return os.path.getmtime(FILE_NPM_GUARD) < os.path.getmtime(FILE_PACKAGE)
+
+
 def check_bower_should_run():
   if not os.path.exists(FILE_BOWER_GUARD):
     return True
   remove_file_dir(DIR_VENV)
 
 
-def get_dependencies(file_name):
-  with open(file_name) as json_file:
-    json_data = json.load(json_file)
-  dependencies = json_data.get('dependencies', dict()).keys()
-  return dependencies + json_data.get('devDependencies', dict()).keys()
-
-
 def install_dependencies():
-  for dependency in get_dependencies('package.json'):
-    if not os.path.exists(os.path.join(DIR_NODE_MODULES, dependency)):
-      os.system('npm install')
-      break
+  if check_npm_should_run():
+    with open(FILE_NPM_GUARD, 'w') as npm_guard:
+      npm_guard.write('Prevents npm execution if newer than package.json')
+    os.system('npm install')
 
   if check_bower_should_run():
     with open(FILE_BOWER_GUARD, 'w') as bower_guard:
   clean_files()
   remove_file_dir(FILE_LIB)
   remove_file_dir(FILE_PIP_GUARD)
+  remove_file_dir(FILE_NPM_GUARD)
   remove_file_dir(FILE_BOWER_GUARD)