2015-10-26 17:11:44 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2016-08-29 01:02:03 +02:00
|
|
|
import argparse
|
2015-10-26 17:11:44 +01:00
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
os.chdir(settings.DEPLOY_ROOT)
|
|
|
|
STATIC_PATH = 'static/'
|
|
|
|
|
|
|
|
def run():
|
2016-10-16 07:27:55 +02:00
|
|
|
# type: () -> None
|
|
|
|
"""Builds for production, writing the output to disk"""
|
2016-11-25 09:08:38 +01:00
|
|
|
subprocess.check_call(['node', 'node_modules/.bin/webpack'] +
|
2016-04-06 17:09:55 +02:00
|
|
|
['--config', 'tools/webpack.production.config.js'])
|
2015-10-26 17:11:44 +01:00
|
|
|
|
2016-04-13 04:19:56 +02:00
|
|
|
def run_watch(port):
|
2016-10-16 07:27:55 +02:00
|
|
|
# type: (str) -> None
|
|
|
|
"""watches and rebuilds on changes, serving files from memory via webpack-dev-server"""
|
2016-11-25 09:08:38 +01:00
|
|
|
subprocess.Popen(['node', 'node_modules/.bin/webpack-dev-server'] +
|
2016-04-13 04:19:56 +02:00
|
|
|
['--config', 'tools/webpack.config.js', '--watch-poll', '--port', port])
|
2015-10-26 17:11:44 +01:00
|
|
|
|
2016-08-29 01:02:03 +02:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('--watch',
|
2016-04-13 04:19:56 +02:00
|
|
|
action='store_true', dest='watch', default=False,
|
|
|
|
help='watch for changes to source files (for development)')
|
2016-08-29 01:02:03 +02:00
|
|
|
parser.add_argument('--port',
|
2016-04-13 04:19:56 +02:00
|
|
|
action='store', dest='port',
|
2016-08-29 01:02:03 +02:00
|
|
|
default='9994', help='set the port for the webpack server to run on')
|
|
|
|
args = parser.parse_args()
|
2016-04-13 04:19:56 +02:00
|
|
|
|
2016-08-29 01:02:03 +02:00
|
|
|
if args.watch:
|
|
|
|
run_watch(args.port)
|
2016-04-13 04:19:56 +02:00
|
|
|
else:
|
|
|
|
run()
|