-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixups and cleanup for build script.
* No need to copy already symlinked README. * Help Windows find pnpm. Ref: https://stackoverflow.com/questions/3022013/windows-cant-find-the-file-on-subprocess-call
- Loading branch information
Showing
1 changed file
with
27 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,61 @@ | ||
"""Build scritp gets called on poetry build.""" | ||
"""Build script gets called on poetry/pip build.""" | ||
|
||
import pathlib | ||
import shutil | ||
import subprocess | ||
|
||
|
||
def pnpm_install(project_root): | ||
subprocess.run(["pnpm", "install"], cwd=project_root) | ||
def pnpm_install(project_root, pnpm_path): | ||
subprocess.run([pnpm_path, "install"], cwd=project_root, check=True) | ||
|
||
|
||
def pnpm_buildui(project_root): | ||
subprocess.run(["pnpm", "buildUi"], cwd=project_root) | ||
def pnpm_buildui(project_root, pnpm_path): | ||
subprocess.run([pnpm_path, "buildUi"], cwd=project_root, check=True) | ||
|
||
|
||
def copy_frontend(project_root): | ||
"""Copy the frontend dist directory to the backend for inclusion in the package.""" | ||
|
||
# Create backend frontend dist dir | ||
backend_frontend_dir = project_root / "backend" / "chainlit" / "frontend" | ||
backend_frontend_dir = project_root / "backend" / "chainlit" / "frontend" / "dist" | ||
backend_frontend_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Recursively copy frontend_dist to backend_frontend_dir | ||
frontend_dist = project_root / "frontend" / "dist" | ||
|
||
shutil.copytree(frontend_dist, backend_frontend_dir / "dist", dirs_exist_ok=True) | ||
print(f"Copying {frontend_dist} to {backend_frontend_dir}") | ||
shutil.copytree(frontend_dist, backend_frontend_dir, dirs_exist_ok=True) | ||
|
||
|
||
def copy_copilot(project_root): | ||
"""Copy the copilot dist directory to the backend for inclusion in the package.""" | ||
|
||
# Create backend copilot dir | ||
backend_copilot_dir = project_root / "backend" / "chainlit" / "copilot" | ||
backend_copilot_dir = project_root / "backend" / "chainlit" / "copilot" / "dist" | ||
backend_copilot_dir.mkdir(parents=True, exist_ok=True) | ||
|
||
# Recursively copy copilot_dist to backend_copilot_dir | ||
copilot_dist = project_root / "libs" / "copilot" / "dist" | ||
|
||
shutil.copytree(copilot_dist, backend_copilot_dir / "dist", dirs_exist_ok=True) | ||
print(f"Copying {copilot_dist} to {backend_copilot_dir}") | ||
shutil.copytree(copilot_dist, backend_copilot_dir, dirs_exist_ok=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
project_root = pathlib.Path.cwd().parent | ||
pnpm_install(project_root) | ||
pnpm_buildui(project_root) | ||
def build(): | ||
# Find directory containing this file. | ||
backend_dir = pathlib.Path(__file__).resolve().parent | ||
project_root = backend_dir.parent | ||
|
||
pnpm = shutil.which("pnpm") | ||
if not pnpm: | ||
print("pnpm not found!") | ||
exit(-1) | ||
|
||
pnpm_install(project_root, pnpm) | ||
pnpm_buildui(project_root, pnpm) | ||
copy_frontend(project_root) | ||
copy_copilot(project_root) | ||
|
||
|
||
if __name__ == "__main__": | ||
build() |