{"id":33018382,"url":"https://github.com/CHH/bob","last_synced_at":"2025-11-16T14:00:35.259Z","repository":{"id":1940975,"uuid":"2870263","full_name":"CHH/bob","owner":"CHH","description":"Hi I'm Bob! I'm a tiny and messy build tool for PHP projects","archived":false,"fork":false,"pushed_at":"2024-11-06T15:33:59.000Z","size":934,"stargazers_count":105,"open_issues_count":4,"forks_count":5,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-27T08:54:21.621Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CHH.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-28T21:11:07.000Z","updated_at":"2025-01-23T12:10:30.000Z","dependencies_parsed_at":"2022-09-15T07:02:10.712Z","dependency_job_id":null,"html_url":"https://github.com/CHH/bob","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/CHH/bob","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHH%2Fbob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHH%2Fbob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHH%2Fbob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHH%2Fbob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CHH","download_url":"https://codeload.github.com/CHH/bob/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CHH%2Fbob/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284719042,"owners_count":27052182,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-16T02:00:05.974Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-11-13T18:00:39.567Z","updated_at":"2025-11-16T14:00:35.252Z","avatar_url":"https://github.com/CHH.png","language":"PHP","funding_links":[],"categories":["构建工具","Build Tools","构建工具( Build Tools )","构建工具 Build Tools"],"sub_categories":[],"readme":"Bob, your friendly builder\n==========================\n\n[![Build Status](https://travis-ci.org/CHH/bob.png?branch=master)](https://travis-ci.org/CHH/bob)\n\n- - -\n## Hello World\n\nPut this in a file named `bob_config.php` in your project's root:\n\n```php\n\u003c?php\n\nnamespace Bob\\BuildConfig;\n\ntask('default', ['hello']);\n\ntask('hello', function() {\n\techo \"Hello World!\\n\";\n});\n```\n\nRun this on your shell:\n\n```\n$ php composer.phar require chh/bob:~1.0@dev\n$ vendor/bin/bob\n```\n\n## What is Bob?\n\nThis is Bob. Bob is a lightweight project automation tool in PHP similar to Rake.\n\nBob _can_ be used as general build tool, but _really shines_ when used in PHP \nprojects as you are capable of reusing existing Application Code and Libraries \nin your buildfiles.\n\n**How Bob compares to [Pake](https://github.com/indeyets/pake):**\n\n - Bob uses a set of namespaced functions for the DSL, so PHP 5.3 __is a must__. \n   **If you need 5.2.x support, look at Pake.**\n - Bob's task definitions directly take a closure for the task's body,\n   instead of performing magic with functions named `run_\u003ctask name\u003e`.\n - Bob **has no** file finder similar to `pakeFinder`, if you need this\n   just use the [Symfony Finder](https://github.com/symfony/Finder).\n\n**How Bob compares to [Phing](http://www.phing.info/trac/):**\n\n - Bob **does not use XML config files** to define tasks. I think build\n   files should be written in the language used to write the project\n   itself so the barrier to contribution to build files is as low as possible. \n   Also I think it's quite hilarious to use XML for a DSL with logic and such.\n - Bob has nothing like plugins. To add new functions to Bob's DSL just\n   put them into the `Bob\\BuildConfig` namespace and require the file somehow at the\n   beginning of your build file. **Simply put:** Bob's build configs are _only_ PHP.\n - Bob has **no** rich set of provided tasks and I do not plan to add\n   this. _Bob is lightweight._\n\nGetting Started\n---------------\n\n### Install\n\n#### Prerequisites\n\nBob needs at least **PHP 5.3.2** to run. \n\nIf you plan to hack on Bob, please make sure you \nhave set `phar.readonly` to `Off` in your `php.ini`. Otherwise you will have a tough luck\ncreating a PHAR package of Bob.\n\n#### Install into a [Composer](https://github.com/composer/composer)-enabled Project (recommended)\n\nAdd the `chh/bob` package to the `require-dev` section in your\n`composer.json`:\n\n    {\n        \"require-dev\": {\n            \"chh/bob\": \"1.0.*@dev\"\n        }\n    }\n\nThen run `composer install --dev`.\n\nYou can invoke Bob with:\n\n    php vendor/bin/bob\n\nor:\n\n    ./vendor/bin/bob\n\n#### System-wide install (Unix-like OS only)\n\nTo do a system-wide install, download either a [Release][tags] or\nclone the Repository with:\n\n    $ git clone git://github.com/CHH/bob.git\n    $ cd Bob\n\n[tags]: https://github.com/CHH/bob/tags\n\nTo install all of Bob's dependencies download Composer and run\n`composer install`:\n\n    $ wget http://getcomposer.org/composer.phar\n    php composer.phar install\n\nThen run `php bin/bob install` and you're done.\n\nBy default the `bob` command is created in `/usr/local/bin`. To change\nthis set a `PREFIX` environment variable, the command is then created\nin `$PREFIX/bin`.\n\n### Prepare your project\n\nYou can output a usage message by running\n\n\t$ php vendor/bin/bob --help\n\nFirst run in your projects root directory Bob with the `--init` flag.\nThis creates an empty `bob_config.php` with one example task:\n\n    $ php vendor/bin/bob --init\n\nBob loads your tasks from a special file named `bob_config.php` in your project's\nroot directory. Bob also includes all files found in a directory\nnamed `bob_tasks`, in the same directory as your `bob_config.php`. Files loaded from\n`bob_tasks` are treated the same way as regular Bob configs.\n\nIt's important that you declare that this file belongs to the \n`Bob\\BuildConfig` namespace with `namespace Bob\\BuildConfig;`, otherwise the DSL functions are\nnot available.\n\n---\n\n**Hint:** It doesn't matter if you're in a sub-directory of your\nproject, Bob _will_ find your `bob_config.php` by wandering up\nthe directory tree.\n\n---\n\nNow let's define our first task. This task will output \"Hello World\":\n\n\ttask('hello', function() {\n\t\tprintln('Hello World');\n\t});\n\nTasks are run by using their name as argument(s) on the command line:\n\n\t$ php vendor/bin/bob hello\n\nWhen Bob is invoked without tasks it tries to invoke\nthe `default` task.\n\nTo set a task as default task assign the task as prerequisite\nof the `default` task:\n\n\ttask('default', array('hello'));\n\nYou know, tasks should be self-documenting, you really don't want a\nmanual for your build config or do you? Bob provides the\n`desc` function for that. Let's add some text to our task, which describes\nwhat the task is all about:\n\n\tdesc('Prints Hello World to the Command Line');\n\ttask('hello', function() {\n\t\tprintln('Hello World');\n\t});\n\nTo view all tasks and their descriptions pass the `--tasks` flag:\n\n\t$ php vendor/bin/bob --tasks\n\tbob hello # Prints Hello World to the Command Line\n\n---\n\nTo see more examples for how Bob can be used, simply look into Bob's\n`bob_config.php`. It contains all configuration to create Bob's build\nartifacts, for example the `bob.phar` and the composer config.\n\n### File Tasks\n\nA file task is a special kind of task, which gets only run if either the\ntarget (the product of some operation) does not exist, or the\nprerequisites are newer than the target.\n\nSo file tasks are very handy if you've some artifacts which are\ngenerated from other files, and which you don't want to regenerate\nif nothing has changed.\n\nFor example: Let's write a task which concatenates three input files to\none output file.\n\nFirst we have to create the prerequisites:\n\n    $ echo \"foo\\n\" \u003e file1.txt\n    $ echo \"bar\\n\" \u003e file2.txt\n    $ echo \"baz\\n\" \u003e file3.txt\n\nThen put this into your `bob_config.php`:\n\n    fileTask('concat.txt', array('file1.txt', 'file2.txt', 'file3.txt'), function($task) {\n        println(\"Concatenating\");\n        $concat = '';\n    \n        foreach ($task-\u003eprerequisites as $file) {\n            $concat .= file_get_contents($file);\n        }\n    \n        @file_put_contents($task-\u003ename, $concat);\n    });\n\nLet's run this task:\n\n    $ php vendor/bin/bob concat.txt\n    Concatenating\n\nThis will result in a `concat.txt` file in your project root:\n\n    $ cat concat.txt\n    foo\n    bar\n    baz\n\nLet's run it again, without modifying the prerequisites:\n\n    $ php vendor/bin/bob concat.txt\n\nSee it? The callback was not run, because the prerequisites were not modified.\n\nLet's verify this:\n\n    $ touch file1.txt\n    $ php vendor/bin/bob concat.txt\n    Concatenating\n\nThe prerequisites of a file task are also resolved as task names, so\nthey can depend on other file tasks too. Or you can put regular task\nnames into the prerequisites, but then you've to be careful to not\naccidentally treat them as files when looping through all prerequisites.\n\n### Packaging tasks for reusability\n\nEver did write a collection of tasks which you want to put into a\npackage and reuse across projects?\n\nEnter Task Libraries.\n\nAll task libraries implement the `\\Bob\\TaskLibraryInterface` which\ndefines two methods:\n\n* `register(\\Bob\\Application $app)`: Is called when the library is\n  registered in the app.\n* `boot(\\Bob\\Application $app)`: is called just before the Bob is run on\n  the command line. Register your tasks here.\n\nHere's a small example which registers a `test` task which uses PHPUnit:\n\n```php\n\u003c?php\n\nuse Bob\\Application;\nuse Bob\\TaskLibraryInterface;\nuse Bob\\BuildConfig as b;\n\nclass TestTasks implements TaskLibraryInterface\n{\n    function register(Application $app)\n    {}\n\n    function boot(Application $app)\n    {\n        $app-\u003efileTask(\"phpunit.xml\", array(\"phpunit.dist.xml\"), function($task) {\n            copy($task-\u003eprerequisites-\u003ecurrent(), $task-\u003ename);\n        });\n\n        $app-\u003etask(\"test\", array(\"phpunit.xml\"), function($task) {\n            b\\sh(\"./vendor/bin/phpunit\");\n\n        })-\u003edescription = \"Runs the test suite\";\n    }\n}\n```\n\nYou can use task libraries by calling the `register` function within\nyour build scripts:\n\n```php\n\u003c?php\n\nnamespace Bob\\BuildConfig;\n\nregister(new TestTasks);\n```\n\nYou will now see the `test` task when you run `./vendor/bin/bob\n--tasks`.\n\nHacking on Bob\n--------------\n\nThere are lots of ways to improve Bob, **but the most useful for me** is\nto simply submit Issues to the [Issue Tracker][issues].\n\n[issues]: http://github.com/CHH/bob/issues\n\n### Contributing Code\n\nI'm using the [Zend Framework Coding Standard][zfcs] in Bob and **so should you**\nwhen contributing code.\n\nActually I'm using a loose version of it, the notable differences are:\n\n - I'm treating the `public` keyword as optional in functions.\n - `var` is okay for defining public instance variables.\n\n[zfcs]: http://framework.zend.com/manual/en/coding-standard.html\n\n#### Documentation\n\nThe Code Documentation is all done with [Tomdoc](http://tomdoc.org),\nthough there isn't anything generated for now.\n\n#### Testing\n\nI'm not requiring unit tests for contributions, though functionality\nwhich affects the command line tool should be at least tried a couple of\ntimes.\n\nThis shouldn't prevent you from writing Unit Tests though. I'm using\n[PHPUnit](http://phpunit.de) for this purpose. There's also a `test`\ntask which runs `phpunit` (this handles the copying the `phpunit.dist.xml` to\n`phpunit.xml` too).\n\nI'm recommending [php-build](https://github.com/CHH/php-build) for doing\ntests with multiple versions of PHP.\n\n#### Building\n\nWhen you've done some changes and want to regenerate the `bob.phar`, simply\nrun Bob on itself:\n\n    $ php bin/bob.php\n\nTo run only the Test Suite:\n\n\t$ php bin/bob.php test\n\n(_In case you wonder that the PHAR gets sometimes not regenerated:_ It's\nonly regenerated when the actual source files for the archive change.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCHH%2Fbob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCHH%2Fbob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCHH%2Fbob/lists"}