#!/usr/bin/env python3 import subprocess import sys toolchain = { "babel": "/usr/bin/babel", "uglifyjs": "/usr/bin/uglifyjs", "terser": "/usr/bin/terser", "jslint": "/usr/bin/jslint", "jshint": "/usr/bin/jshint", "eslint": "/usr/bin/eslint" } CSI = '\033[' FAIL = '91m' OSC = '\033]' def print_fail(line): if sys.stderr is None: return if sys.stderr.isatty(): print(CSI + FAIL + line.decode('utf-8') + OSC, end='', file=sys.stderr) else: print(line.decode('utf-8'), end='', file=sys.stderr) def print_succ(line): if sys.stdout is None: return print(line.decode('utf-8'), end='', file=sys.stdout) def find_toolchain(tool): if tool in toolchain: return toolchain[tool] return tool def main(): try: args = sys.argv[1:] if len(sys.argv) > 1 else [] if len(args) >= 1 and args[0] == 'chroot': tool = [] if len(args) >= 2: tool = [find_toolchain(args[1])] args = args[2:] cmd_list = ['/usr/bin/node'] + tool + args else: cmd_list = ['/usr/bin/pnpm'] + args proc = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) for line in iter(proc.stdout.readline, b''): print_succ(line) for line in iter(proc.stderr.readline, b''): print_fail(line) proc.wait() except subprocess.CalledProcessError as err: print("""Failed with %s.""" % str(err), file=sys.stderr) sys.exit(1) if __name__ == '__main__': main()