Hi I'm Bob! I'm a tiny and messy build tool for PHP projects

Related tags

Build Tools bob
Overview

Bob, your friendly builder

Build Status


Hello World

Put this in a file named bob_config.php in your project's root:

<?php

namespace Bob\BuildConfig;

task('default', ['hello']);

task('hello', function() {
	echo "Hello World!\n";
});

Run this on your shell:

$ php composer.phar require chh/bob:~1.0@dev
$ vendor/bin/bob

What is Bob?

This is Bob. Bob is a lightweight project automation tool in PHP similar to Rake.

Bob can be used as general build tool, but really shines when used in PHP projects as you are capable of reusing existing Application Code and Libraries in your buildfiles.

How Bob compares to Pake:

  • Bob uses a set of namespaced functions for the DSL, so PHP 5.3 is a must. If you need 5.2.x support, look at Pake.
  • Bob's task definitions directly take a closure for the task's body, instead of performing magic with functions named run_<task name>.
  • Bob has no file finder similar to pakeFinder, if you need this just use the Symfony Finder.

How Bob compares to Phing:

  • Bob does not use XML config files to define tasks. I think build files should be written in the language used to write the project itself so the barrier to contribution to build files is as low as possible. Also I think it's quite hilarious to use XML for a DSL with logic and such.
  • Bob has nothing like plugins. To add new functions to Bob's DSL just put them into the Bob\BuildConfig namespace and require the file somehow at the beginning of your build file. Simply put: Bob's build configs are only PHP.
  • Bob has no rich set of provided tasks and I do not plan to add this. Bob is lightweight.

Getting Started

Install

Prerequisites

Bob needs at least PHP 5.3.2 to run.

If you plan to hack on Bob, please make sure you have set phar.readonly to Off in your php.ini. Otherwise you will have a tough luck creating a PHAR package of Bob.

Install into a Composer-enabled Project (recommended)

Add the chh/bob package to the require-dev section in your composer.json:

{
    "require-dev": {
        "chh/bob": "1.0.*@dev"
    }
}

Then run composer install --dev.

You can invoke Bob with:

php vendor/bin/bob

or:

./vendor/bin/bob

System-wide install (Unix-like OS only)

To do a system-wide install, download either a Release or clone the Repository with:

$ git clone git://github.com/CHH/bob.git
$ cd Bob

To install all of Bob's dependencies download Composer and run composer install:

$ wget http://getcomposer.org/composer.phar
php composer.phar install

Then run php bin/bob install and you're done.

By default the bob command is created in /usr/local/bin. To change this set a PREFIX environment variable, the command is then created in $PREFIX/bin.

Prepare your project

You can output a usage message by running

$ php vendor/bin/bob --help

First run in your projects root directory Bob with the --init flag. This creates an empty bob_config.php with one example task:

$ php vendor/bin/bob --init

Bob loads your tasks from a special file named bob_config.php in your project's root directory. Bob also includes all files found in a directory named bob_tasks, in the same directory as your bob_config.php. Files loaded from bob_tasks are treated the same way as regular Bob configs.

It's important that you declare that this file belongs to the Bob\BuildConfig namespace with namespace Bob\BuildConfig;, otherwise the DSL functions are not available.


Hint: It doesn't matter if you're in a sub-directory of your project, Bob will find your bob_config.php by wandering up the directory tree.


Now let's define our first task. This task will output "Hello World":

task('hello', function() {
	println('Hello World');
});

Tasks are run by using their name as argument(s) on the command line:

$ php vendor/bin/bob hello

When Bob is invoked without tasks it tries to invoke the default task.

To set a task as default task assign the task as prerequisite of the default task:

task('default', array('hello'));

You know, tasks should be self-documenting, you really don't want a manual for your build config or do you? Bob provides the desc function for that. Let's add some text to our task, which describes what the task is all about:

desc('Prints Hello World to the Command Line');
task('hello', function() {
	println('Hello World');
});

To view all tasks and their descriptions pass the --tasks flag:

$ php vendor/bin/bob --tasks
bob hello # Prints Hello World to the Command Line

To see more examples for how Bob can be used, simply look into Bob's bob_config.php. It contains all configuration to create Bob's build artifacts, for example the bob.phar and the composer config.

File Tasks

A file task is a special kind of task, which gets only run if either the target (the product of some operation) does not exist, or the prerequisites are newer than the target.

So file tasks are very handy if you've some artifacts which are generated from other files, and which you don't want to regenerate if nothing has changed.

For example: Let's write a task which concatenates three input files to one output file.

First we have to create the prerequisites:

$ echo "foo\n" > file1.txt
$ echo "bar\n" > file2.txt
$ echo "baz\n" > file3.txt

Then put this into your bob_config.php:

fileTask('concat.txt', array('file1.txt', 'file2.txt', 'file3.txt'), function($task) {
    println("Concatenating");
    $concat = '';

    foreach ($task->prerequisites as $file) {
        $concat .= file_get_contents($file);
    }

    @file_put_contents($task->name, $concat);
});

