-
Notifications
You must be signed in to change notification settings - Fork 87
/
install-testplan-ui
executable file
·136 lines (117 loc) · 3.56 KB
/
install-testplan-ui
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python
"""
Installs & Builds the Testplan UI code.
"""
import argparse
import logging
import os
import subprocess
import sys
from testplan import web_ui
TESTPLAN_UI_DIR = os.path.join(os.path.dirname(web_ui.__file__), "testing")
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.DEBUG)
def parse_cli_args() -> argparse.Namespace:
"""
Parse CLI arguments.
"""
parser = argparse.ArgumentParser(
description="Run this script to install & build the Testplan UI."
)
parser.add_argument(
"-v",
"--verbose",
action="store_true",
dest="verbose",
help="Displays verbose logs.",
)
parser.add_argument(
"-d",
"--dev",
action="store_true",
dest="dev",
help="Installs dev dependencies, use if developing the UI.",
)
parser.add_argument(
"-p",
"--path",
action="store",
dest="path",
default=TESTPLAN_UI_DIR,
help="The path to the testplan UI directory.",
)
return parser.parse_args()
def is_manager_installed(command: str) -> bool:
"""
Checks if package manager is installed.
:param command: command to invoke package manager (npm, yarn, pnpm, ...)
:type command: ``str``
"""
with open(os.devnull, "w") as FNULL:
try:
subprocess.check_call(
f"{command} --version",
shell=True,
stdout=FNULL
)
except subprocess.CalledProcessError:
return False
else:
return True
def install_and_build_ui(
path: str = TESTPLAN_UI_DIR,
dev: bool = False,
verbose: bool = False
) -> None:
"""
Installs dependencies & builds the UI code.
:param path: Where to install dev dependencies.
:type path: ``str``
:param dev: Whether to install dev dependencies, use if developing the UI.
:type dev: ``bool``
:param verbose: Whether to display verbose logs.
:type verbose: ``bool``
"""
if not is_manager_installed('pnpm'):
logging.warning("=" * 54)
logging.warning("PNPM IS NOT INSTALLED.")
logging.warning(
"Testplan UI is built using PNPM, follow instructions at:")
logging.warning("https://pnpm.io/installation")
logging.warning("=" * 54)
sys.exit(1)
with open(os.devnull, "w") as FNULL:
output = FNULL
if verbose:
output = None
production_cmd = " --production"
if dev:
production_cmd = ""
logging.info("Installing Testplan UI dependencies...")
logging.info(f"Installing to path: {os.path.abspath(path)}")
subprocess.check_call(
"pnpm install{}".format(production_cmd),
shell=True,
cwd=path,
stdout=output,
stderr=subprocess.STDOUT,
)
logging.info("Enabling pre and post scripts...")
subprocess.check_call(
"pnpm config set enable-pre-post-scripts true",
shell=True,
cwd=path,
stdout=output,
stderr=subprocess.STDOUT,
)
logging.info("Building Testplan UI...")
subprocess.check_call(
"pnpm build",
shell=True,
cwd=path,
stdout=output,
stderr=subprocess.STDOUT,
)
logging.info("Testplan UI install & build have completed successfully.")
if __name__ == "__main__":
args = parse_cli_args()
install_and_build_ui(path=args.path, dev=args.dev, verbose=args.verbose)