Skip to content

Commit

Permalink
Revert back use_async usage and add component_type
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltanawy committed Sep 13, 2023
1 parent 2e2f70d commit 32c324a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 68 deletions.
8 changes: 2 additions & 6 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
"author_email": "Enter your email (For package.json)",
"github_org": "",
"description": "Project Description",
"component_type": [
"Async with Class Component",
"Async with Function Component",
"Class Component",
"Function Component"
],
"use_async": ["False", "True"],
"component_type": ["Function Component", "Class Component"],
"license": [
"MIT License",
"BSD License",
Expand Down
11 changes: 5 additions & 6 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

install_deps = '{{cookiecutter.install_dependencies}}'
project_shortname = '{{cookiecutter.project_shortname}}'
component_type = '{{cookiecutter.component_type}}'
use_async = '{{cookiecutter.use_async}}'


is_windows = sys.platform == 'win32'
Expand Down Expand Up @@ -41,16 +41,15 @@ def _execute_command(cmd):
template_dir = os.path.join(os.getcwd(), 'cookiecutter_templates')
shutil.rmtree(template_dir)

print("\n\n\ncomponent_type")
print(component_type)
print("\n\n\nuse_async")
print(use_async)
# If it doesn't use async, we can remove the fragments and lazyloader.js
if "Async" not in component_type:
print('Since Async component is not in use, your component will not be lazy loaded and fragments will not be created.')
if use_async != "True":
print('use_async is set to False, your component will not be lazy loaded and fragments will not be created.')
shutil.rmtree(os.path.join(os.getcwd(), 'src', 'lib', 'fragments'))
os.remove(os.path.join(os.getcwd(), 'src', 'lib', 'LazyLoader.js'))



if install_deps != 'True':
print('`install_dependencies` is false!!', file=sys.stderr)
print('Please create a venv in your project root'
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{%- if "Async" in cookiecutter.component_type and "Class" in cookiecutter.component_type -%}
{%- include 'cookiecutter_templates/AsyncClassComponent.react.js' -%}
{%- elif "Async" in cookiecutter.component_type and "Function" in cookiecutter.component_type -%}
{%- if cookiecutter.use_async == "True" -%}
{%- include 'cookiecutter_templates/AsyncFunctionComponent.react.js' -%}
{%- elif "Class" in cookiecutter.component_type -%}
{%- include 'cookiecutter_templates/ClassComponent.react.js' -%}
{%- else -%}
{%- elif cookiecutter.component_type == "Function Component" -%}
{%- include 'cookiecutter_templates/FunctionComponent.react.js' -%}
{%- else -%}
{%- include 'cookiecutter_templates/ClassComponent.react.js' -%}
{%- endif -%}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
_this_module = _sys.modules[__name__]

async_resources = [
{%- if "Async" in cookiecutter.component_type -%}
{%- if cookiecutter.use_async == "True" -%}
"{{cookiecutter.component_name}}",
{%- endif -%}
]
Expand Down

0 comments on commit 32c324a

Please sign in to comment.