mirror of https://github.com/zulip/zulip.git
70 lines
2.5 KiB
Python
Executable File
70 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Updates static files for production.
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import os
|
|
import subprocess
|
|
import optparse
|
|
import sys
|
|
|
|
# We need settings so we can figure out where the prod-static directory is.
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
import scripts.lib.setup_path_on_import
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
|
from django.conf import settings
|
|
|
|
parser = optparse.OptionParser()
|
|
parser.add_option('--prev-deploy', nargs=1, metavar='DIR',
|
|
help='A previous deploy from which to reuse files if possible')
|
|
(options, args) = parser.parse_args()
|
|
prev_deploy = options.prev_deploy
|
|
|
|
os.chdir(settings.DEPLOY_ROOT)
|
|
|
|
# Redirect child processes' output to a log file (most recent run only).
|
|
subprocess.check_call(["mkdir", "-p", "var/log"])
|
|
fp = open('var/log/update-prod-static.log', 'w')
|
|
|
|
# Install node packages
|
|
subprocess.check_call(['npm', 'install', '--production'], stdout=fp, stderr=fp);
|
|
|
|
# Compile Handlebars templates and minify JavaScript.
|
|
subprocess.check_call(['python', 'tools/minify-js']
|
|
+ (['--prev-deploy', prev_deploy] if prev_deploy else []),
|
|
stdout=fp, stderr=fp)
|
|
|
|
# Build emoji
|
|
subprocess.check_call(['bash', '-ex', 'tools/setup/emoji_dump/build_emoji'],
|
|
stdout=fp, stderr=fp)
|
|
|
|
# Download and include zxcvbn.js
|
|
subprocess.check_call(['bash', '-ex', 'tools/setup/download-zxcvbn'],
|
|
stdout=fp, stderr=fp)
|
|
|
|
# Collect the files that we're going to serve.
|
|
subprocess.check_call(['python', './manage.py', 'collectstatic', '--noinput'],
|
|
stdout=fp, stderr=fp)
|
|
|
|
# Compile translation strings to generate `.mo` files.
|
|
subprocess.check_call(['python', './manage.py', 'compilemessages'],
|
|
stdout=fp, stderr=fp)
|
|
|
|
# Move the source maps out of the serve/ directory and into their
|
|
# proper place.
|
|
subprocess.check_call(['rm', '-rf', 'prod-static/source-map'],
|
|
stdout=fp, stderr=fp)
|
|
subprocess.check_call(['mkdir', '-p', 'prod-static'], # Needed if PRODUCTION
|
|
stdout=fp, stderr=fp)
|
|
subprocess.check_call(['mv', os.path.join(settings.STATIC_ROOT, 'source-map'),
|
|
'prod-static/source-map'],
|
|
stdout=fp, stderr=fp)
|
|
|
|
# Move language_options.json to the production release
|
|
subprocess.check_call(['cp', '-a', 'static/locale',
|
|
os.path.join(settings.STATIC_ROOT, 'locale')],
|
|
stdout=fp, stderr=fp)
|
|
|
|
fp.close()
|