Features
- Automatic Package Discovery: Scans the
packages/directory for any composer packages staged aspackages/{author}/{package}. - Development Mode:
- Switches selected packages to use a
pathrepository. - Updates
composer.jsonto point to the local directory. - Requirements are set to
@devto allow immediate symlinking.
- Switches selected packages to use a
- Publish Mode:
- Unsets local
pathrepositories. - Automatically detects the latest Git tag in each package's directory.
- Switches requirements to the latest version (e.g.,
^1.0) if a tag is found, otherwise defaults back to@devfor remote fetching.
- Unsets local
- Batch Processing: Allows switching all packages at once or selecting specific ones.
Requirements
- Environment: Bash (macOS/Linux).
- Composer: Must be installed and available in your
$PATH. - Git: Required for automatic version detection in "Publish" mode.
- Project Structure: Packages must be located in
packages/{author}/{package_name}.
Usage
-
Make the script executable (if not already):
chmod +x composer-switch.sh -
Run the script:
./composer-switch.sh -
Choose an Action:
1) Development: Switch packages to their localpackages/source.2) Publish: Switch packages back to standard remote/tagged versions.
-
Select Packages (for Development mode):
- Enter
0to switch all discovered packages. - Enter specific numbers (e.g.,
1 3) to switch only those packages.
- Enter
How it Works
Development Mode
When you select a package for development, the script runs:
composer config repositories.<package-name> path packages/<author>/<package>
composer require <author>/<package>:@dev
This creates a symlink from vendor/<author>/<package> to your local packages/ folder, allowing you to edit package code and see changes instantly without running composer update.
Publish Mode
When switching to publish mode, the script:
- Removes the
pathrepository configuration for all discovered packages. - Fetches tags from the local Git repositories of each package.
- Identifies the latest version tag (e.g.,
v1.2.3). - Runs
composer requirewith the appropriate version constraint (e.g.,^1.2).
This ensures your composer.json and composer.lock are ready for production or sharing with other developers who don't have the local packages/ folder.