12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- # -*- coding: utf-8 -*-
- # !/usr/bin/env python
- import os
- import glob
- import shutil
- import subprocess
-
- import click
- from dotenv import load_dotenv
- from apilib.utils import Timer
- @click.command()
- def build():
- """ build frontend static files """
- t = Timer() # type: Timer
-
- with t:
-
- cur_dir = os.path.abspath(os.path.split(os.path.realpath('__file__'))[0])
- #: grab all and update, the options we need are constant(setting-agnostic)
- for _ in glob.glob('.env.*'):
- load_dotenv(_)
- os.chdir(cur_dir)
- subprocess.call('yarn', shell=True)
- subprocess.call('gulp all', shell=True)
- click.echo('build main finished')
- bluetooth_path = os.environ.get('BLUETOOTH_PATH', os.path.join(cur_dir, 'tmp', 'bluetooth'))
- if not os.path.exists(bluetooth_path):
- os.makedirs(bluetooth_path)
- subprocess.call('git clone %s' % (os.environ['BLUETOOTH_REPO_URL'],))
- os.chdir(bluetooth_path)
- subprocess.call('git checkout for-web')
- subprocess.call('git pull')
- subprocess.call('yarn', shell=True)
- subprocess.call('npm run build', shell=True)
- click.echo('build bluetooth finished')
- src_dir = os.path.join(bluetooth_path, 'dist')
- dest_dir = os.path.join(cur_dir, 'dist')
- for name in os.listdir(src_dir):
- src_name = os.path.join(src_dir, name)
- dest_name = os.path.join(dest_dir, name)
- if os.path.exists(dest_name):
- shutil.rmtree(dest_name)
- shutil.move(src_name, dest_name)
- click.echo('moved bluetooth dist to main dist')
- click.echo('build finished')
- click.echo('time spent {} secs'.format(t.elapsed))
- if __name__ == '__main__':
- build()
|