Let's run this task:

$ php vendor/bin/bob concat.txt
Concatenating

This will result in a concat.txt file in your project root:

$ cat concat.txt
foo
bar
baz

Let's run it again, without modifying the prerequisites:

$ php vendor/bin/bob concat.txt

See it? The callback was not run, because the prerequisites were not modified.

Let's verify this:

$ touch file1.txt
$ php vendor/bin/bob concat.txt
Concatenating

The prerequisites of a file task are also resolved as task names, so they can depend on other file tasks too. Or you can put regular task names into the prerequisites, but then you've to be careful to not accidentally treat them as files when looping through all prerequisites.

Packaging tasks for reusability

Ever did write a collection of tasks which you want to put into a package and reuse across projects?

Enter Task Libraries.

All task libraries implement the \Bob\TaskLibraryInterface which defines two methods:

  • register(\Bob\Application $app): Is called when the library is registered in the app.
  • boot(\Bob\Application $app): is called just before the Bob is run on the command line. Register your tasks here.

Here's a small example which registers a test task which uses PHPUnit:

<?php

use Bob\Application;
use Bob\TaskLibraryInterface;
use Bob\BuildConfig as b;

class TestTasks implements TaskLibraryInterface
{
    function register(Application $app)
    {}

    function boot(Application $app)
    {
        $app->fileTask("phpunit.xml", array("phpunit.dist.xml"), function($task) {
            copy($task->prerequisites->current(), $task->name);
        });

        $app->task("test", array("phpunit.xml"), function($task) {
            b\sh("./vendor/bin/phpunit");

        })->description = "Runs the test suite";
    }
}

You can use task libraries by calling the register function within your build scripts:

<?php

namespace Bob\BuildConfig;

register(new TestTasks);

You will now see the test task when you run ./vendor/bin/bob --tasks.

Hacking on Bob

There are lots of ways to improve Bob, but the most useful for me is to simply submit Issues to the Issue Tracker.

Contributing Code

I'm using the Zend Framework Coding Standard in Bob and so should you when contributing code.

Actually I'm using a loose version of it, the notable differences are:

  • I'm treating the public keyword as optional in functions.
  • var is okay for defining public instance variables.

Documentation

The Code Documentation is all done with Tomdoc, though there isn't anything generated for now.

Testing

I'm not requiring unit tests for contributions, though functionality which affects the command line tool should be at least tried a couple of times.

This shouldn't prevent you from writing Unit Tests though. I'm using PHPUnit for this purpose. There's also a test task which runs phpunit (this handles the copying the phpunit.dist.xml to phpunit.xml too).

I'm recommending php-build for doing tests with multiple versions of PHP.

Building

When you've done some changes and want to regenerate the bob.phar, simply run Bob on itself:

$ php bin/bob.php

To run only the Test Suite:

$ php bin/bob.php test

