-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli
executable file
·171 lines (134 loc) · 5.24 KB
/
cli
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
import datetime
import tempfile
import os
import subprocess
import sys
import getpass
import base64
import json
import re
from colorama import init as colorama_init, Fore, Back, Style
import git
import click
def print_info(string):
print(Back.RED + "zmslocaldev" + Style.RESET_ALL + " " + Fore.YELLOW + string + Style.RESET_ALL)
repo_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
modules = [
"mellon",
"zmsadmin",
"zmsapi",
"zmscalldisplay",
"zmsclient",
"zmsdb",
"zmsdldb",
"zmsentities",
"zmsmessaging",
"zmsslim",
"zmsstatistic",
"zmsticketprinter",
]
# cli
@click.group()
def cli():
pass
@cli.group("modules")
def cli_modules():
pass
@cli_modules.command("reference-libraries")
@click.option("--no-symlink", is_flag=True, show_default=True, default=False)
def cli_modules_reference_libraries(no_symlink: bool):
module_dependencies = {}
for module in modules:
composer_file_path = os.path.join(repo_dir, module, "composer.json")
with open(composer_file_path, "r") as f:
composer_content = json.load(f)
composer_content["repositories"] = list([i for i in composer_content.get("repositories", []) if i.get("type") != "path" and i.get("url", None) != "../*"])
composer_content["repositories"].append({
"type": "path",
"url": "../*",
"options": {
"symlink": not no_symlink
}
})
require = composer_content.get("require", [])
for dependency_key in require:
if dependency_key.startswith("eappointment/"):
if module not in module_dependencies:
module_dependencies[module] = []
module_dependencies[module].append(dependency_key)
require[dependency_key] = "@dev"
composer_content["require"] = require
with open(composer_file_path, "w") as f:
json.dump(composer_content, f, indent=4)
f.write("\n")
for module in module_dependencies:
module_dir = os.path.join(repo_dir, module)
os.system(f"cd {module_dir} && composer update {' '.join(module_dependencies[module])} --no-scripts --no-plugins 1>/dev/null")
@cli_modules.command("check-upgrade")
@click.argument("php_version")
def cli_modules_check_upgrade(php_version):
"""Check dependencies for upgrade to specified PHP version without actually upgrading."""
for module in modules:
print_info(f"Checking module: {module}")
composer_file_path = os.path.join(repo_dir, module, "composer.json")
# Load composer.json
with open(composer_file_path, "r") as f:
composer_content = json.load(f)
# Save the current PHP version
current_php_version = composer_content.get("config", {}).get("platform", {}).get("php")
if current_php_version is None:
print_info(f"{module}: current PHP version is not set, skipping...")
continue # Skip this module if PHP version is not set
print_info(f"{module}: {current_php_version} -> {php_version}")
# Update PHP version in composer.json
if "config" not in composer_content:
composer_content["config"] = {}
if "platform" not in composer_content["config"]:
composer_content["config"]["platform"] = {}
composer_content["config"]["platform"]["php"] = php_version
# Save modified composer.json
with open(composer_file_path, "w") as f:
json.dump(composer_content, f, indent=4)
# Run composer outdated to check for potential updates
os.system(f"cd {os.path.join(repo_dir, module)} && composer outdated")
# Revert changes to composer.json
composer_content["config"]["platform"]["php"] = current_php_version
with open(composer_file_path, "w") as f:
json.dump(composer_content, f, indent=4)
@cli.group("clean")
def cli_clean():
pass
@cli_clean.command("cache")
def cli_clean_cache():
for module in modules:
os.system(f"rm -rf {module}/cache/*")
print_info("Cache cleaned")
@cli_modules.command("loop")
@click.argument("commands", required=True, nargs=-1)
def cli_modules_loop(commands):
"""Loops through repositories and executes a given command. Adds --legacy-peer-deps for npm install commands."""
specific_modules = ["zmsadmin", "zmscalldisplay", "zmsstatistic", "zmsticketprinter"]
is_npm_command = commands[0] == "npm"
build_commands = {
"zmsadmin": ["npm run build"],
"zmscalldisplay": ["npm run build"],
"zmsstatistic": ["npm run build"],
"zmsticketprinter": ["npm run build"]
}
target_modules = specific_modules if is_npm_command else modules
for module in target_modules:
print_info(f"Repository: {module}")
module_dir = os.path.join(repo_dir, module)
os.chdir(module_dir)
if is_npm_command and commands[1] == "install":
modified_commands = list(commands) + ["--legacy-peer-deps"]
os.system(" ".join(modified_commands))
elif is_npm_command and len(commands) > 1 and commands[1] == "build":
print_info(f"Running custom npm build commands for {module}")
for build_command in build_commands.get(module, []):
os.system(build_command)
else:
os.system(" ".join(commands))
if __name__ == "__main__":
cli()