Skip to content

Commit 101e7d6

Browse files
author
xhlulu
committed
Update post-gen to (conditionally) delete files
- Always deletes the cookiecutter_templates - Delete fragments and lazyloader.js when async not used
1 parent f223bcd commit 101e7d6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

hooks/post_gen_project.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
import shlex
44
import sys
55
import os
6+
import shutil
67
import subprocess
78

89
install_deps = '{{cookiecutter.install_dependencies}}'
910
project_shortname = '{{cookiecutter.project_shortname}}'
11+
use_async = '{{cookiecutter.use_async}}'
1012

1113

1214
is_windows = sys.platform == 'win32'
@@ -33,6 +35,22 @@ def _execute_command(cmd):
3335
return status
3436

3537

38+
39+
# Remove the cookiecutter_templates directory since it only contains
40+
# files that are conditionally included.
41+
template_dir = os.path.join(os.getcwd(), 'cookiecutter_templates')
42+
shutil.rmtree(template_dir)
43+
44+
print("\n\n\nuse_async")
45+
print(use_async)
46+
# If it doesn't use async, we can remove the fragments and lazyloader.js
47+
if use_async != "True":
48+
print('use_async is set to False, your component will not be lazy loaded and fragments will not be created.')
49+
shutil.rmtree(os.path.join(os.getcwd(), 'src', 'lib', 'fragments'))
50+
os.remove(os.path.join(os.getcwd(), 'src', 'lib', 'LazyLoader.js'))
51+
52+
53+
3654
if install_deps != 'True':
3755
print('`install_dependencies` is false!!', file=sys.stderr)
3856
print('Please create a venv in your project root'
@@ -90,4 +108,5 @@ def _execute_command(cmd):
90108

91109
print('\n{} ready!\n'.format(project_shortname))
92110

111+
93112
sys.exit(0)

0 commit comments

Comments
 (0)