-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathpost_gen_project.py
More file actions
95 lines (74 loc) · 2.48 KB
/
Copy pathpost_gen_project.py
File metadata and controls
95 lines (74 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""Post generation hook."""
import os
from copy import deepcopy
from pathlib import Path
from typing import OrderedDict
from cookieplone import generator
from cookieplone.utils import console, files
context: OrderedDict = {{cookiecutter}}
DOCUMENTATION_STARTER_REMOVE = [
".github",
".git",
]
TEMPLATES_FOLDER = "templates"
def generate_docs_starter(context, output_dir):
"""Generate documentation scaffold"""
output_dir = output_dir
folder_name = "docs"
generator.generate_subtemplate(
f"{TEMPLATES_FOLDER}/docs/starter",
output_dir,
"docs",
context,
DOCUMENTATION_STARTER_REMOVE,
)
files.remove_files(output_dir / folder_name, DOCUMENTATION_STARTER_REMOVE)
def remove_conditional_files(context, output_dir):
if context["__test_framework"] == "jest":
(
output_dir
/ "packages"
/ context["frontend_addon_name"]
/ "vitest.config.mjs"
).unlink()
else:
(output_dir / "jest-addon.config.js").unlink()
if context["volto_version"] < "19":
(output_dir / ".pnpmfile.cjs").unlink()
def main():
"""Final fixes."""
output_dir = Path().cwd()
subtemplates = context.get(
"__cookieplone_subtemplates", []
) # {{ cookiecutter.__cookieplone_subtemplates }}
funcs = {k: v for k, v in globals().items() if k.startswith("generate_")}
for template_id, title, enabled in subtemplates:
os.getenv("COOKIEPLONE_SUBTEMPLATE")
func_name = f"generate_{template_id.replace('/', '_')}"
func = funcs.get(func_name)
if not func:
raise ValueError(f"No handler available for sub_template {template_id}")
elif not int(enabled):
console.print(f" -> Ignoring ({title})")
continue
new_context = deepcopy(context)
console.print(f" -> {title}")
func(new_context, output_dir)
remove_conditional_files(context, output_dir)
msg = """
[bold blue]{{ cookiecutter.frontend_addon_name }}[/bold blue]
Now, enter the generated directory and finish the install:
cd {{ cookiecutter.frontend_addon_name }}
make install
start coding, and push to your organization.
Sorry for the convenience,
The Plone Community.
"""
console.panel(
title=":tada: New addon was generated :tada:",
subtitle="",
msg=msg,
url="https://plone.org/",
)
if __name__ == "__main__":
main()