(slug, plugin_dir=None)
| 49 | |
| 50 | |
| 51 | def create_plugin(slug, plugin_dir=None): |
| 52 | # Check slug |
| 53 | if not is_valid_slug(slug): |
| 54 | raise UserException("Slug must only contain ASCII letters, numbers, '-', and '_'.") |
| 55 | |
| 56 | if not plugin_dir: |
| 57 | plugin_dir = os.path.join(slug, '') |
| 58 | |
| 59 | # Check if plugin directory exists |
| 60 | if os.path.exists(plugin_dir): |
| 61 | raise UserException(f"Directory {plugin_dir} already exists") |
| 62 | |
| 63 | # Create plugin directory |
| 64 | os.mkdir(plugin_dir) |
| 65 | |
| 66 | # Create manifest |
| 67 | try: |
| 68 | create_manifest(slug, plugin_dir) |
| 69 | except Exception as e: |
| 70 | os.rmdir(plugin_dir) |
| 71 | raise e |
| 72 | |
| 73 | # Create subdirectories |
| 74 | os.mkdir(os.path.join(plugin_dir, "src")) |
| 75 | os.mkdir(os.path.join(plugin_dir, "res")) |
| 76 | |
| 77 | # Create Makefile |
| 78 | makefile = """# If RACK_DIR is not defined when calling the Makefile, default to two directories above |
| 79 | RACK_DIR ?= ../.. |
| 80 | |
| 81 | # FLAGS will be passed to both the C and C++ compiler |
| 82 | FLAGS += |
| 83 | CFLAGS += |
| 84 | CXXFLAGS += |
| 85 | |
| 86 | # Careful about linking to shared libraries, since you can't assume much about the user's environment and library search path. |
| 87 | # Static libraries are fine, but they should be added to this plugin's build system. |
| 88 | LDFLAGS += |
| 89 | |
| 90 | # Add .cpp files to the build |
| 91 | SOURCES += $(wildcard src/*.cpp) |
| 92 | |
| 93 | # Add files to the ZIP package when running `make dist` |
| 94 | # The compiled plugin and "plugin.json" are automatically added. |
| 95 | DISTRIBUTABLES += res |
| 96 | DISTRIBUTABLES += $(wildcard LICENSE*) |
| 97 | DISTRIBUTABLES += $(wildcard presets) |
| 98 | |
| 99 | # Include the Rack plugin Makefile framework |
| 100 | include $(RACK_DIR)/plugin.mk |
| 101 | """ |
| 102 | with open(os.path.join(plugin_dir, "Makefile"), "w") as f: |
| 103 | f.write(makefile) |
| 104 | |
| 105 | # Create plugin.hpp |
| 106 | plugin_hpp = """#pragma once |
| 107 | #include <rack.hpp> |
| 108 |
no test coverage detected