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

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

Issue 2338753003: DevTools: Make eslint mandatory and check node.js/npm modules in presubmit (Closed)
Patch Set: Fix copyright year 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/node.py
diff --git a/third_party/WebKit/Source/devtools/scripts/node.py b/third_party/WebKit/Source/devtools/scripts/node.py
new file mode 100755
index 0000000000000000000000000000000000000000..6ef6435b0e6d8b2f9ea1ef9efe498307350470b7
--- /dev/null
+++ b/third_party/WebKit/Source/devtools/scripts/node.py
@@ -0,0 +1,82 @@
+#!/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
dgozman 2016/09/14 16:37:41 Let's rename this to install_node_deps
chenwilliam 2016/09/15 00:40:11 Done.
+"""
+
+import os
+from os import path
+import subprocess
+import sys
+
+MIN_NODE_VERSION = 4
+
+
+def main():
+ check_node_version()
+ npm_install()
+
+
+def check_node_version():
+ node_path = which('node')
+ if not node_path:
+ invalid_node_error_message()
+ node_process = popen([node_path, '--version'])
+ (node_process_out, _) = node_process.communicate()
+ if node_process.returncode != 0:
+ invalid_node_error_message()
+ print('Using node.js version: {}'.format(node_process_out))
+ major_version = node_process_out[1]
+ version = int(major_version)
+ if version < MIN_NODE_VERSION:
+ invalid_node_error_message()
+
+
+def invalid_node_error_message():
+ print('Please install node.js v4 or later')
+ print('Download the latest LTS version from nodejs.org:')
+ print('https://nodejs.org/en/download/\n')
+ raise
+
+
+def npm_install():
+ npm_path = which('npm')
+ if not npm_path:
+ print('Cannot find npm, which is bundled with node.js')
+ invalid_node_error_message()
+ 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)
+
+
+# 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