neronmoon/scriptsdev
Laravel package to manage and run custom development scripts—generate commands, automate tasks, and organize project utilities from a clean structure. Helpful for scaffolding, repetitive workflows, and keeping team scripts consistent across environments.
Installation Add the package to your project via Composer:
composer require neronmoon/scriptsdev --dev
The package registers a custom Composer script directive (scripts-dev) automatically.
First Use Case
Define a scripts-dev section in your composer.json to run development-specific tasks:
{
"scripts-dev": {
"test": "phpunit",
"lint": "php-cs-fixer fix --dry-run"
}
}
Run them via:
composer scripts-dev
Where to Look
composer.json for the scripts-dev section.composer.json for existing scripts vs. scripts-dev separation.scripts-dev unless specified otherwise.Parallel with scripts
Use scripts for production tasks (e.g., dump-autoload) and scripts-dev for dev-only tasks (e.g., lint, test).
Example:
{
"scripts": {
"build": "npm run build"
},
"scripts-dev": {
"test": "phpunit",
"watch": "npm run dev"
}
}
Conditional Execution
Combine with Composer’s --no-dev flag or custom scripts to toggle dev tasks:
composer scripts-dev test # Runs only 'test'
composer scripts-dev # Runs all dev scripts
Laravel-Specific Patterns
scripts-dev tasks to Artisan commands for consistency:
"scripts-dev": {
"migrate:fresh": "php artisan migrate:fresh --seed"
}
&& or use composer run for complex workflows:
composer scripts-dev test && composer scripts-dev lint
Environment Awareness
Use environment variables (e.g., .env) to conditionally enable/disable tasks:
"scripts-dev": {
"debug": "php artisan tinker",
"debug:only-if": "APP_DEBUG=true php artisan tinker"
}
No Default Task Grouping
Unlike scripts, scripts-dev does not auto-group tasks under composer run-script. Always prefix with scripts-dev:
composer scripts-dev test # Correct
composer test # Fails (unless aliased)
Order Dependency
Tasks run in alphabetical order by default. Use composer run-script with explicit ordering:
composer run-script scripts-dev test lint
Dev Mode Only
Tasks in scripts-dev ignore --no-dev and will fail if run in production. Test locally:
composer --no-dev scripts-dev # Still runs dev scripts!
No Built-in Parallelism
Unlike npm run or make, scripts-dev tasks run sequentially. Use & or tools like parallel for concurrency:
composer scripts-dev test & composer scripts-dev lint
Dry Runs
Use set -x in scripts to debug:
"scripts-dev": {
"debug": "set -x; php artisan tinker"
}
Exit Codes
Scripts with non-zero exits will stop further execution. Use || true to ignore failures:
"scripts-dev": {
"lint": "php-cs-fixer fix || true"
}
Logging Redirect output to files for debugging:
"scripts-dev": {
"test:log": "phpunit > test.log 2>&1"
}
Custom Directives
Extend the package by creating a post-autoload-dump script to dynamically generate scripts-dev:
"scripts": {
"post-autoload-dump": "php generate-scripts-dev.php"
}
Integration with Laravel Mix/Vite
Use scripts-dev to wrap frontend builds:
"scripts-dev": {
"dev": "npm run dev",
"build": "npm run build"
}
CI/CD Pipelines
Gate scripts-dev tasks in GitHub Actions/GitLab CI:
# .github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: composer scripts-dev test
How can I help you explore Laravel packages today?