Skip to content

Commit 28f8bf9

Browse files
committed
Add bolt create <package>
1 parent 69f1b14 commit 28f8bf9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

bolt/cli/cli.py

+39
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,45 @@ def compile(ctx):
305305
ctx.invoke(legacy_alias, legacy_args=["collectstatic", "--noinput"])
306306

307307

308+
@bolt_cli.command()
309+
@click.argument("package_name")
310+
def create(package_name):
311+
"""Create a new local package"""
312+
package_dir = bolt.runtime.APP_PATH / package_name
313+
package_dir.mkdir(exist_ok=True)
314+
315+
empty_dirs = (
316+
f"templates/{package_name}",
317+
"migrations",
318+
)
319+
for d in empty_dirs:
320+
(package_dir / d).mkdir(parents=True, exist_ok=True)
321+
322+
empty_files = (
323+
"__init__.py",
324+
"migrations/__init__.py",
325+
"models.py",
326+
"views.py",
327+
)
328+
for f in empty_files:
329+
(package_dir / f).touch(exist_ok=True)
330+
331+
# Create a urls.py file with a default namespace
332+
if not (package_dir / "urls.py").exists():
333+
(package_dir / "urls.py").write_text(
334+
f"""from bolt.urls import path
335+
336+
default_namespace = f"{package_name}"
337+
338+
urlpatterns = [
339+
# path("", views.IndexView, name="index"),
340+
]
341+
"""
342+
)
343+
344+
click.secho(f"Created {package_dir.relative_to(Path.cwd())}", fg="green")
345+
346+
308347
class AppCLIGroup(click.Group):
309348
"""
310349
Loads app.cli if it exists as `bolt app`

0 commit comments

Comments
 (0)