-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_deps.py
More file actions
62 lines (44 loc) · 1.29 KB
/
check_deps.py
File metadata and controls
62 lines (44 loc) · 1.29 KB
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
#!/usr/bin/env python3
# Created by Patrick Fu on 2021/3/27.
import os, sys
"""
Script for checking dependence
"""
PROJ_ROOT = os.path.dirname(os.path.abspath(__file__))
def __check_node_module(module_name: str, root_path: str) -> bool:
"""
Check whether the [root_path]/node_modules/[module_name] directory exists locally
"""
node_modules_path = os.path.join(root_path, 'node_modules')
module_path = os.path.join(node_modules_path, module_name)
if not os.path.exists(node_modules_path):
return False
if not os.path.exists(module_path):
return False
return True
def check_commitlint() -> int:
"""
Check if commitlint is installed (not required if it is Jenkins)
Return 0: OK; 1: Check failed!
"""
if os.environ.get('JENKINS_HOME'):
return 0
result = __check_node_module('@commitlint', PROJ_ROOT)
return 0 if result else 1
def main(argv):
ACTIONS = {
'commitlint': check_commitlint,
}
if len(argv) != 1 or argv[0] not in ACTIONS:
__usage()
return 1
else:
return ACTIONS[argv[0]]()
def __usage():
print("""
Usage:
1. Check if `commitlint` is installed
python3 check_deps.py commitlint
""")
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))