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

Conversation

Projects
None yet
9 participants
@MaxGfeller
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 some commits Dec 19, 2013

Don't throw an exception if the called script is not one of the
event-scripts. This makes it possible for one to define their own
scripts like "make-release" etc.
@MaxGfeller

This comment has been minimized.

Show comment
Hide comment
@MaxGfeller

MaxGfeller Dec 19, 2013

Contributor

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

Contributor

MaxGfeller commented Dec 19, 2013

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

@substack

This comment has been minimized.

Show comment
Hide comment
@substack

substack 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".

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

This comment has been minimized.

Show comment
Hide comment
@MaxGfeller

MaxGfeller Dec 19, 2013

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@max-voloshin

max-voloshin Dec 19, 2013

Contributor

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

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

This comment has been minimized.

Show comment
Hide comment
@bendavies

bendavies 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.

+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

This comment has been minimized.

Show comment
Hide comment
@F21

F21 Dec 21, 2013

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

F21 commented Dec 21, 2013

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

@tassoevan

This comment has been minimized.

Show comment
Hide comment

+1

@mbrevda

This comment has been minimized.

Show comment
Hide comment

mbrevda commented Jan 3, 2014

+1

@mbrevda mbrevda referenced this pull request Jan 3, 2014

Closed

Test Command #1055

@MaxGfeller

This comment has been minimized.

Show comment
Hide comment
@MaxGfeller

MaxGfeller Jan 10, 2014

Contributor

@Seldaek Any opinion on this?

Contributor

MaxGfeller commented Jan 10, 2014

@Seldaek Any opinion on this?

@bonndan

This comment has been minimized.

Show comment
Hide comment

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

default The Travis CI build passed
Details
@Seldaek

This comment has been minimized.

Show comment
Hide comment
@Seldaek

Seldaek Jul 20, 2014

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@MaxGfeller

MaxGfeller Jul 20, 2014

Contributor

This is huge! Thanks

Contributor

MaxGfeller commented Jul 20, 2014

This is huge! Thanks

@bonndan

This comment has been minimized.

Show comment
Hide comment
@bonndan

bonndan Jul 21, 2014

Awesome. Thanks :)

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