rate/scripts/tools.py

45 lines
1.1 KiB
Python
Raw Normal View History

2022-10-25 20:03:11 +00:00
#!/usr/bin/python
2022-11-02 19:36:13 +00:00
from os import chdir, path
2022-10-30 18:35:35 +00:00
from sys import argv
from subprocess import run, PIPE
from multiprocessing import Process
2022-10-25 20:03:11 +00:00
apps = ['core', 'api', 'www']
commands = {
'build': 'npm run build',
'install': 'npm ci',
'prettier': 'npm run prettier'
}
def print_commands():
2022-10-25 21:06:10 +00:00
print('Available commands:', [c for c in commands])
2022-10-25 20:03:11 +00:00
2022-10-30 18:35:35 +00:00
def run_command_in_app(app: str, command: str):
chdir(app)
result = run(command.split(' '), stdout=PIPE, stderr=PIPE, text=True)
status = 'DONE' if result.returncode == 0 else 'ERROR'
print('%s:\t%s' % (app, status))
if status == 'ERROR':
print(result.stdout, result.stderr)
2022-10-25 20:03:11 +00:00
if __name__ == '__main__':
2022-10-30 18:35:35 +00:00
if len(argv) < 2:
2022-10-25 20:03:11 +00:00
print_commands()
exit()
2022-10-30 18:35:35 +00:00
cmd = argv[1]
2022-10-25 20:03:11 +00:00
if cmd not in commands:
2022-10-25 21:06:10 +00:00
print('Command \'%s\' not available' % cmd)
2022-10-25 20:03:11 +00:00
print_commands()
exit()
2022-10-30 18:35:35 +00:00
chdir(path.join(path.dirname(path.realpath(__file__)), '..'))
2022-10-25 21:06:10 +00:00
print('Running \'%s\' on %d apps: %s' % (commands[cmd], len(apps), apps))
2022-10-25 20:03:11 +00:00
for app in apps:
2022-10-30 18:35:35 +00:00
Process(target=run_command_in_app, args=(app, commands[cmd])).start()