(In case you wonder that the PHAR gets sometimes not regenerated: It's only regenerated when the actual source files for the archive change.)

You might also like...
PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

P H I N G Thank you for using PHING! PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything wit

PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

P H I N G Thank you for using PHING! PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything wit

Takeout is a CLI tool for spinning up tiny Docker containers, one for each of your development environment dependencies.
Takeout is a CLI tool for spinning up tiny Docker containers, one for each of your development environment dependencies.

Takeout Takeout is a CLI tool for spinning up tiny Docker containers, one for each of your development environment dependencies. It's meant to be pair

Laravel Admin Dashboard, Admin Template with Frontend Template, for scalable Laravel projects. It is to save your time when You start with new scalable Laravel projects with many features Bootstrap, cooreui, infyom admin Generator, roles and  permissions, translatable models, spatie media and much more
A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

A tiny PHP class-based program to analyze an input file and extract all of that words and detect how many times every word is repeated

Tiny php mysql lib (PDO-based) with handy fetch/update functionality, supports both SQL and parametric queries

Micro PHP mysql lib (~ 200 lines of code) with ultra powerful CRUD for faster than ever development: parametric fetch/insert/update/delete (based on a

Tiny PHP library providing retry functionality with multiple backoff strategies and jitter support

JBZoo / Retry 4 retry strategies (plus the ability to use your own) Optional jitter / randomness to spread out retries and minimize collisions Wait ti

Tiny, fast and simple PHP boilerplate built on top of FlightPHP

BlessPHP Tiny, fast and simple PHP boilerplate built on top of FlightPHP. Good enough to use as skeleton for prototypes and some pet-projects. The nam

Tiny hands is a Laravel multi-tenant boilerplate with SPA and i18n.

About Tiny Hands Tiny hands is a Laravel multi-tenant boilerplate with SPA and i18n using the following technology stack: Backend Laravel 8.0 API with

Boost the speed of Kirby by having content files of pages cached, with automatic unique ID, fast lookup and Tiny-URL.

🚀 Kirby3 Boost ⏱️ up to 3x faster content loading 🎣 fastest page lookup and resolution of relations Boost the speed of Kirby by having content files

A tiny REPL for PHP

Boris A tiny, but robust REPL for PHP. Announcement: I'm looking to add one or two additional collaborators with commit access. If you are actively in

A tiny, yet powerful, PHP micro-framework.

Equip Framework A tiny and powerful PHP micro-framework created and maintained by the engineering team at When I Work. Attempts to be PSR-1, PSR-2, PS

Biny is a tiny, high-performance PHP framework for web applications

Biny is high performance. Framework comes default with response time of less than 1ms. Stand-alone QPS easily up to 3000.

Wake PC is a super tiny password protected webapp for linux machines that sends WOL packets, written in PHP.
Wake PC is a super tiny password protected webapp for linux machines that sends WOL packets, written in PHP.

Wake PC Wake PC is a super tiny password protected webapp for linux machines that sends WOL packets, written in PHP. How to set up Quick setup You can

Tiny PHP lib to transform a number into french words.

Number To FR Words English I've written this tiny library to easily transform a number into french words. This project came up when I had to automatic

A tiny REPL for PHP

Boris A tiny, but robust REPL for PHP. Announcement: I'm looking to add one or two additional collaborators with commit access. If you are actively in

YouTubeClone - Web Projects Build By Laravel Framework v8 & LiveWire it's Small project to upload video Like Youtube
YouTubeClone - Web Projects Build By Laravel Framework v8 & LiveWire it's Small project to upload video Like Youtube

YouTubeClone YouTubeClone - Web Projects Build By Laravel Framework & LiveWire it's Small project to upload video Like Youtube Use Laravel v8.80.0 Ima

WordPress Tiny Snippets

WordPress Tiny Snippets [+] :: Info/Инфо: [ 🇺🇸 ] Collection of tiny snippets for WordPress CMS.

PIP is a tiny application framework built for people who use a LAMP stack.

PIP is a tiny application framework built for people who use a LAMP stack. PIP aims to be as simple as possible to set up and use.

Comments
  • Task Groups

    Task Groups

    :+1: this Feature to vote for it.

    I'm not entirely sold on this, because you can already namespace tasks simply by putting a ":" in the name, for example assets:dump.

    Syntax could look like this:

    group("assets", function($g) {
        $g->task("dump", function() {
        # ...
        });
    });
    

    or like this:

    task("foo", function() {});
    
    group("assets", function() {
        # some group prerequisite
        task('foo', function() {});
    
        # Tasks are first looked up in the current group, so the group's "foo" task is invoked:
        task("dump", array('foo'), function() {
        # ...
        });
    });
    
    Discussion 
    opened by CHH 1
Owner
Christoph Hochstrasser
Christoph Hochstrasser
A PHP project/micro-package generator for PDS compliant projects or micro-packages.

Construct A PHP project/micro-package generator for PDS compliant projects or micro-packages. Installation Construct should be installed globally thro

Jonathan Torres 263 Sep 28, 2022
The tool converts different error reporting standards for deep compatibility with popular CI systems (TeamCity, IntelliJ IDEA, GitHub Actions, etc).

JBZoo / CI-Report-Converter Why? Installing Using as GitHub Action Example GitHub Action workflow Available Directions Help description in terminal Co

JBZoo Toolbox 17 Jun 16, 2022
GitHub action to setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer...

Setup PHP in GitHub Actions Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer in GitHub

Shivam Mathur 2.4k Jan 6, 2023
An application for building and managing Phars.

This project has been moved to https://github.com/box-project/box If you are looking to upgrade, don't forget to have a look at the upgrade guide. Box

Box Project 1.2k Nov 9, 2022
Danger runs during your CI process, and gives teams the chance to automate common code review chores.

Danger runs during your CI process, and gives teams the chance to automate common code review chores. This project ports Danger to PHP. This project is still in the early phase. Feel free to try it out and contribute!

Shyim 55 Dec 7, 2022
GitHub Action that diffs composer.lock between current branch and default branch

github-action-composer.lock-diff GitHub Action that diffs composer.lock between current branch and default branch Options (inputs) This action support

Cees-Jan Kiewiet 13 Oct 31, 2022
Unpacking and packaging for Qualcomm splash images

Magic Splash Wand Magic Splash!! Wand Unpacking and packaging for Qualcomm splash images. How to use Download and install PHP for your system from the

Jim Wu 6 Oct 25, 2022
A starter-kit for your PHP project.

PHP Noise A starter-kit for your PHP project. It includes frequently needed boilerplate setups (ci, badges, etc.) ?? Installation To install this appl

medunes 52 Dec 17, 2022
remake of doxbin in php

DOXBIN $Version V1.6 $Warnings [ THIS IS NOT THE ORG SRC OF DOXBIN.ORG, PLEASE DON'T FALSE CLAIM AROUND SAYING U HACKED DOXBIN, THE OWNER OF DOXBIN IS

Nano 28 Dec 1, 2021
Phpake is a make-like utility built for PHP.

Phpake is a make-like utility built for PHP. It is pronounced fake because the second p is silent just like the second p in the word elephpant.

Jigar Mehta 8 Jul 26, 2022