feat(server): add rebuild option for server

This commit is contained in:
Haoyu Xu
2021-08-03 02:50:46 -04:00
parent 2cdb48e7d5
commit 665ca6c617
2 changed files with 12 additions and 6 deletions

View File

@@ -49,6 +49,13 @@ class AkLive2D:
required=True,
help="<Required> Operatro to develop",
)
server.add_argument(
"-r",
"--rebuild",
dest="rebuild",
action='store_true',
help="Rebuild assets"
)
build = subprasers.add_parser(
"build",
@@ -65,7 +72,6 @@ class AkLive2D:
nargs='+',
help="Operators to build"
)
build.add_argument(
"-r",
"--rebuild",
@@ -76,9 +82,8 @@ class AkLive2D:
self.args = parser.parse_args()
if self.args.command == "server" or self.args.command == "s":
self.running = Server(self.args.port, self.args.operator_name, self.config)
if self.args.command == "build" or self.args.command == "b":
self.running = Server(self.args.port, self.args.operator_name, self.config, self.args.rebuild)
elif self.args.command == "build" or self.args.command == "b":
self.running = Builder(self.config, self.args.operator_names, self.args.rebuild)
self.running.start()

View File

@@ -6,15 +6,16 @@ from lib.builder import Builder
from lib.html_processor import HtmlProcessor
class Server:
def __init__(self, port, operator, config) -> None:
def __init__(self, port, operator, config, rebuild) -> None:
self.config = config
self.operator = operator
self.port = port
self.rebuild = rebuild
self.httpd = TCPServer(("", port), httpd(operator, config, directory=str(pathlib.Path.cwd())))
def start(self):
# build assets first
Builder(self.config).build_assets(self.operator)
Builder(self.config, rebuild=self.rebuild).build_assets(self.operator)
print("Server is up at 0.0.0.0:{port}".format(port=self.port))
self.httpd.serve_forever()
return