build_frontend.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # -*- coding: utf-8 -*-
  2. # !/usr/bin/env python
  3. import os
  4. import glob
  5. import shutil
  6. import subprocess
  7. import click
  8. from dotenv import load_dotenv
  9. from apilib.utils import Timer
  10. @click.command()
  11. def build():
  12. """ build frontend static files """
  13. t = Timer() # type: Timer
  14. with t:
  15. cur_dir = os.path.abspath(os.path.split(os.path.realpath('__file__'))[0])
  16. #: grab all and update, the options we need are constant(setting-agnostic)
  17. for _ in glob.glob('.env.*'):
  18. load_dotenv(_)
  19. os.chdir(cur_dir)
  20. subprocess.call('yarn', shell=True)
  21. subprocess.call('gulp all', shell=True)
  22. click.echo('build main finished')
  23. bluetooth_path = os.environ.get('BLUETOOTH_PATH', os.path.join(cur_dir, 'tmp', 'bluetooth'))
  24. if not os.path.exists(bluetooth_path):
  25. os.makedirs(bluetooth_path)
  26. subprocess.call('git clone %s' % (os.environ['BLUETOOTH_REPO_URL'],))
  27. os.chdir(bluetooth_path)
  28. subprocess.call('git checkout for-web')
  29. subprocess.call('git pull')
  30. subprocess.call('yarn', shell=True)
  31. subprocess.call('npm run build', shell=True)
  32. click.echo('build bluetooth finished')
  33. src_dir = os.path.join(bluetooth_path, 'dist')
  34. dest_dir = os.path.join(cur_dir, 'dist')
  35. for name in os.listdir(src_dir):
  36. src_name = os.path.join(src_dir, name)
  37. dest_name = os.path.join(dest_dir, name)
  38. if os.path.exists(dest_name):
  39. shutil.rmtree(dest_name)
  40. shutil.move(src_name, dest_name)
  41. click.echo('moved bluetooth dist to main dist')
  42. click.echo('build finished')
  43. click.echo('time spent {} secs'.format(t.elapsed))
  44. if __name__ == '__main__':
  45. build()