Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: third_party/WebKit/Source/devtools/scripts/install_node_deps.py

Issue 2338753003: DevTools: Make eslint mandatory and check node.js/npm modules in presubmit (Closed)
Patch Set: auto-install local node.js for linux Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/scripts/install_node_deps.py
diff --git a/third_party/WebKit/Source/devtools/scripts/install_node_deps.py b/third_party/WebKit/Source/devtools/scripts/install_node_deps.py
new file mode 100755
index 0000000000000000000000000000000000000000..60fd840b0f574201f24ba43eacb24c9630edd5a7
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/install_node_deps.py
@@ -0,0 +1,109 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Ensure node.js and npm modules are installed
+"""
+
+import os
+from os import path
+import subprocess
+import sys
+
+MIN_NODE_VERSION = 4
+
+scripts_path = path.dirname(path.abspath(__file__))
+local_node_path = path.join(scripts_path, 'local_node', 'node.py')
+
+
+def main():
+ valid_global_node = has_valid_global_node()
+ if not valid_global_node:
+ install_node()
+ npm_install(valid_global_node)
+
+
+def has_valid_global_node():
+ node_path = which('node')
+ if not node_path:
+ return False
+ node_process = popen([node_path, '--version'])
+ (node_process_out, _) = node_process.communicate()
+ if node_process.returncode != 0:
+ return False
+ major_version = node_process_out[1]
+ version = int(major_version)
+ if version < MIN_NODE_VERSION:
+ return False
+ return True
+
+
+def install_node():
+ print('Did not find node.js v4 or later installed globally')
+ if sys.platform != 'linux2':
+ print('Please install the latest node.js LTS version using the Mac or Windows installer:')
+ print('https://nodejs.org/en/download/')
+ raise
+ print('Running node.js v4 locally')
+ print('First time run installs this in devtools/scripts/local_node/runtimes')
lushnikov 2016/09/27 19:01:20 can we output this only as we actually fetch node/
chenwilliam 2016/10/05 01:21:33 Done.
+ print('NOTE: this does not add to PATH or affect global node.js installation')
+ install_node_process = popen([local_node_path, '--version'])
+ (node_process_out, error) = install_node_process.communicate()
+ if install_node_process.returncode != 0:
+ print('Could not install node locally')
+ print(error)
+ raise
+ print(node_process_out)
+
+
+def npm_install(valid_global_node):
+ if valid_global_node:
+ npm_path = which('npm')
+ else:
+ npm_path = path.join(scripts_path, 'local_node', 'npm.py')
+ print('Runing npm install using {}'.format(npm_path))
+ npm_process = popen([npm_path, 'install'])
+ (npm_process_out, _) = npm_process.communicate()
+ if npm_process.returncode != 0:
+ print('WARNING: npm install had an issue')
+ print(npm_process_out)
+
+
+def get_node_path():
+ if has_valid_global_node():
+ return which('node')
+ if sys.platform != 'linux2':
+ print('Please install the latest node.js LTS version using the Mac or Windows installer:')
+ print('https://nodejs.org/en/download/')
+ raise
+ return local_node_path
+
+
+# Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python.
+def which(program):
+ def is_exe(fpath):
+ return path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for part in os.environ['PATH'].split(os.pathsep):
+ part = part.strip('\"')
+ exe_file = path.join(part, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
+
+
+def popen(arguments):
+ return subprocess.Popen(
+ arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+
+if __name__ == '__main__':
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698