zrb 0.0.85__py3-none-any.whl → 0.0.87__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- zrb/__init__.py +4 -2
- zrb/action/runner.py +7 -3
- zrb/builtin/__init__.py +8 -22
- zrb/builtin/base64.py +1 -1
- zrb/builtin/devtool/__init__.py +20 -0
- zrb/builtin/devtool/devtool_install.py +45 -2
- zrb/builtin/devtool/docker/install.sh +8 -0
- zrb/builtin/devtool/gcloud/install.sh +8 -0
- zrb/builtin/devtool/helix/install.sh +20 -0
- zrb/builtin/devtool/helix/resource/config.toml +10 -0
- zrb/builtin/devtool/helix/resource/themes/gruvbox_transparent.toml +2 -0
- zrb/builtin/devtool/tmux/install.sh +8 -0
- zrb/builtin/devtool/zsh/install.sh +9 -0
- zrb/builtin/devtool/zsh/resource/config.sh +2 -0
- zrb/builtin/env.py +6 -3
- zrb/builtin/explain.py +129 -0
- zrb/builtin/generator/__init__.py +27 -0
- zrb/builtin/generator/app_generator/add.py +81 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/add.py +182 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/_common.py +38 -0
- zrb/builtin/generator/{fastapp/template/_automate/snake_zrb_app_name/cmd/prepare-load-test.sh → app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/cmd/app-activate-venv.sh} +0 -6
- zrb/builtin/generator/{simple_python_app/template/_automate/snake_zrb_app_name/cmd/start.sh → app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/cmd/app-start.sh} +0 -9
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/cmd/pulumi-destroy.sh +1 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/cmd/pulumi-init-stack.sh +1 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/cmd/pulumi-up.sh +1 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/container.py +148 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/deployment.py +108 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/image.py +68 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/local.py +54 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/.gitignore +1 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/deployment/.gitignore +2 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/deployment/Pulumi.yaml +6 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/deployment/__main__.py +79 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/deployment/requirements.txt +3 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/deployment/state/.gitkeep +0 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/docker-compose.env +3 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/docker-compose.yml +20 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/src/.dockerignore +3 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/src/.gitignore +3 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/src/Dockerfile +7 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/src/main.py +20 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/src/requirements.txt +1 -0
- zrb/builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/src/kebab-zrb-app-name/src/template.env +4 -0
- zrb/builtin/generator/cmd_task/add.py +14 -14
- zrb/builtin/generator/cmd_task/template/_automate/snake_zrb_task_name.py +1 -1
- zrb/builtin/generator/common/__init__.py +0 -0
- zrb/builtin/generator/common/helper.py +57 -0
- zrb/builtin/generator/common/task_factory.py +82 -0
- zrb/builtin/generator/{_common/input.py → common/task_input.py} +46 -1
- zrb/builtin/generator/docker_compose_task/add.py +16 -15
- zrb/builtin/generator/docker_compose_task/template/_automate/snake_zrb_task_name.py +1 -1
- zrb/builtin/generator/fastapp/add.py +105 -101
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/_common.py +2 -1
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/activate-venv.sh +7 -0
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/{load-test.sh → app-load-test.sh} +0 -3
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/app-prepare-backend.sh +2 -0
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/app-prepare-load-test.sh +3 -0
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/app-start.sh +3 -0
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/pulumi-destroy.sh +0 -1
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/pulumi-init-stack.sh +1 -0
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/pulumi-up.sh +0 -1
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/container.py +1 -1
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/deployment.py +9 -3
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/frontend.py +3 -3
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/image.py +1 -1
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/load_test.py +11 -4
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local.py +13 -4
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/local_microservices.py +4 -1
- zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/test.py +3 -5
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/deployment/requirements.txt +2 -2
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/loadtest/requirements.txt +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/requirements.txt +3 -3
- zrb/builtin/generator/fastapp_crud/add.py +13 -126
- zrb/builtin/generator/fastapp_crud/helper.py +115 -0
- zrb/builtin/generator/fastapp_crud/task_factory.py +34 -0
- zrb/builtin/generator/fastapp_field/add.py +10 -282
- zrb/builtin/generator/fastapp_field/helper.py +283 -0
- zrb/builtin/generator/fastapp_module/add.py +22 -331
- zrb/builtin/generator/fastapp_module/helper.py +326 -0
- zrb/builtin/generator/pip_package/__init__.py +0 -0
- zrb/builtin/generator/pip_package/add.py +84 -0
- zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/cmd/build.sh +12 -0
- zrb/builtin/generator/{fastapp/template/_automate/snake_zrb_app_name/cmd/start.sh → pip_package/template/_automate/snake_zrb_package_name/cmd/install-symlink.sh} +2 -2
- zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/cmd/publish.sh +6 -0
- zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/local.py +60 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/.gitignore +1 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/README.md +79 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/pyproject.toml +36 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/requirements.txt +4 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/__init__.py +2 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/__main__.py +2 -0
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/util.py +2 -0
- zrb/builtin/generator/project/create.py +12 -8
- zrb/builtin/generator/project_task/task_factory.py +167 -83
- zrb/builtin/generator/project_task/template/_automate/_project/build_project_images.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/deploy_project.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/destroy_project.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/push_project_images.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/remove_project_containers.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/start_project.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/start_project_containers.py +1 -1
- zrb/builtin/generator/project_task/template/_automate/_project/stop_project_containers.py +1 -1
- zrb/builtin/generator/python_task/add.py +14 -16
- zrb/builtin/generator/python_task/template/_automate/snake_zrb_task_name.py +1 -1
- zrb/builtin/generator/simple_python_app/add.py +95 -99
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/cmd/app-activate-venv.sh +7 -0
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/cmd/app-start.sh +6 -0
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/cmd/pulumi-destroy.sh +0 -1
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/cmd/pulumi-init-stack.sh +1 -0
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/cmd/pulumi-up.sh +0 -1
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/container.py +1 -1
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/deployment.py +9 -3
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/image.py +1 -1
- zrb/builtin/generator/simple_python_app/template/_automate/snake_zrb_app_name/local.py +5 -2
- zrb/builtin/generator/simple_python_app/template/src/kebab-zrb-app-name/deployment/requirements.txt +2 -2
- zrb/builtin/git.py +1 -1
- zrb/builtin/{_group.py → group.py} +2 -5
- zrb/builtin/md5.py +1 -1
- zrb/builtin/project.py +1 -1
- zrb/builtin/ubuntu.py +1 -1
- zrb/config/config.py +8 -6
- zrb/helper/accessories/color.py +5 -1
- zrb/helper/accessories/icon.py +2 -0
- zrb/helper/accessories/name.py +2 -0
- zrb/helper/advertisement.py +1 -0
- zrb/helper/cli.py +5 -1
- zrb/helper/codemod/add_argument_to_function.py +3 -0
- zrb/helper/codemod/add_argument_to_function_call.py +3 -0
- zrb/helper/codemod/add_assert_resource.py +2 -0
- zrb/helper/codemod/add_function_call.py +2 -0
- zrb/helper/codemod/add_import_module.py +3 -0
- zrb/helper/codemod/add_key_value_to_dict.py +2 -0
- zrb/helper/codemod/add_property_to_class.py +3 -0
- zrb/helper/codemod/add_upstream_to_task.py +3 -0
- zrb/helper/codemod/append_code_to_function.py +3 -0
- zrb/helper/codemod/format_code.py +2 -0
- zrb/helper/default_env.py +2 -0
- zrb/helper/docker_compose/fetch_external_env.py +3 -0
- zrb/helper/docker_compose/file.py +4 -0
- zrb/helper/env_map/fetch.py +7 -0
- zrb/helper/file/text.py +6 -0
- zrb/helper/git/detect_changes.py +4 -0
- zrb/helper/loader/load_module.py +2 -0
- zrb/helper/map/conversion.py +2 -0
- zrb/helper/string/conversion.py +5 -0
- zrb/helper/string/double_quote.py +6 -2
- zrb/helper/string/jinja.py +2 -0
- zrb/helper/string/parse_replacement.py +2 -0
- zrb/helper/util.py +13 -0
- zrb/task/any_task.py +2 -2
- zrb/task/base_task.py +16 -16
- zrb/task/base_task_composite.py +12 -9
- zrb/task/cmd_task.py +23 -12
- zrb/task/decorator.py +2 -2
- zrb/task/docker_compose_task.py +5 -5
- zrb/task/flow_task.py +5 -5
- zrb/task/http_checker.py +2 -2
- zrb/task/path_checker.py +2 -2
- zrb/task/port_checker.py +2 -2
- zrb/task/resource_maker.py +3 -5
- zrb/task_input/any_input.py +23 -0
- zrb/task_input/base_input.py +46 -43
- zrb/task_input/float_input.py +0 -1
- {zrb-0.0.85.dist-info → zrb-0.0.87.dist-info}/METADATA +16 -17
- {zrb-0.0.85.dist-info → zrb-0.0.87.dist-info}/RECORD +175 -122
- zrb/builtin/generator/_common/helper.py +0 -79
- zrb/builtin/generator/fastapp_crud/add_navigation.py +0 -32
- zrb/builtin/principle.py +0 -66
- /zrb/builtin/generator/{_common → app_generator}/__init__.py +0 -0
- /zrb/{config.toml → builtin/generator/app_generator/template/_automate/snake_zrb_meta_template_name/template/_automate/snake_zrb_app_name/__init__.py} +0 -0
- /zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/{build-frontend.sh → app-build-frontend.sh} +0 -0
- /zrb/builtin/generator/fastapp/template/_automate/snake_zrb_app_name/cmd/{test.sh → app-test.sh} +0 -0
- /zrb/builtin/generator/{fastapp/template/_automate/snake_zrb_app_name/cmd/prepare-backend.sh → pip_package/template/_automate/snake_zrb_package_name/cmd/prepare-venv.sh} +0 -0
- /zrb/task_input/{_constant.py → constant.py} +0 -0
- /zrb/task_input/{input.py → task_input.py} +0 -0
- {zrb-0.0.85.dist-info → zrb-0.0.87.dist-info}/LICENSE +0 -0
- {zrb-0.0.85.dist-info → zrb-0.0.87.dist-info}/WHEEL +0 -0
- {zrb-0.0.85.dist-info → zrb-0.0.87.dist-info}/entry_points.txt +0 -0
@@ -1,26 +1,24 @@
|
|
1
1
|
from typing import Any
|
2
|
-
from
|
2
|
+
from .task_factory import create_add_navigation_task
|
3
|
+
from .helper import register_api, register_permission, register_rpc
|
4
|
+
from ..common.task_input import (
|
5
|
+
project_dir_input, app_name_input, module_name_input, entity_name_input,
|
6
|
+
plural_entity_name_input, main_column_name_input
|
7
|
+
)
|
8
|
+
from ..common.helper import validate_existing_project_dir
|
9
|
+
from ...group import project_add_group
|
3
10
|
from ....task.task import Task
|
4
11
|
from ....task.decorator import python_task
|
5
12
|
from ....task.cmd_task import CmdTask
|
6
13
|
from ....task.resource_maker import ResourceMaker
|
7
14
|
from ....runner import runner
|
8
15
|
from ....helper import util
|
9
|
-
from ....helper.codemod.add_import_module import add_import_module
|
10
|
-
from ....helper.codemod.append_code_to_function import append_code_to_function
|
11
|
-
from ....helper.file.text import read_text_file_async, write_text_file_async
|
12
|
-
from .._common.input import (
|
13
|
-
project_dir_input, app_name_input, module_name_input, entity_name_input,
|
14
|
-
plural_entity_name_input, main_column_name_input
|
15
|
-
)
|
16
|
-
from .._common.helper import validate_project_dir
|
17
|
-
from .add_navigation import create_add_navigation_task
|
18
16
|
|
19
17
|
import asyncio
|
20
18
|
import os
|
21
19
|
|
22
|
-
|
23
|
-
|
20
|
+
CURRENT_DIR = os.path.dirname(__file__)
|
21
|
+
CODEMOD_DIR = os.path.join(CURRENT_DIR, 'nodejs', 'codemod')
|
24
22
|
|
25
23
|
###############################################################################
|
26
24
|
# Task Definitions
|
@@ -35,7 +33,7 @@ codemod_dir = os.path.join(current_dir, 'nodejs', 'codemod')
|
|
35
33
|
)
|
36
34
|
async def validate(*args: Any, **kwargs: Any):
|
37
35
|
project_dir = kwargs.get('project_dir')
|
38
|
-
|
36
|
+
validate_existing_project_dir(project_dir)
|
39
37
|
app_name = kwargs.get('app_name')
|
40
38
|
module_name = kwargs.get('module_name')
|
41
39
|
entity_name = kwargs.get('entity_name')
|
@@ -79,7 +77,7 @@ copy_resource = ResourceMaker(
|
|
79
77
|
'zrbPluralEntityName': '{{input.plural_entity_name}}',
|
80
78
|
'zrbColumnName': '{{input.column_name}}',
|
81
79
|
},
|
82
|
-
template_path=os.path.join(
|
80
|
+
template_path=os.path.join(CURRENT_DIR, 'template'),
|
83
81
|
destination_path='{{ input.project_dir }}',
|
84
82
|
excludes=[
|
85
83
|
'*/__pycache__',
|
@@ -128,7 +126,7 @@ async def register_crud(*args: Any, **kwargs: Any):
|
|
128
126
|
|
129
127
|
prepare_codemod = CmdTask(
|
130
128
|
name='prepare-codemod',
|
131
|
-
cwd=
|
129
|
+
cwd=CODEMOD_DIR,
|
132
130
|
cmd=[
|
133
131
|
'npm install --save-dev',
|
134
132
|
'node_modules/.bin/tsc'
|
@@ -155,114 +153,3 @@ add_navigation = create_add_navigation_task(
|
|
155
153
|
async def add_fastapp_crud(*args: Any, **kwargs: Any):
|
156
154
|
task: Task = kwargs.get('_task')
|
157
155
|
task.print_out('Success')
|
158
|
-
|
159
|
-
|
160
|
-
###############################################################################
|
161
|
-
# Helper Definitions
|
162
|
-
###############################################################################
|
163
|
-
|
164
|
-
|
165
|
-
async def register_api(
|
166
|
-
task: Task,
|
167
|
-
project_dir: str,
|
168
|
-
kebab_app_name: str,
|
169
|
-
snake_module_name: str,
|
170
|
-
snake_entity_name: str
|
171
|
-
):
|
172
|
-
module_api_file_path = os.path.join(
|
173
|
-
project_dir, 'src', kebab_app_name, 'src', 'module', snake_module_name,
|
174
|
-
'api.py'
|
175
|
-
)
|
176
|
-
register_function_path = '.'.join([
|
177
|
-
'module', snake_module_name, 'entity', snake_entity_name, 'api'
|
178
|
-
])
|
179
|
-
register_function = f'register_{snake_entity_name}_api'
|
180
|
-
task.print_out(f'Read code from: {module_api_file_path}')
|
181
|
-
code = await read_text_file_async(module_api_file_path)
|
182
|
-
task.print_out(
|
183
|
-
f'Add import "register_api" as "{register_function}" ' +
|
184
|
-
f'from "{register_function_path}" to the code'
|
185
|
-
)
|
186
|
-
code = add_import_module(
|
187
|
-
code=code,
|
188
|
-
module_path=register_function_path,
|
189
|
-
resource='register_api',
|
190
|
-
alias=register_function
|
191
|
-
)
|
192
|
-
task.print_out(f'Add "{register_function}" call to the code')
|
193
|
-
code = append_code_to_function(
|
194
|
-
code=code,
|
195
|
-
function_name='register_api',
|
196
|
-
new_code=f'{register_function}(logger, app, authorizer, rpc_caller, publisher)' # noqa
|
197
|
-
)
|
198
|
-
task.print_out(f'Write modified code to: {module_api_file_path}')
|
199
|
-
await write_text_file_async(module_api_file_path, code)
|
200
|
-
|
201
|
-
|
202
|
-
async def register_rpc(
|
203
|
-
task: Task,
|
204
|
-
project_dir: str,
|
205
|
-
kebab_app_name: str,
|
206
|
-
snake_module_name: str,
|
207
|
-
snake_entity_name: str
|
208
|
-
):
|
209
|
-
module_rpc_file_path = os.path.join(
|
210
|
-
project_dir, 'src', kebab_app_name, 'src', 'module', snake_module_name,
|
211
|
-
'rpc.py'
|
212
|
-
)
|
213
|
-
register_function_path = '.'.join([
|
214
|
-
'module', snake_module_name, 'entity', snake_entity_name, 'rpc'
|
215
|
-
])
|
216
|
-
register_function = f'register_{snake_entity_name}_rpc'
|
217
|
-
task.print_out(f'Read code from: {module_rpc_file_path}')
|
218
|
-
code = await read_text_file_async(module_rpc_file_path)
|
219
|
-
task.print_out(
|
220
|
-
f'Add import "register_rpc" as "{register_function}" ' +
|
221
|
-
f'from "{register_function_path}" to the code'
|
222
|
-
)
|
223
|
-
code = add_import_module(
|
224
|
-
code=code,
|
225
|
-
module_path=register_function_path,
|
226
|
-
resource='register_rpc',
|
227
|
-
alias=register_function
|
228
|
-
)
|
229
|
-
task.print_out(f'Add "{register_function}" call to the code')
|
230
|
-
code = append_code_to_function(
|
231
|
-
code=code,
|
232
|
-
function_name='register_rpc',
|
233
|
-
new_code=f'{register_function}(logger, rpc_server, rpc_caller, publisher)' # noqa
|
234
|
-
)
|
235
|
-
task.print_out(f'Write modified code to: {module_rpc_file_path}')
|
236
|
-
await write_text_file_async(module_rpc_file_path, code)
|
237
|
-
|
238
|
-
|
239
|
-
async def register_permission(
|
240
|
-
task: Task,
|
241
|
-
project_dir: str,
|
242
|
-
kebab_app_name: str,
|
243
|
-
snake_module_name: str,
|
244
|
-
snake_entity_name: str
|
245
|
-
):
|
246
|
-
module_register_permission_file_path = os.path.join(
|
247
|
-
project_dir, 'src', kebab_app_name, 'src', 'module', 'auth',
|
248
|
-
'register_permission.py'
|
249
|
-
)
|
250
|
-
task.print_out(f'Read code from: {module_register_permission_file_path}')
|
251
|
-
code = await read_text_file_async(module_register_permission_file_path)
|
252
|
-
code = append_code_to_function(
|
253
|
-
code=code,
|
254
|
-
function_name='register_permission',
|
255
|
-
new_code='\n'.join([
|
256
|
-
'await ensure_entity_permission(',
|
257
|
-
f" module_name='{snake_module_name}', entity_name='{snake_entity_name}'", # noqa
|
258
|
-
')'
|
259
|
-
])
|
260
|
-
)
|
261
|
-
task.print_out(
|
262
|
-
f'Add "ensure_entity_permission" call for {snake_entity_name} ' +
|
263
|
-
'to the code'
|
264
|
-
)
|
265
|
-
task.print_out(
|
266
|
-
f'Write modified code to: {module_register_permission_file_path}'
|
267
|
-
)
|
268
|
-
await write_text_file_async(module_register_permission_file_path, code)
|
@@ -0,0 +1,115 @@
|
|
1
|
+
from typeguard import typechecked
|
2
|
+
from ....task.task import Task
|
3
|
+
from ....helper.codemod.add_import_module import add_import_module
|
4
|
+
from ....helper.codemod.append_code_to_function import append_code_to_function
|
5
|
+
from ....helper.file.text import read_text_file_async, write_text_file_async
|
6
|
+
import os
|
7
|
+
|
8
|
+
|
9
|
+
@typechecked
|
10
|
+
async def register_api(
|
11
|
+
task: Task,
|
12
|
+
project_dir: str,
|
13
|
+
kebab_app_name: str,
|
14
|
+
snake_module_name: str,
|
15
|
+
snake_entity_name: str
|
16
|
+
):
|
17
|
+
module_api_file_path = os.path.join(
|
18
|
+
project_dir, 'src', kebab_app_name, 'src', 'module', snake_module_name,
|
19
|
+
'api.py'
|
20
|
+
)
|
21
|
+
register_function_path = '.'.join([
|
22
|
+
'module', snake_module_name, 'entity', snake_entity_name, 'api'
|
23
|
+
])
|
24
|
+
register_function = f'register_{snake_entity_name}_api'
|
25
|
+
task.print_out(f'Read code from: {module_api_file_path}')
|
26
|
+
code = await read_text_file_async(module_api_file_path)
|
27
|
+
task.print_out(
|
28
|
+
f'Add import "register_api" as "{register_function}" ' +
|
29
|
+
f'from "{register_function_path}" to the code'
|
30
|
+
)
|
31
|
+
code = add_import_module(
|
32
|
+
code=code,
|
33
|
+
module_path=register_function_path,
|
34
|
+
resource='register_api',
|
35
|
+
alias=register_function
|
36
|
+
)
|
37
|
+
task.print_out(f'Add "{register_function}" call to the code')
|
38
|
+
code = append_code_to_function(
|
39
|
+
code=code,
|
40
|
+
function_name='register_api',
|
41
|
+
new_code=f'{register_function}(logger, app, authorizer, rpc_caller, publisher)' # noqa
|
42
|
+
)
|
43
|
+
task.print_out(f'Write modified code to: {module_api_file_path}')
|
44
|
+
await write_text_file_async(module_api_file_path, code)
|
45
|
+
|
46
|
+
|
47
|
+
@typechecked
|
48
|
+
async def register_rpc(
|
49
|
+
task: Task,
|
50
|
+
project_dir: str,
|
51
|
+
kebab_app_name: str,
|
52
|
+
snake_module_name: str,
|
53
|
+
snake_entity_name: str
|
54
|
+
):
|
55
|
+
module_rpc_file_path = os.path.join(
|
56
|
+
project_dir, 'src', kebab_app_name, 'src', 'module', snake_module_name,
|
57
|
+
'rpc.py'
|
58
|
+
)
|
59
|
+
register_function_path = '.'.join([
|
60
|
+
'module', snake_module_name, 'entity', snake_entity_name, 'rpc'
|
61
|
+
])
|
62
|
+
register_function = f'register_{snake_entity_name}_rpc'
|
63
|
+
task.print_out(f'Read code from: {module_rpc_file_path}')
|
64
|
+
code = await read_text_file_async(module_rpc_file_path)
|
65
|
+
task.print_out(
|
66
|
+
f'Add import "register_rpc" as "{register_function}" ' +
|
67
|
+
f'from "{register_function_path}" to the code'
|
68
|
+
)
|
69
|
+
code = add_import_module(
|
70
|
+
code=code,
|
71
|
+
module_path=register_function_path,
|
72
|
+
resource='register_rpc',
|
73
|
+
alias=register_function
|
74
|
+
)
|
75
|
+
task.print_out(f'Add "{register_function}" call to the code')
|
76
|
+
code = append_code_to_function(
|
77
|
+
code=code,
|
78
|
+
function_name='register_rpc',
|
79
|
+
new_code=f'{register_function}(logger, rpc_server, rpc_caller, publisher)' # noqa
|
80
|
+
)
|
81
|
+
task.print_out(f'Write modified code to: {module_rpc_file_path}')
|
82
|
+
await write_text_file_async(module_rpc_file_path, code)
|
83
|
+
|
84
|
+
|
85
|
+
@typechecked
|
86
|
+
async def register_permission(
|
87
|
+
task: Task,
|
88
|
+
project_dir: str,
|
89
|
+
kebab_app_name: str,
|
90
|
+
snake_module_name: str,
|
91
|
+
snake_entity_name: str
|
92
|
+
):
|
93
|
+
module_register_permission_file_path = os.path.join(
|
94
|
+
project_dir, 'src', kebab_app_name, 'src', 'module', 'auth',
|
95
|
+
'register_permission.py'
|
96
|
+
)
|
97
|
+
task.print_out(f'Read code from: {module_register_permission_file_path}')
|
98
|
+
code = await read_text_file_async(module_register_permission_file_path)
|
99
|
+
code = append_code_to_function(
|
100
|
+
code=code,
|
101
|
+
function_name='register_permission',
|
102
|
+
new_code='\n'.join([
|
103
|
+
'await ensure_entity_permission(',
|
104
|
+
f" module_name='{snake_module_name}', entity_name='{snake_entity_name}'", # noqa
|
105
|
+
')'
|
106
|
+
])
|
107
|
+
)
|
108
|
+
task.print_out(
|
109
|
+
f'Add "ensure_entity_permission" call for {snake_entity_name} ' +
|
110
|
+
'to the code'
|
111
|
+
)
|
112
|
+
task.print_out(
|
113
|
+
f'Write modified code to: {module_register_permission_file_path}'
|
114
|
+
)
|
115
|
+
await write_text_file_async(module_register_permission_file_path, code)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from typing import List
|
2
|
+
from typeguard import typechecked
|
3
|
+
from ....task.any_task import AnyTask
|
4
|
+
from ....task.cmd_task import CmdTask
|
5
|
+
from ..common.task_input import (
|
6
|
+
project_dir_input, app_name_input, module_name_input, entity_name_input,
|
7
|
+
)
|
8
|
+
|
9
|
+
import os
|
10
|
+
|
11
|
+
CURRENT_DIR = os.path.dirname(__file__)
|
12
|
+
CODEMOD_DIR = os.path.join(CURRENT_DIR, 'nodejs', 'codemod')
|
13
|
+
|
14
|
+
NAV_CONFIG_FILE_PATH = '{{input.project_dir}}/src/{{util.to_kebab_case(input.app_name)}}/src/frontend/src/lib/config/navData.ts' # noqa
|
15
|
+
ENV_VAR_NAME = 'navData'
|
16
|
+
NAV_TITLE = '{{util.to_pascal_case(input.entity_name)}}'
|
17
|
+
NAV_URL = '/{{util.to_kebab_case(input.module_name)}}/{{util.to_kebab_case(input.entity_name)}}' # noqa
|
18
|
+
NAV_PERMISSION = '{{util.to_snake_case(input.module_name)}}:{{util.to_snake_case(input.entity_name)}}:get' # noqa
|
19
|
+
|
20
|
+
|
21
|
+
@typechecked
|
22
|
+
def create_add_navigation_task(upstreams: List[AnyTask]) -> AnyTask:
|
23
|
+
return CmdTask(
|
24
|
+
name='add-navigation',
|
25
|
+
inputs=[
|
26
|
+
project_dir_input,
|
27
|
+
app_name_input,
|
28
|
+
module_name_input,
|
29
|
+
entity_name_input,
|
30
|
+
],
|
31
|
+
upstreams=upstreams,
|
32
|
+
retry=0,
|
33
|
+
cmd=f'node {CODEMOD_DIR}/dist/addNav.js "{NAV_CONFIG_FILE_PATH}" "{ENV_VAR_NAME}" "{NAV_TITLE}" "{NAV_URL}" "{NAV_PERMISSION}"' # noqa
|
34
|
+
)
|
@@ -1,23 +1,24 @@
|
|
1
1
|
from typing import Any
|
2
|
-
from
|
2
|
+
from .helper import (
|
3
|
+
add_column_to_delete_page, add_column_to_detail_page,
|
4
|
+
add_column_to_insert_page, add_column_to_list_page, add_column_to_repo,
|
5
|
+
add_column_to_schema, add_column_to_test, add_column_to_update_page
|
6
|
+
)
|
7
|
+
from ..common.task_input import (
|
3
8
|
project_dir_input, app_name_input, module_name_input, entity_name_input,
|
4
9
|
column_name_input, column_type_input
|
5
10
|
)
|
6
|
-
from ..
|
7
|
-
from ...
|
11
|
+
from ..common.helper import validate_existing_project_dir
|
12
|
+
from ...group import project_add_group
|
8
13
|
from ....task.task import Task
|
9
14
|
from ....task.decorator import python_task
|
10
15
|
from ....runner import runner
|
11
16
|
from ....helper import util
|
12
|
-
from ....helper.codemod.add_property_to_class import add_property_to_class
|
13
|
-
from ....helper.codemod.add_key_value_to_dict import add_key_value_to_dict
|
14
|
-
from ....helper.file.text import read_text_file_async, write_text_file_async
|
15
17
|
|
16
18
|
import asyncio
|
17
19
|
import os
|
18
|
-
import re
|
19
20
|
|
20
|
-
|
21
|
+
CURRENT_DIR = os.path.dirname(__file__)
|
21
22
|
|
22
23
|
###############################################################################
|
23
24
|
# Task Definitions
|
@@ -32,7 +33,7 @@ current_dir = os.path.dirname(__file__)
|
|
32
33
|
)
|
33
34
|
async def validate(*args: Any, **kwargs: Any):
|
34
35
|
project_dir = kwargs.get('project_dir')
|
35
|
-
|
36
|
+
validate_existing_project_dir(project_dir)
|
36
37
|
app_name = kwargs.get('app_name')
|
37
38
|
module_name = kwargs.get('module_name')
|
38
39
|
entity_name = kwargs.get('entity_name')
|
@@ -135,276 +136,3 @@ async def add_fastapp_field(*args: Any, **kwargs: Any):
|
|
135
136
|
)),
|
136
137
|
)
|
137
138
|
task.print_out('Success')
|
138
|
-
|
139
|
-
|
140
|
-
###############################################################################
|
141
|
-
# Helper Definitions
|
142
|
-
###############################################################################
|
143
|
-
|
144
|
-
|
145
|
-
async def add_column_to_insert_page(
|
146
|
-
task: Task,
|
147
|
-
project_dir: str,
|
148
|
-
kebab_app_name: str,
|
149
|
-
kebab_module_name: str,
|
150
|
-
kebab_entity_name: str,
|
151
|
-
kebab_column_name: str,
|
152
|
-
snake_column_name: str,
|
153
|
-
capitalized_human_readable_column_name: str
|
154
|
-
):
|
155
|
-
list_page_file_path = os.path.join(
|
156
|
-
project_dir, 'src', kebab_app_name, 'src', 'frontend', 'src', 'routes',
|
157
|
-
kebab_module_name, kebab_entity_name, 'new', '+page.svelte'
|
158
|
-
)
|
159
|
-
task.print_out(f'Read HTML from: {list_page_file_path}')
|
160
|
-
html_content = await read_text_file_async(list_page_file_path)
|
161
|
-
task.print_out('Add default value to insert page')
|
162
|
-
default_value_regex = r"(.*)(// DON'T DELETE: set field default value here)"
|
163
|
-
default_value_subst = '\\n'.join([
|
164
|
-
f"\\1row.{snake_column_name} = '';",
|
165
|
-
'\\1\\2'
|
166
|
-
])
|
167
|
-
html_content = re.sub(
|
168
|
-
default_value_regex, default_value_subst, html_content, 0, re.MULTILINE
|
169
|
-
)
|
170
|
-
task.print_out('Add field to insert page')
|
171
|
-
field_regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
172
|
-
field_subst = '\\n'.join([
|
173
|
-
'\\1<div class="mb-4">',
|
174
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
175
|
-
f'\\1 <input type="text" class="input w-full" id="{kebab_column_name}" placeholder="{capitalized_human_readable_column_name}" bind:value=' + '{row.' + snake_column_name + '} />', # noqa
|
176
|
-
'\\1</div>',
|
177
|
-
'\\1\\2'
|
178
|
-
])
|
179
|
-
html_content = re.sub(
|
180
|
-
field_regex, field_subst, html_content, 0, re.MULTILINE
|
181
|
-
)
|
182
|
-
task.print_out(f'Write modified HTML to: {list_page_file_path}')
|
183
|
-
await write_text_file_async(list_page_file_path, html_content)
|
184
|
-
|
185
|
-
|
186
|
-
async def add_column_to_update_page(
|
187
|
-
task: Task,
|
188
|
-
project_dir: str,
|
189
|
-
kebab_app_name: str,
|
190
|
-
kebab_module_name: str,
|
191
|
-
kebab_entity_name: str,
|
192
|
-
kebab_column_name: str,
|
193
|
-
snake_column_name: str,
|
194
|
-
capitalized_human_readable_column_name: str
|
195
|
-
):
|
196
|
-
list_page_file_path = os.path.join(
|
197
|
-
project_dir, 'src', kebab_app_name, 'src', 'frontend', 'src', 'routes',
|
198
|
-
kebab_module_name, kebab_entity_name, 'update', '[id]', '+page.svelte'
|
199
|
-
)
|
200
|
-
task.print_out(f'Read HTML from: {list_page_file_path}')
|
201
|
-
html_content = await read_text_file_async(list_page_file_path)
|
202
|
-
task.print_out('Add field to update page')
|
203
|
-
regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
204
|
-
subst = '\\n'.join([
|
205
|
-
'\\1<div class="mb-4">',
|
206
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
207
|
-
f'\\1 <input type="text" class="input w-full" id="{kebab_column_name}" placeholder="{capitalized_human_readable_column_name}" bind:value=' + '{row.' + snake_column_name + '} />', # noqa
|
208
|
-
'\\1</div>',
|
209
|
-
'\\1\\2'
|
210
|
-
])
|
211
|
-
html_content = re.sub(
|
212
|
-
regex, subst, html_content, 0, re.MULTILINE
|
213
|
-
)
|
214
|
-
task.print_out(f'Write modified HTML to: {list_page_file_path}')
|
215
|
-
await write_text_file_async(list_page_file_path, html_content)
|
216
|
-
|
217
|
-
|
218
|
-
async def add_column_to_delete_page(
|
219
|
-
task: Task,
|
220
|
-
project_dir: str,
|
221
|
-
kebab_app_name: str,
|
222
|
-
kebab_module_name: str,
|
223
|
-
kebab_entity_name: str,
|
224
|
-
kebab_column_name: str,
|
225
|
-
snake_column_name: str,
|
226
|
-
capitalized_human_readable_column_name: str
|
227
|
-
):
|
228
|
-
list_page_file_path = os.path.join(
|
229
|
-
project_dir, 'src', kebab_app_name, 'src', 'frontend', 'src', 'routes',
|
230
|
-
kebab_module_name, kebab_entity_name, 'delete', '[id]', '+page.svelte'
|
231
|
-
)
|
232
|
-
task.print_out(f'Read HTML from: {list_page_file_path}')
|
233
|
-
html_content = await read_text_file_async(list_page_file_path)
|
234
|
-
task.print_out('Add field to delete page')
|
235
|
-
regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
236
|
-
subst = '\\n'.join([
|
237
|
-
'\\1<div class="mb-4">',
|
238
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
239
|
-
f'\\1 <span id="{kebab_column_name}">' + '{row.' + snake_column_name + '}</span>', # noqa
|
240
|
-
'\\1</div>',
|
241
|
-
'\\1\\2'
|
242
|
-
])
|
243
|
-
html_content = re.sub(
|
244
|
-
regex, subst, html_content, 0, re.MULTILINE
|
245
|
-
)
|
246
|
-
task.print_out(f'Write modified HTML to: {list_page_file_path}')
|
247
|
-
await write_text_file_async(list_page_file_path, html_content)
|
248
|
-
|
249
|
-
|
250
|
-
async def add_column_to_detail_page(
|
251
|
-
task: Task,
|
252
|
-
project_dir: str,
|
253
|
-
kebab_app_name: str,
|
254
|
-
kebab_module_name: str,
|
255
|
-
kebab_entity_name: str,
|
256
|
-
kebab_column_name: str,
|
257
|
-
snake_column_name: str,
|
258
|
-
capitalized_human_readable_column_name: str
|
259
|
-
):
|
260
|
-
list_page_file_path = os.path.join(
|
261
|
-
project_dir, 'src', kebab_app_name, 'src', 'frontend', 'src', 'routes',
|
262
|
-
kebab_module_name, kebab_entity_name, 'detail', '[id]', '+page.svelte'
|
263
|
-
)
|
264
|
-
task.print_out(f'Read HTML from: {list_page_file_path}')
|
265
|
-
html_content = await read_text_file_async(list_page_file_path)
|
266
|
-
task.print_out('Add field to detail page')
|
267
|
-
regex = r"(.*)(<!-- DON'T DELETE: insert new field here-->)"
|
268
|
-
subst = '\\n'.join([
|
269
|
-
'\\1<div class="mb-4">',
|
270
|
-
f'\\1 <label class="block text-gray-700 font-bold mb-2" for="{kebab_column_name}">{capitalized_human_readable_column_name}</label>', # noqa
|
271
|
-
f'\\1 <span id="{kebab_column_name}">' + '{row.' + snake_column_name + '}</span>', # noqa
|
272
|
-
'\\1</div>',
|
273
|
-
'\\1\\2'
|
274
|
-
])
|
275
|
-
html_content = re.sub(
|
276
|
-
regex, subst, html_content, 0, re.MULTILINE
|
277
|
-
)
|
278
|
-
task.print_out(f'Write modified HTML to: {list_page_file_path}')
|
279
|
-
await write_text_file_async(list_page_file_path, html_content)
|
280
|
-
|
281
|
-
|
282
|
-
async def add_column_to_list_page(
|
283
|
-
task: Task,
|
284
|
-
project_dir: str,
|
285
|
-
kebab_app_name: str,
|
286
|
-
kebab_module_name: str,
|
287
|
-
kebab_entity_name: str,
|
288
|
-
snake_column_name: str,
|
289
|
-
capitalized_human_readable_column_name: str
|
290
|
-
):
|
291
|
-
list_page_file_path = os.path.join(
|
292
|
-
project_dir, 'src', kebab_app_name, 'src', 'frontend', 'src', 'routes',
|
293
|
-
kebab_module_name, kebab_entity_name, '+page.svelte'
|
294
|
-
)
|
295
|
-
task.print_out(f'Read HTML from: {list_page_file_path}')
|
296
|
-
html_content = await read_text_file_async(list_page_file_path)
|
297
|
-
# process header
|
298
|
-
task.print_out('Add column header to table')
|
299
|
-
header_regex = r"(.*)(<!-- DON'T DELETE: insert new column header here-->)"
|
300
|
-
header_subst = '\\n'.join([
|
301
|
-
f'\\1<th>{capitalized_human_readable_column_name}</th>',
|
302
|
-
'\\1\\2'
|
303
|
-
])
|
304
|
-
html_content = re.sub(
|
305
|
-
header_regex, header_subst, html_content, 0, re.MULTILINE
|
306
|
-
)
|
307
|
-
# process column
|
308
|
-
task.print_out('Add column to table')
|
309
|
-
column_regex = r"(.*)(<!-- DON'T DELETE: insert new column here-->)"
|
310
|
-
column_subst = '\\n'.join([
|
311
|
-
'\\1<td>{row.' + snake_column_name + '}</td>',
|
312
|
-
'\\1\\2'
|
313
|
-
])
|
314
|
-
html_content = re.sub(
|
315
|
-
column_regex, column_subst, html_content, 0, re.MULTILINE
|
316
|
-
)
|
317
|
-
task.print_out(f'Write modified HTML to: {list_page_file_path}')
|
318
|
-
await write_text_file_async(list_page_file_path, html_content)
|
319
|
-
|
320
|
-
|
321
|
-
async def add_column_to_test(
|
322
|
-
task: Task,
|
323
|
-
project_dir: str,
|
324
|
-
kebab_app_name: str,
|
325
|
-
snake_module_name: str,
|
326
|
-
snake_entity_name: str,
|
327
|
-
snake_column_name: str,
|
328
|
-
column_type: str
|
329
|
-
):
|
330
|
-
test_file_path = os.path.join(
|
331
|
-
project_dir, 'src', kebab_app_name, 'test', snake_module_name,
|
332
|
-
f'test_{snake_entity_name}.py'
|
333
|
-
)
|
334
|
-
task.print_out(f'Read code from: {test_file_path}')
|
335
|
-
code = await read_text_file_async(test_file_path)
|
336
|
-
task.print_out(
|
337
|
-
f'Add column "{snake_column_name}" to the test'
|
338
|
-
)
|
339
|
-
dict_names = [
|
340
|
-
'inserted_success_data', 'to_be_updated_success_data',
|
341
|
-
'updated_success_data', 'to_be_deleted_success_data'
|
342
|
-
]
|
343
|
-
for dict_name in dict_names:
|
344
|
-
code = add_key_value_to_dict(
|
345
|
-
code=code,
|
346
|
-
dict_name=dict_name,
|
347
|
-
key=f"'{snake_column_name}'",
|
348
|
-
value="''"
|
349
|
-
)
|
350
|
-
task.print_out(f'Write modified code to: {test_file_path}')
|
351
|
-
await write_text_file_async(test_file_path, code)
|
352
|
-
|
353
|
-
|
354
|
-
async def add_column_to_schema(
|
355
|
-
task: Task,
|
356
|
-
project_dir: str,
|
357
|
-
kebab_app_name: str,
|
358
|
-
snake_module_name: str,
|
359
|
-
snake_entity_name: str,
|
360
|
-
pascal_entity_name: str,
|
361
|
-
snake_column_name: str,
|
362
|
-
column_type: str
|
363
|
-
):
|
364
|
-
schema_file_path = os.path.join(
|
365
|
-
project_dir, 'src', kebab_app_name, 'src', 'module', snake_module_name,
|
366
|
-
'schema', f'{snake_entity_name}.py'
|
367
|
-
)
|
368
|
-
task.print_out(f'Read code from: {schema_file_path}')
|
369
|
-
code = await read_text_file_async(schema_file_path)
|
370
|
-
task.print_out(
|
371
|
-
f'Add column "{snake_column_name}" to the schema'
|
372
|
-
)
|
373
|
-
code = add_property_to_class(
|
374
|
-
code=code,
|
375
|
-
class_name=f'{pascal_entity_name}Data',
|
376
|
-
property_name=snake_column_name,
|
377
|
-
property_type='str'
|
378
|
-
)
|
379
|
-
task.print_out(f'Write modified code to: {schema_file_path}')
|
380
|
-
await write_text_file_async(schema_file_path, code)
|
381
|
-
|
382
|
-
|
383
|
-
async def add_column_to_repo(
|
384
|
-
task: Task,
|
385
|
-
project_dir: str,
|
386
|
-
kebab_app_name: str,
|
387
|
-
snake_module_name: str,
|
388
|
-
snake_entity_name: str,
|
389
|
-
pascal_entity_name: str,
|
390
|
-
snake_column_name: str,
|
391
|
-
column_type: str
|
392
|
-
):
|
393
|
-
repo_file_path = os.path.join(
|
394
|
-
project_dir, 'src', kebab_app_name, 'src', 'module', snake_module_name,
|
395
|
-
'entity', snake_entity_name, 'repo.py'
|
396
|
-
)
|
397
|
-
task.print_out(f'Read code from: {repo_file_path}')
|
398
|
-
code = await read_text_file_async(repo_file_path)
|
399
|
-
task.print_out(
|
400
|
-
f'Add column "{snake_column_name}" to the repo'
|
401
|
-
)
|
402
|
-
code = add_property_to_class(
|
403
|
-
code=code,
|
404
|
-
class_name=f'DBEntity{pascal_entity_name}',
|
405
|
-
property_name=snake_column_name,
|
406
|
-
property_type='Column',
|
407
|
-
property_value='Column(String)'
|
408
|
-
)
|
409
|
-
task.print_out(f'Write modified code to: {repo_file_path}')
|
410
|
-
await write_text_file_async(repo_file_path, code)
|