mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
Add "forever" option to tools/compile-handlebars-templates.
The "forever" option causes the tool to continue looking for template changes and, when they happen, to recompile them. (imported from commit 2fa719a205f02c7c90cc071f99252148a888654f)
This commit is contained in:
committed by
Waseem Daher
parent
1f82cb2138
commit
d256994528
@@ -5,6 +5,7 @@ import os
|
||||
import glob
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
||||
@@ -13,11 +14,37 @@ from django.conf import settings
|
||||
os.chdir(settings.DEPLOY_ROOT)
|
||||
STATIC_PATH = 'static/'
|
||||
|
||||
def get_templates():
|
||||
return glob.glob(os.path.join(STATIC_PATH, 'templates/*.handlebars'))
|
||||
|
||||
def run():
|
||||
subprocess.check_call(['tools/node', 'node_modules/.bin/handlebars']
|
||||
+ glob.glob(os.path.join(STATIC_PATH, 'templates/*.handlebars'))
|
||||
+ get_templates()
|
||||
+ ['--output', os.path.join(STATIC_PATH, 'templates/compiled.js'),
|
||||
'--known', 'if,unless,each,with'])
|
||||
|
||||
def run_forever():
|
||||
# Keep polling for file changes, similar to how Django does it in
|
||||
# django/utils/autoreload.py. If any of our templates change, rebuild
|
||||
# compiled.js
|
||||
mtimes = {}
|
||||
while True:
|
||||
changed = False
|
||||
for fn in get_templates():
|
||||
new_mtime = os.stat(fn).st_mtime
|
||||
if new_mtime != mtimes.get(fn, None):
|
||||
changed = True
|
||||
mtimes[fn] = new_mtime
|
||||
if changed:
|
||||
print 'Recompiling templates'
|
||||
try:
|
||||
run()
|
||||
print 'done'
|
||||
except:
|
||||
print '\n\n\nPLEASE FIX!!\n\n'
|
||||
time.sleep(0.200)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 2 and sys.argv[1] == 'forever':
|
||||
run_forever()
|
||||
run()
|
||||
|
||||
Reference in New Issue
Block a user