diff --git a/README.md b/README.md index 9cf668b..9eadb71 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,16 @@ If a release was already saved to directory '0.0.1-1', then a new release direct #### Next Step Simply double-click the .streamDeckPlugin file, which will load up the plugin in the Stream Deck application. +#### Pack for debug mode +To pack the plugin in debug mode, which enables remote debugging capabilities, use the `--debug` flag: + +```bash +streamdeck-cli pack /path/to/plugin --debug --debug-port 5679 +``` + +This will create a flag file named `.debug` in the packed plugin containing the specified port. + +When this file is included, the plugin will wait for a debugger to attach at that port before starting. You can use tools like VS Code's Python debugger or PyCharm's remote debugger to connect to it. ## Contributing Contributions are welcome! Please open an issue or submit a pull request on GitHub. diff --git a/streamdeck_cli/commands/pack/__init__.py b/streamdeck_cli/commands/pack/__init__.py index eb8bd91..298aff8 100644 --- a/streamdeck_cli/commands/pack/__init__.py +++ b/streamdeck_cli/commands/pack/__init__.py @@ -1,6 +1,4 @@ """Pack/build a Stream Deck plugin into a .streamDeckPlugin file.""" -from __future__ import annotations - import logging from pathlib import Path from typing import Optional @@ -35,6 +33,12 @@ def pack( help="Output directory", ), version: Optional[str] = None, # noqa: UP007 + debug_port: Optional[int] = typer.Option( + None, + "--debug", + "-d", + help="Enable debug mode in the packed plugin to listen for debug messages on the specified port", + ), ) -> None: """Pack/build a Stream Deck plugin into a .streamDeckPlugin file.""" # Validate the manifest by initiating its model. @@ -49,7 +53,7 @@ def pack( # Define the full output file path for the plugin. # The output file at this path will be a .streamDeckPlugin file, which will open the plugin in the Stream Deck app. # The output file at this path is a zip file containing the files of the plugin, which the Stream Deck software unzips to a specific app directory. - output_filepath = output_dirpath / f"{manifest.uuid}.streamDeckPlugin" + output_filepath = versioned_output_dirpath / f"{manifest.uuid}.streamDeckPlugin" logger.info("Output plugin file will be created at: %s", output_filepath) # Create the package directory @@ -59,7 +63,13 @@ def pack( pathignore_spec: pathspec.PathSpec = get_packignore_specification(plugin_dirpath) # Create the zip file and add the plugin files - archive_plugin_files(plugin_dirpath, output_filepath, plugin_uuid=manifest.uuid, packignore_spec=pathignore_spec) + archive_plugin_files( + plugin_dirpath, + output_filepath, + plugin_uuid=manifest.uuid, + packignore_spec=pathignore_spec, + debug_port=debug_port, + ) if __name__ == "__main__": diff --git a/streamdeck_cli/commands/pack/zip.py b/streamdeck_cli/commands/pack/zip.py index 3991269..9c329b8 100644 --- a/streamdeck_cli/commands/pack/zip.py +++ b/streamdeck_cli/commands/pack/zip.py @@ -19,7 +19,13 @@ logger = logging.getLogger("streamdeck-cli") -def archive_plugin_files(plugin_dirpath: Path, output_filepath: Path, plugin_uuid: str, packignore_spec: pathspec.PathSpec) -> None: +def archive_plugin_files( + plugin_dirpath: Path, + output_filepath: Path, + plugin_uuid: str, + packignore_spec: pathspec.PathSpec, + debug_port: int | None = None, +) -> None: """Archive the plugin files into a a new zip file.""" with zipfile.ZipFile(output_filepath, "w", zipfile.ZIP_DEFLATED) as zip_file: # Files should be stuffed in the zip file under a base directory with the name of the plugin UUID found in the manifest. @@ -37,6 +43,12 @@ def archive_plugin_files(plugin_dirpath: Path, output_filepath: Path, plugin_uui zip_file.write(full_filepath, arcname=arcname) + # Add a file `.debug` containing the debug port number if debug mode is enabled to the zip file + if debug_port: + print("YOOO") + zip_file.writestr(f"{entry_prefix}/.debug", str(debug_port)) + + def walk_filtered_plugin_files(source_dirpath: Path, packignore_spec: pathspec.PathSpec) -> Generator[Path, None, None]: """Walk through the plugin directory and yield files that are not ignored.""" # Walk through the directory and yield files that are not ignored