devkit/composer-manager
Composer 安装命令:
composer require devkit/composer-manager
包简介
Structured Composer script discovery, favourites, and execution from the CLI
README 文档
README
devkit-composer-manager
Interactive CLI for Composer scripts, dependencies, autoload, config, and repositories — with validation, favourites, and a Symfony TUI.
Table of Contents
- Why this exists
- Prerequisites
- Install
- How to run it
- Add Composer shortcuts using manage
- Wire Composer shortcuts manually
- Manage menu reference
- CLI commands reference
- Behaviour notes
- Quick test (this repo)
- Full local setup
- Development
- Support
- License
Why this exists
composer.json scripts grow over time: test suites, linters, deploy steps, one-off helpers. Listing them with composer run-script --list is fine, but finding, running, favouriting, and editing scripts — plus dependencies, autoload, config, and repositories — usually means jumping between docs, grep, and hand-editing JSON.
This tool gives you a single CLI that walks up to the nearest composer.json, shows scripts in a table (with filters and favourites), runs them via composer run-script, and offers an interactive manage hub. On PHP 8.4+ with symfony/tui installed, manage uses a full-screen TUI; on PHP 8.3 (or without TUI), the same flows use numbered console menus. Before mutating composer.json, it writes composer.json.bak.
Package: devkit/composer-manager
Prerequisites
| Requirement | Version |
|---|---|
| PHP | 8.3+ |
| Symfony Console / Process | 7.x or 8.x (resolved by Composer for your PHP version) |
| symfony/tui (optional) | 8.1+ — full-screen TUI on PHP 8.4+ only |
| Composer | any recent (for run-script, require, remove) |
| Terminal | ANSI + TTY recommended for manage |
Optional: install Symfony TUI (PHP 8.4+)
composer require symfony/tui:^8.1
Without this package (or on PHP 8.3), manage still works using console menus and prompts.
Install
composer require devkit/composer-manager
From a clone of this repo
git clone https://github.com/stuarttodd-dev/devkit-composer-manager.git
cd devkit-composer-manager
composer install
Path repository (local development)
{
"repositories": [
{
"type": "path",
"url": "../devkit-composer-manager"
}
],
"require-dev": {
"devkit/composer-manager": "@dev"
}
}
Then composer update devkit/composer-manager.
How to run it
The CLI finds composer.json by walking up from the current working directory (or from --dir / -d). Run from your application root, or pass --dir to target another project.
1. Install the package
composer require devkit/composer-manager
2. Run the binary
# After composer require (consumer project) ./vendor/bin/devkit-composer-manager --help # This repo (development) php bin/devkit-composer-manager --help
Windows: use
vendor\bin\devkit-composer-manager.batorphp vendor\bin\devkit-composer-manager.
3. Open the interactive manager
Needs a real terminal (TTY):
./vendor/bin/devkit-composer-manager manage
# or, when stdin is a TTY:
./vendor/bin/devkit-composer-manager
4. List or run scripts without the menu
./vendor/bin/devkit-composer-manager list ./vendor/bin/devkit-composer-manager run tests ./vendor/bin/devkit-composer-manager list --filter=test
Default command
| Environment | No arguments runs |
|---|---|
| TTY (interactive terminal) | manage |
| Non-TTY (CI, pipes) | list |
Global option
| Option | Description |
|---|---|
--dir / -d |
Directory to start searching for composer.json (default: current working directory) |
Passing options through Composer scripts
Use -- before options when calling through composer run-script so Composer does not consume them:
composer commands:list -- --filter=tests
composer commands:list -- --filter='/^test/' --regex
composer commands:run -- tests --no-interaction
Docker
Mount your project and run from the app root inside the container:
docker compose run --rm -it composer php vendor/bin/devkit-composer-manager manage
Ensure devkit/composer-manager is installed in that project’s composer.json.
Add Composer shortcuts using manage
The easiest way to wire shortcuts is through manage itself — no hand-editing JSON.
Example: add composer commands:manage
-
Open manage (from your project root):
./vendor/bin/devkit-composer-manager manage
-
Main menu — choose
Scripts(usually option1). -
Scripts menu — choose
Add script. -
Script name — enter:
commands:manage -
Command line — enter:
vendor/bin/devkit-composer-manager manageConfirm the line when prompted. For a multi-line script, choose Add another line after each line; leave the line empty when finished.
-
Preview — confirm the summary.
-
Back — return to the main menu, then Exit.
-
Test the shortcut:
composer commands:manage
Add the rest of the recommended shortcuts
Repeat Scripts → Add script for each row below:
| Script name | Command line |
|---|---|
commands:list |
vendor/bin/devkit-composer-manager list |
commands:run |
vendor/bin/devkit-composer-manager run |
commands:favourite |
vendor/bin/devkit-composer-manager favourite |
commands:add |
vendor/bin/devkit-composer-manager add |
commands:edit |
vendor/bin/devkit-composer-manager edit |
commands:remove |
vendor/bin/devkit-composer-manager remove |
commands:manage |
vendor/bin/devkit-composer-manager manage |
commands:guide |
vendor/bin/devkit-composer-manager guide |
commands:help |
vendor/bin/devkit-composer-manager help |
commands:cli |
vendor/bin/devkit-composer-manager list-commands |
After that you can use composer commands:list, composer commands:manage, and so on.
Tip: star your daily drivers with Scripts → Toggle favourite, or composer commands:favourite add tests.
Wire Composer shortcuts manually (recommended set)
Alternatively, paste this into the consumer project’s composer.json:
{
"scripts": {
"commands:list": "vendor/bin/devkit-composer-manager list",
"commands:run": "vendor/bin/devkit-composer-manager run",
"commands:favourite": "vendor/bin/devkit-composer-manager favourite",
"commands:add": "vendor/bin/devkit-composer-manager add",
"commands:edit": "vendor/bin/devkit-composer-manager edit",
"commands:remove": "vendor/bin/devkit-composer-manager remove",
"commands:manage": "vendor/bin/devkit-composer-manager manage",
"commands:guide": "vendor/bin/devkit-composer-manager guide",
"commands:help": "vendor/bin/devkit-composer-manager help",
"commands:cli": "vendor/bin/devkit-composer-manager list-commands"
}
}
In this repo, the same shortcuts use @php bin/devkit-composer-manager … so Composer invokes PHP on the checked-in binary.
Manage menu reference
Open with ./vendor/bin/devkit-composer-manager manage (or composer commands:manage once wired).
On PHP 8.4+ with symfony/tui, menus use full-screen lists and a multi-line editor (Ctrl+Enter to submit). Otherwise numbered console menus are used. Destructive or structural changes show a preview and ask for confirmation before saving.
Main menu
| # | Section | What it does |
|---|---|---|
| 1 | Scripts | Add, edit, remove Composer scripts; toggle favourites |
| 2 | Dependencies (require) | Add/remove production packages |
| 3 | Dev dependencies (require-dev) | Same as above for require-dev (composer require --dev / remove --dev) |
| 4 | Autoload | Manage autoload PSR-4, classmap, files, exclude-from-classmap |
| 5 | Autoload dev (autoload-dev) | Same for test/fixture namespaces |
| 6 | Config | Add, edit, remove Composer config settings |
| 7 | Repositories | Add/remove path, vcs, or composer repositories |
| 8 | Backups | Create, restore, or delete timestamped composer.json snapshots |
| 9 | Run a script | Pick a script and execute it |
| 10 | Exit | Leave manage |
Scripts
| Action | Instructions |
|---|---|
| Add script | Enter script name → enter one or more command lines → confirm each line → preview → save. Names use letters, digits, ._:-. |
| Edit script | Pick script → line manager (add, edit, remove lines) → save changes or back without saving. |
| Remove script | Pick script → confirm → removed from scripts. |
| Toggle favourite | Pick script → adds/removes from extra.devkit-composer-manager.favourites (shown as * in list). |
| Back | Return to main menu. |
Dependencies / Dev dependencies
Both sections work the same; dev uses require-dev and passes --dev to Composer.
| Action | Instructions |
|---|---|
| Add package | Enter vendor/package or a search keyword → Packagist search with pagination if keyword → pick version from Packagist releases (or Any version (*), Custom constraint, Back) → preview → runs composer require (or require --dev). |
| Remove package | Pick package → confirm → runs composer remove (or remove --dev). |
| Back | Return to main menu. |
Packagist search shows package name, description, installs, stars, and a Packagist URL column. Use Next page, Previous page, Search again, or Exit results while browsing.
Autoload / Autoload dev
Same actions; Autoload dev writes to autoload-dev.
| Action | Instructions |
|---|---|
| Add PSR-4 mapping | Namespace (e.g. App\\) → directory path (e.g. src/) → preview → save. Path must exist under the project. |
| Add classmap / files path | Choose type: classmap, files, or exclude-from-classmap → enter path → preview → save. |
| Edit entry | Pick entry → new path → preview → save. |
| Remove entry | Pick entry → confirm → remove. |
| Back | Return to main menu. |
Config
Manages the "config" block — Composer behaviour settings (not packages or autoload).
| Action | Instructions |
|---|---|
| Add config key | Pick from documented presets (see table below) or Custom config key → read the description → choose from fixed options (boolean/enum) or enter a string/JSON value → preview → save. |
| Edit config key | Pick key → description shown for known keys → new value → preview → save. |
| Remove config key | Pick key → confirm → remove. |
| Back | Return to main menu. |
Preset config keys (available when adding):
| Key | Purpose | Example value |
|---|---|---|
sort-packages |
Sort require / require-dev keys alphabetically |
true |
optimize-autoloader |
Generate optimized class map for faster autoloading | true |
preferred-install |
Default install method: dist (zip) or source (git) |
dist |
prefer-stable |
Prefer stable releases when constraints allow pre-releases | true |
allow-plugins |
Allow/block Composer plugins by package name | {"vendor/plugin": true} |
platform |
Pretend the project runs on specific PHP/extension versions | {"php": "8.4.0"} |
platform-check |
Fail if runtime PHP/extensions don’t match lock file | true |
classmap-authoritative |
Never fall back to PSR path scanning | true |
apcu-autoloader |
Cache optimized autoloader in APCu | true |
prepend-autoloader |
Prepend Composer autoloader to the stack | true |
discard-changes |
What to do when vendor files would be overwritten | stash |
vendor-dir |
Where packages are installed | vendor |
bin-dir |
Where binaries are installed | vendor/bin |
Keys already present in composer.json are hidden from the preset list. Custom keys accept true/false, numbers, strings, or JSON objects/arrays.
Repositories
| Action | Instructions |
|---|---|
| Add repository | Choose type: path, vcs, or composer → enter URL → preview → save. |
| Remove repository | Pick repository → confirm → remove. |
| Back | Return to main menu. |
Backups
Snapshots live in .devkit-composer-manager/backups/. Every edit also writes a quick composer.json.bak next to your project file.
| Action | Instructions |
|---|---|
| Create backup now | Optional note → timestamped snapshot saved. |
| Restore from backup | Pick backup → optionally backup current file first → restore → runs composer update. |
| Delete backup | Pick backup → confirm → delete snapshot file. |
| Back | Return to main menu. |
Run a script
Pick a script from the list → executes via composer run-script → returns to main menu when finished.
CLI commands reference
Global option on all project-aware commands: --dir / -d — project root to search for composer.json.
| Command | Description |
|---|---|
manage |
Interactive hub (see Manage menu reference). |
list |
Table of Composer scripts; favourites show * in the first column. |
run |
Run a script by name, or pick interactively. |
favourite |
Add, remove, or list favourite script names. |
add |
Add a script to composer.json. |
edit |
Edit an existing script. |
remove |
Remove a script. |
guide |
Short wiring and workflow notes in the terminal. |
list-commands |
Lists this binary’s CLI subcommands (not project scripts). |
list
vendor/bin/devkit-composer-manager list
vendor/bin/devkit-composer-manager list --filter=test
vendor/bin/devkit-composer-manager list --filter='/^test/' --regex
| Option | Description |
|---|---|
--filter / -f |
Filter script names (substring, case-insensitive) |
--regex |
Treat --filter as a PCRE pattern (include delimiters) |
run
vendor/bin/devkit-composer-manager run vendor/bin/devkit-composer-manager run tests vendor/bin/devkit-composer-manager run --favourites-only
| Option / argument | Description |
|---|---|
name |
Script name (optional — interactive picker when omitted) |
--favourites-only |
Interactive mode: only offer favourite scripts |
favourite
vendor/bin/devkit-composer-manager favourite add tests vendor/bin/devkit-composer-manager favourite remove tests vendor/bin/devkit-composer-manager favourite list
| Argument | Description |
|---|---|
action |
Required: add, remove, or list |
name |
Script name (required for add / remove; must exist in scripts) |
Favourites are stored in extra.devkit-composer-manager.favourites.
add
vendor/bin/devkit-composer-manager add --name=qa --line="./vendor/bin/pest" vendor/bin/devkit-composer-manager add # interactive prompts
| Option | Description |
|---|---|
--name |
Script name |
--line |
Command line (repeat for array scripts) |
edit
vendor/bin/devkit-composer-manager edit tests vendor/bin/devkit-composer-manager edit tests --line="phpunit" --line="echo done"
| Option / argument | Description |
|---|---|
name |
Script name (optional — picker when interactive) |
--line |
New lines (replaces entire definition; repeatable) |
remove
vendor/bin/devkit-composer-manager remove old-script vendor/bin/devkit-composer-manager remove old-script --force
| Option / argument | Description |
|---|---|
name |
Script name (optional — picker when interactive) |
--force |
Skip confirmation |
Help
vendor/bin/devkit-composer-manager help vendor/bin/devkit-composer-manager help run composer commands:help run
list— table of Composer scripts in the project.list-commands— this app’s CLI subcommands (run,favourite,add, …).guide— install, shortcuts, and examples in the terminal.
Behaviour notes
- composer.json only — every read, write, backup, restore, and
composer require/removetargetscomposer.jsonin the project root. TheCOMPOSERenvironment variable (e.g.composer.local.jsonin Docker) is ignored so this tool always adjusts the same file you commit. - Startup — on load,
composer.jsonis repaired (common shape issues) and validated withcomposer validate. Invalid files show errors and exit before the menu opens. - Dependencies — add/remove runs
composer require/composer removesocomposer.lockstays in sync. Version picker loads stable releases from Packagist when adding a package. - Validation — repositories, autoload paths, config keys/values, script names/lines, package names/constraints, and list filters are validated on input.
- Symfony TUI — when
symfony/tuiis installed on PHP 8.4+, filterable full-screen pickers in interactive mode; otherwise console menus. - Run uses
php vendor/bin/composer run-script <name>when that file exists, otherwisecomposeron yourPATH. - Backups — timestamped snapshots in
.devkit-composer-manager/backups/; quickcomposer.json.bakbefore each edit; restore can auto-backup current file and runscomposer update. - Favourites —
extra.devkit-composer-manager.favourites(legacyextra.devkit-composer-ui.favouritesandextra.devkit-composer-commands.favouritesstill read). - Saving
composer.jsonmay normalise formatting (Composer’s JSON writer).
Quick test (this repo)
From the project root, after dependencies are installed:
composer install php bin/devkit-composer-manager list composer tests
You should see a table of script names and definitions, then passing Pest tests.
Optional one-liners:
php bin/devkit-composer-manager list --filter=tests
php bin/devkit-composer-manager guide
php bin/devkit-composer-manager help run
php bin/devkit-composer-manager list --dir=/path/to/other/php/project
composer commands:manage
Full local setup
-
Get the code and install dependencies
git clone https://github.com/stuarttodd-dev/devkit-composer-manager.git cd devkit-composer-manager composer install -
Automated tests
composer tests
-
Docker (optional)
docker compose build --no-cache --pull docker compose run --rm app php -v # must show PHP 8.3.x docker compose run --rm app php bin/devkit-composer-manager list docker compose run --rm -it app php bin/devkit-composer-manager # interactive manage docker compose run --rm app composer tests
The image is
php:8.3-cliwith Composer installed. The project is mounted at/src, so local edits are visible in the container. Rebuild after pulling changes:docker compose build --no-cache --pull app.For TUI testing inside Docker, use a PHP 8.4 image and run
composer require symfony/tui:^8.1in the container.
Development
composer run tests composer run standards:check
Support
If this project saves you time, consider buying me a coffee:
License
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-11