|
1 | 1 | import json |
2 | 2 | import logging |
3 | | -import os |
4 | | -from pathlib import Path |
5 | 3 | import shutil |
| 4 | +from pathlib import Path |
6 | 5 | from typing import Any, List, Tuple |
7 | 6 |
|
8 | 7 | from multiversx_sdk_cli import errors, utils |
9 | 8 | from multiversx_sdk_cli.projects import shared |
10 | 9 | from multiversx_sdk_cli.projects.project_rust import CargoFile |
11 | | -from multiversx_sdk_cli.projects.templates_config import get_templates_repositories |
12 | | -from multiversx_sdk_cli.projects.templates_repository import TemplatesRepository |
| 10 | +from multiversx_sdk_cli.projects.templates_config import \ |
| 11 | + get_templates_repositories |
| 12 | +from multiversx_sdk_cli.projects.templates_repository import \ |
| 13 | + TemplatesRepository |
13 | 14 |
|
14 | 15 | logger = logging.getLogger("projects.templates") |
15 | | -ERDJS_SNIPPETS_FOLDER_NAME = "erdjs-snippets" |
16 | 16 |
|
17 | 17 |
|
18 | 18 | def list_project_templates(): |
@@ -70,42 +70,11 @@ def _copy_template(template: str, destination_path: Path, project_name: str): |
70 | 70 | if repo.has_template(template): |
71 | 71 | source_path = repo.get_template_folder(template) |
72 | 72 | shutil.copytree(source_path, destination_path) |
73 | | - _copy_erdjs_snippets(template, repo.get_payload_folder(), destination_path, project_name) |
74 | 73 | return |
75 | 74 |
|
76 | 75 | raise errors.TemplateMissingError(template) |
77 | 76 |
|
78 | 77 |
|
79 | | -def _copy_erdjs_snippets(template: str, templates_payload_folder: Path, destination_path: Path, project_name: str): |
80 | | - source_erdjs_snippets_folder = templates_payload_folder / ERDJS_SNIPPETS_FOLDER_NAME |
81 | | - source_erdjs_snippets_subfolder = source_erdjs_snippets_folder / template |
82 | | - destination_erdjs_snippets_folder = destination_path.parent / ERDJS_SNIPPETS_FOLDER_NAME |
83 | | - no_snippets = not source_erdjs_snippets_subfolder.is_dir() |
84 | | - |
85 | | - logger.info(f"_copy_erdjs_snippets, source_erdjs_snippets_subfolder: {source_erdjs_snippets_subfolder}") |
86 | | - logger.info(f"_copy_erdjs_snippets, destination_erdjs_snippets_folder: {destination_erdjs_snippets_folder}") |
87 | | - |
88 | | - if no_snippets: |
89 | | - logger.info(f"_copy_erdjs_snippets: no snippets in template {template}") |
90 | | - return |
91 | | - |
92 | | - utils.ensure_folder(destination_erdjs_snippets_folder) |
93 | | - |
94 | | - # Copy snippets to destination |
95 | | - # First, copy the subfolder associated with the template |
96 | | - shutil.copytree(source_erdjs_snippets_subfolder, destination_erdjs_snippets_folder / project_name) |
97 | | - |
98 | | - # After that, copy the remaining files from the source folder - not recursively (on purpose). |
99 | | - for file in os.listdir(source_erdjs_snippets_folder): |
100 | | - source_file = source_erdjs_snippets_folder / file |
101 | | - destination_file = destination_erdjs_snippets_folder / file |
102 | | - should_copy = source_file.is_file() and not destination_file.exists() |
103 | | - |
104 | | - if should_copy: |
105 | | - logger.info(f"_copy_erdjs_snippets, file: {file}") |
106 | | - shutil.copy(source_file, destination_file) |
107 | | - |
108 | | - |
109 | 78 | def _load_as_template(directory: Path): |
110 | 79 | if shared.is_source_clang(directory): |
111 | 80 | return TemplateClang(directory) |
|
0 commit comments