Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to define their own scripts #2516

Merged
merged 5 commits into from Jul 20, 2014
Merged

Conversation

@MaxGfeller
Copy link
Contributor

MaxGfeller commented Dec 19, 2013

Composer already supports defining scripts to be run for specific events, like post-install-cmd, post-create-project-cmd etc. However it would be nice if users could define their own scripts which then can be run with composer run.

This is already possible with npm, although not well documented. @substack wrote a detailed article on how these scripts can be used for different tasks in your project.

It would be cool if composer supported this because their is no really popular tool for defining build-tasks in php.

Some use cases might be:

  • Running tests: "test": "vendor/bin/phpunit -c app"
  • Building your app: "build": "vendor/bin/box"
  • Make a release: "release": "composer run build && <bump version> && git tag <version>"
  • ...and many more
MaxGfeller added 2 commits Dec 19, 2013
event-scripts. This makes it possible for one to define their own
scripts like "make-release" etc.
@MaxGfeller
Copy link
Contributor Author

MaxGfeller commented Dec 19, 2013

Sorry have to rewrite that, tests didn't fail on my machine.

@substack
Copy link

substack commented Dec 19, 2013

If vendor/bin is a place that composer already uses it might be handy to unshift that onto $PATH when running commands so you can just "test": "phpunit -c app" instead of "test": "vendor/bin/phpunit -c app".

@MaxGfeller
Copy link
Contributor Author

MaxGfeller commented Dec 19, 2013

Yes if the package is installed globally then this is possible. Not sure what the best practice is, a lot of libraries do require-dev php-unit. Probably it's better to have it installed globally.

@max-voloshin
Copy link
Contributor

max-voloshin commented Dec 19, 2013

@MaxGfeller on my projects I prefer require-dev phpunit to prevent failed tests on CI that has unexpected phpunit version...

@bendavies
Copy link

bendavies commented Dec 19, 2013

+1 on this.
I have a need for a script that only runs Incenteev\\ParameterHandler\\ScriptHandler::buildParameters
I can't do this without defining my own script, as far as I can see.

@F21
Copy link

F21 commented Dec 21, 2013

+1 for this. Very useful for writing scripts to build and package up our app.

@tassoevan
Copy link

tassoevan commented Jan 2, 2014

+1

1 similar comment
@mbrevda
Copy link

mbrevda commented Jan 3, 2014

+1

@mbrevda mbrevda mentioned this pull request Jan 3, 2014
@MaxGfeller
Copy link
Contributor Author

MaxGfeller commented Jan 10, 2014

@Seldaek Any opinion on this?

@bonndan
Copy link

bonndan commented Jan 26, 2014

+1

@Seldaek Seldaek added the Feature label Jul 19, 2014
@Seldaek Seldaek modified the milestones: Urgent, Nice To Have Jul 19, 2014
@Seldaek Seldaek merged commit 067a8e7 into composer:master Jul 20, 2014
1 check passed
1 check passed
default The Travis CI build passed
Details
Seldaek added a commit that referenced this pull request Jul 20, 2014
@Seldaek
Copy link
Member

Seldaek commented Jul 20, 2014

Thanks! I finally merged this (sorry for the delay).

I also added the bin-dir to the PATH as @substack suggested, and I added an aliasing feature so that if you define for ex a script like "test":"phpunit ...", you can now just run composer test, which is even shorter than composer run-script test. Finally I added parameter passing so you can do composer test -- --filter Foo and phpunit will receive --filter Foo.

@MaxGfeller MaxGfeller deleted the MaxGfeller:run-script-enhancement branch Jul 20, 2014
@MaxGfeller
Copy link
Contributor Author

MaxGfeller commented Jul 20, 2014

This is huge! Thanks

@bonndan
Copy link

bonndan commented Jul 21, 2014

Awesome. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

9 participants
You can’t perform that action at this time.