Added logic to run build code to cpl start #124

This commit is contained in:
2022-12-02 19:38:03 +01:00
parent d0877a4ea6
commit 856960d799
4 changed files with 68 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ from cpl_core.environment.application_environment_abc import ApplicationEnvironm
from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.live_server.live_server_thread import LiveServerThread
from cpl_core.utils import String
class LiveServerService(FileSystemEventHandler):
@@ -37,6 +38,7 @@ class LiveServerService(FileSystemEventHandler):
self._publisher = publisher
self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path)
self._wd = self._src_dir
self._ls_thread = None
self._observer = None
@@ -83,10 +85,11 @@ class LiveServerService(FileSystemEventHandler):
self._restart()
def _start(self):
self._build()
self._start_observer()
self._ls_thread = LiveServerThread(
self._project_settings.python_executable,
self._src_dir,
self._wd,
self._args,
self._env,
self._build_settings
@@ -98,7 +101,18 @@ class LiveServerService(FileSystemEventHandler):
def _build(self):
if self._is_dev:
return
self._env.set_working_directory(self._src_dir)
Console.disable()
self._publisher.build()
Console.enable()
self._wd = os.path.abspath(os.path.join(
self._src_dir,
self._build_settings.output_path,
self._project_settings.name,
'build',
String.convert_to_snake_case(self._project_settings.name)
))
def start(self, args: list[str]):
"""
@@ -114,8 +128,6 @@ class LiveServerService(FileSystemEventHandler):
self._is_dev = True
args.remove('dev')
self._build()
self._args = args
Console.write_line('** CPL live development server is running **')
self._start()