From 477c4da9d335e8d358b2fdcc9dbcb5f56dd0f29d Mon Sep 17 00:00:00 2001 From: Mirek Simek Date: Thu, 18 Jan 2024 09:17:29 +0100 Subject: [PATCH] Creating component files only if they do not exist yet --- pyproject.toml | 2 +- src/nrp_devtools/cli/ui.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d9536df..e131a42 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "nrp-devtools" -version = "0.1.7" +version = "0.1.8" description = "NRP repository development tools" readme = "README.md" authors = [ diff --git a/src/nrp_devtools/cli/ui.py b/src/nrp_devtools/cli/ui.py index d643bc6..8e714d2 100644 --- a/src/nrp_devtools/cli/ui.py +++ b/src/nrp_devtools/cli/ui.py @@ -185,15 +185,17 @@ def create_less_component(*args, **kwargs): # create variable and override files component_variables_file.parent.mkdir(parents=True, exist_ok=True) - component_variables_file.write_text(f""" + if not component_variables_file.exists(): + component_variables_file.write_text(f""" /* https://github.com/Semantic-Org/example-github/blob/master/semantic/src/themes/default/globals/site.variables */ /* @{component_name}Background: @inputBackground; */ - """) + """) click.secho(f"Place variables that parametrize the component inside {component_variables_file}", fg="green") component_overrides_file.parent.mkdir(parents=True, exist_ok=True) - component_overrides_file.touch() + if not component_overrides_file.exists(): + component_overrides_file.touch() # create the component less_data = (Path(__file__).parent.parent / "templates" / "component.less").read_text() @@ -201,7 +203,8 @@ def create_less_component(*args, **kwargs): less_data = less_data.replace('{{component_name}}', component_name) component_file.parent.mkdir(parents=True, exist_ok=True) - component_file.write_text(less_data) + if not component_file.exists(): + component_file.write_text(less_data) click.secho(f"Put the default css to {component_file}", fg="green") # add the component to the registration file @@ -216,11 +219,12 @@ def create_jinjax_component(*args, **kwargs): jinjax_component_file = ui_dir / "templates" / ui_name / f"{component_name_capitalized}.jinja" jinjax_component_file.parent.mkdir(parents=True, exist_ok=True) - jinjax_component_file.write_text(f"""{{# def #}} -
- Overwrite this file with your own jinja template. -
- """) + if not jinjax_component_file.exists(): + jinjax_component_file.write_text(f"""{{# def #}} +
+ Overwrite this file with your own jinja template. +
+ """) click.secho(f"Place the HTML code of the component to {jinjax_component_file} " f"and reference it from elsewhere as or <{component_name_capitalized} />. " f"Do not forget to put css classes 'ui {component_name}' to the root element of the template.",