diff --git a/docs/source/user_guide.md b/docs/source/user_guide.md index 05f6032..14028e1 100644 --- a/docs/source/user_guide.md +++ b/docs/source/user_guide.md @@ -2,7 +2,28 @@ ## Developing a new plugin -Create a function, and then register it like below. +### Making your plugin discoverable + +To register a python module/package as a new a `pyscript` CLI plugin, it's first +necessary to register that plugin via `setuptools.entrypoints`. To do so, if you +are using a `setup.py` file, you'll need to add the following to it: + +``` +entry_points={"pyscript-cli": [" = "]} +``` + +otherwise, if you are using `Poetry`, you'll need to add the following to your +`pyproject.toml` file: + +``` +[tool.poetry.plugins."pyscript-cli"] + = "" +``` + +### Extending `pyscript` CLI with new commands + +To create new commands in your plugin and make them available in the `pyscript` +CLI, create a function and then register it like below. ```python from pyscript import console, plugins diff --git a/src/pyscript/__init__.py b/src/pyscript/__init__.py index 471235c..0d58f23 100644 --- a/src/pyscript/__init__.py +++ b/src/pyscript/__init__.py @@ -7,13 +7,13 @@ APPNAME = "pyscript" APPAUTHOR = "python" -DEFAULT_CONFIG_FILENAME = "pyscript.json" +DEFAULT_CONFIG_FILENAME = ".pyscriptconfig" # Default initial data for the command line. DEFAULT_CONFIG = { # Name of config file for PyScript projects. - "project_config_filename": "manifest.json", + "project_config_filename": "pyscript.json", } diff --git a/src/pyscript/_generator.py b/src/pyscript/_generator.py index 1a949ba..9d471ff 100644 --- a/src/pyscript/_generator.py +++ b/src/pyscript/_generator.py @@ -51,5 +51,18 @@ def create_project( manifest_file = app_dir / config["project_config_filename"] with manifest_file.open("w", encoding="utf-8") as fp: json.dump(context, fp) + + if project_type == "plugin": + create_plugin_files() + else: + create_app_files() + + +def create_app_files(app_dir): index_file = app_dir / "index.html" string_to_html('print("Hello, world!")', app_name, index_file) + + +def create_plugin_files(app_dir, name): + index_file = app_dir / f"{name}.py" + string_to_html('print("Hello, world!")', app_name, index_file) \ No newline at end of file diff --git a/src/pyscript/plugins/create.py b/src/pyscript/plugins/create.py index aeed292..7682776 100644 --- a/src/pyscript/plugins/create.py +++ b/src/pyscript/plugins/create.py @@ -22,6 +22,7 @@ def create( """ try: create_project(app_name, app_description, author_name, author_email) + cli.ok(f"Project {app_name} created succesfully. cd into the the {app_name} folder to start using it.") except FileExistsError: raise cli.Abort( f"A directory called {app_name} already exists in this location."