Cache node_modules in Travis.

Fixes: #712
This commit is contained in:
Umair Khan 2016-06-02 14:54:05 +05:00 committed by Tim Abbott
parent 584887e588
commit 08045241a7
2 changed files with 15 additions and 1 deletions

View File

@ -9,6 +9,7 @@ cache:
- directories: - directories:
- $HOME/phantomjs - $HOME/phantomjs
- $HOME/zulip-venv-cache - $HOME/zulip-venv-cache
- node_modules
env: env:
global: global:
- COVERALLS_PARALLEL=true - COVERALLS_PARALLEL=true

View File

@ -110,6 +110,19 @@ REPO_STOPWORDS_PATH = os.path.join(
LOUD = dict(_out=sys.stdout, _err=sys.stderr) LOUD = dict(_out=sys.stdout, _err=sys.stderr)
def setup_node_modules():
output = subprocess.check_output(['sha1sum', 'package.json'])
sha1sum = output.split()[0]
success_stamp = os.path.join('node_modules', '.npm-success-stamp', sha1sum)
if not os.path.exists(success_stamp):
print("Deleting cached version")
run(["rm", "-rf", "node_modules"])
print("Installing node modules")
run(["npm", "install"])
run(["mkdir", "-p", success_stamp])
else:
print("Using cached version of node_modules")
def setup_virtualenv(target_venv_path, requirements_file, virtualenv_args=None): def setup_virtualenv(target_venv_path, requirements_file, virtualenv_args=None):
# Check if a cached version already exists # Check if a cached version already exists
output = subprocess.check_output(['sha1sum', requirements_file]) output = subprocess.check_output(['sha1sum', requirements_file])
@ -195,7 +208,7 @@ def main():
# Run npm install last because it can be flaky, and that way one # Run npm install last because it can be flaky, and that way one
# only needs to rerun `npm install` to fix the installation. # only needs to rerun `npm install` to fix the installation.
run(["npm", "install"]) setup_node_modules()
return 0 return 0
if __name__ == "__main__": if __name__ == "__main__":