Giter VIP home page Giter VIP logo

phake's Introduction

phake - Rake/Make for PHP 5.3 Build Status

© 2010 Jason Frame [ [email protected] / @jaz303 ]
Released under the MIT License.

A wee clone of Ruby's rake for PHP 5.3. Uses closures for ultimate coolness.

Questions abut phake? Come and chat in #phake on Freenode!

Usage

  • Download
  • Create a Phakefile in the current directory or a parent directory
  • Invoke ./phake task:name to invoke task or ./phake -T to list defined tasks

Defining Tasks

Define tasks like this:

task('dependency1', function() {
    echo "i will run first!\n";
});

task('dependency2', function() {
    echo "i will run second!\n";
});

task('task_name', 'dependency1', 'dependency2', function() {
    echo "i will run last!\n";
});

This task would be invoked from the command line by ./phake task_name

Task bodies are optional if you want to create some sort of "super-task" that just invokes a bunch of others:

task('foo', 'dep1', 'dep2');

And multiple bodies can be added to tasks, all of which will be executed when the task is invoked:

task('foo', function() { echo "task work item 1\n"; });
task('foo', function() { echo "task work item 2\n"; });

Grouping Tasks

Like Rake, we can group tasks:

group('db', function() {
    task('init', function() {
        echo "i'm initialising the database\n";
    });
});

This would be invoked by ./phake db:init

Describing Tasks

Call desc() immediately before defining a task to set its description:

desc("Initialises the database");
task('db_init', function() { echo "oh hai it's a database\n"; });

Output from ./phake -T:

db_init    Initialises the database

After/Before Blocks

Sometimes you may want to specify that some code should run before or after a task (distinct from dependencies), a bit like Capistrano. Phake supports this:

before('foo', function() { ... });
after('baz:bar', function() { ... });

Task Arguments

Phake allows arguments to specified on the command line:

# Execute task `quux` with the given args
./phake quux name=Jason city=Glasgow

This format must be matched exactly; do not put spaces between = and the argument name/value. If you need to put spaces in the argument value, place the entire assignment in quotes.

Arguments are made available to tasks by the application object's ArrayAccess implementation:

task('task_with_args', function($app) {
    $name = $app['name'];
    $city = $app['city'];
    // do some stuff...
});

Aborting Execution

To abort execution of a task sequence, simply throw an exception.

desc('Demonstrate failure');
task('fail', function() {
    throw new Exception;
});

Running phake fail will yield:

- jason@disco phake % ./bin/phake fail
(in /Users/jason/dev/projects/phake)
aborted!
Exception 

(See full trace by running task with --trace)

A Somewhat More Complete Example

This is what a complete Phakefile might look like. It also highlights some of the more complex name resolution issues arising when dealing with groups.

<?php
desc('Load the application environment');
task('environment', function() {
    echo "I am the outer environment. I should run first.\n";
});

desc('Initialises the database connection');
task('database', function() {
    echo "I am initialising the database...\n";
});

group('test', function() {

    // 'environment' dependency for this task is resolved locally to
    // task in same group. There is no 'database' task defined in this
    // group so it drops back to a search of the root group.
    desc('Run the unit tests');
    task('units', 'environment', ':environment', 'database', function() {
        echo "Running unit tests...\n";
    });

    // another level of nesting; application object is passed to all
    // executing tasks
    group('all', function() {
        desc('Run absolutely every test everywhere!');
        task('run', 'test:units', function($application) {
            echo "All tests complete! ($application)\n";
        });
    });

});

// duplicate group definitions are merged
group('test', function() {

    // duplicate task definitions are merged
    // (although the first description takes precedence when running with -T)
    desc("You won't see this description");
    task('units', function() {
        echo "Running a second batch of unit tests...\n";
    });

    // use ':environment' to refer to task in root group
    // we currently have no cyclic dependency checking, you have been warned.
    task('environment', ':environment', function() {
        echo "I am the inner environment. I should run second.\n";
    });

});

task('default', 'test:all:run');
?>

Here's the output from ./phake (implied task to run is default):

jason@ratchet phake [master*] $ ./phake
(in /Users/jason/dev/projects/phake)
I am the outer environment. I should run first.
I am the inner environment. I should run second.
I am initialising the database...
Running unit tests...
Running a second batch of unit tests...
All tests complete! (<phake\Application>)

And the corresponding output from phake -T:

jason@ratchet phake [master*] $ ./phake -T
(in /Users/jason/dev/projects/phake)
database        Initialises the database connection
environment     Load the application environment
test:all:run    Run absolutely every test everywhere!
test:units      Run the unit tests

Bash Autocompletion

Bashkim Isai has created phake-autocomplete, a bash-completion script for phake task names.

phake's People

Contributors

benatkin avatar check002 avatar clue avatar denzel-morris avatar jaz303 avatar kpitn avatar mamchenkov avatar mekras avatar mhumpula avatar miezuit avatar swichers avatar tamagokun avatar trq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phake's Issues

Phake autocomplete

What is the recommended way to add autocompletion for phake?

The repository contains a phake_completion.sh with no instructions whatsoever, while its README links to bashaus/phake-autocomplete.

It's probably safer to recommend the preferred way and add the required documentation to the README.

Running `group` should run `group:default` if it exists and no `group` task exists

Ideally phake would use the following order of precedence to determine which task to run:

  1. A task with the exact name within the current or named group
  2. The default task in the current group
  3. Error

That means if I have tasks for default, build, run, test, deploy, db:init, db:update, db:delete and db:default, test:init, test:run, and test:default, the following behaviour is expected:

  1. Running phake run would execute run
  2. Running phake default would execute default
  3. Running phake would execute default
  4. Running phake db:init would execute db:init
  5. Running phake db:default would execute db:default
  6. Running phake db would execute db:default
  7. Running phake test:init would execute test:init
  8. Running phake test:default would execute test:default
  9. Running phake test would execute test (there's a named task called test which has higher precedence than test:default)

As far as I can tell, that mimics the behaviour of the root :default task fairly closely without breaking compatibility with existing Phakefiles.

Fatal error: Cannot redeclare builder() when use composer

i use composer install phake,
and in Phakefile there is "require 'vendor/autoload.php;"

when i run 'vendor\bin\phake taskname'
error occur

Fatal error: Cannot redeclare builder() (previously declared in G:\www\laravel4\
lang\vendor\jaz303\phake\lib\functions.php:2) in G:\www\laravel4\lang\vendor\jaz
303\phake\lib\functions.php on line 7

that's because functions.php is included by phake and comoser,
is there any solution to solve this ?

Use a real option parser

When I originally wrote phake I hand-rolled the command line option parser because PHP's getopt functions were useless and the only alternative was to pull in half of PEAR to get access to a better one. However, we're now living in the age of Composer/Packagist, and a cursory search showed there to be a number of independently maintained possible alternatives.

What are everyone's thoughts about switching to a more robust option parser? Does anybody have a preferred package?

Task name is missing when TaskNotFoundException is logged

If you try to run a build script that has an invalid or missing task name, this is what you see:

(in /snip)
PHP Notice:  Undefined variable: task_name in /snip/vendor/jaz303/phake/lib/phake/Bin.php on line 115

Notice: Undefined variable: task_name in /snip/vendor/jaz303/phake/lib/phake/Bin.php on line 115 aborted!
Don't know how to build task ''


(See full trace by running task with --trace)

numeric (i.e. param=0) arguments

I was writing a phake task that takes a numeric argument (eg: phake some:task backup=[0|1] ) when I noticed what I would call a little bug: in the argument I was getting the array: " [0] => "backup" instead of ["backup"] => 0. I looked in the code and I verified that the function empty() is used (lib/phake:14). I changed it to ( !isset() ) and it's working like I need.

diff:

'''
diff --git a/lib/phake.php b/lib/phake.php
index c432d55..5cf6bef 100644
--- a/lib/phake.php
+++ b/lib/phake.php
@@ -11,7 +11,7 @@ class Utils
$pos = 0;
foreach ($args as $arg) {
list($k, $v) = explode('=', $arg);

  •        if (empty($v)) {
    
  •        if (!isset($v)) {
             $out[$pos++] = $k;
         } else {
             $out[$k] = $v;
    
    @@ -221,4 +221,4 @@ class Task
    }
    }
    }
    -?>
    \ No newline at end of file
    +?>
    '''

Include automatic CLEAN and CLOBBER tasks

It would be nice to have semi-automatic cleaning tasks like in Rake. These could be activated simply by adding entries to their global variable, like $CLEAN->add(array('some/path'));

Documentation on how to abort tasks

I was playing around with Phake, trying to abort a sequence of tasks if one failed.

Noticed that returning false does nothing to the super-task sequence. However, thrown exceptions become nice error messages in the console, but this is not documented in the README :(

Grouped tasks broken after v0.5.1

A change after version 0.5.1 seems to have broken grouped tasks. In the example below, the db:init task works, but db:console and db:migrate do not:

task('environment', function () {
    echo 'environment', "\n";
});

group('db', function () {
    desc('Verify that the database is configured correctly. No message means it works.');
    task('init', 'environment', function () {
        echo 'db:init', "\n";
    });

    desc('Open the PostgreSQL interactive terminal command');
    task('console', 'init', function () {
        echo 'db:console', "\n";
    });

    desc('Migrate the database');
    task('migrate', 'init', function () {
        echo 'db:migrate', "\n";
    });
});

desc('Generate a random string consisting of 0-9a-z characters. Default: length=16');
task('randstr', 'environment', function ($args) {
    echo 'randstr', "\n";
});

PSR-2 Coding Style Guide

Phake currently uses its own coding standard, which is somewhat similar to PSR-2.

Would you accept a PR that changes it to conform to PSR-2?

wrong task name for multiple group

for this code :

group('A', function(){
  group('B', function(){
    task('C', function(){});
  });
});

phake -T returns B:A:C instead of A:B:C

Invoking multiple tasks does not work

Phakefile.php

task('a', function() { echo 'a'; });
task('b', function() { echo 'b'; });

Invoking phake a b:

Expected Output: ab
Actual Output: a

Phake seems to ignore any additional task names and thus is not quite in line with how rake/make work.

Fix should be rather easy, but I'm opening this as a reminder for the time being. Also, we might want to discuss if we could even consider this a feature.

Personally, I've (ab)used this feature as a nicer syntax to pass additional arguments to a task like this:

task('dump', function() {
  $dump = argv(2);
  echo file_get_contents($path);
});

So running phake dump index.php would run the dump task which processes any additional arguments internally. I understand that this might be an unwanted side-effect, but it certainly adds to a nicer syntax than the usual phake dump path=index.php.

New release?

Would love to introduce some new Pomander code that uses the latest Phake stuff.

Having to depend on the master branch is a pain with Composer. Can someone cut a release or is it not ready?

Add semver compatible tags (e.g. v1.0.0)

Makes the packagist integration a bit nicer and allows composer to cache the repository making updating packages a lot faster (in the context of a build server this can save several minutes).

Passing arguments to tasks

Hi,
great clone of Rake i'm using it for almost all my scripts

Have you though about passing arguments to tasks?
that would be great.

Nice work.

Include File and Directory tasks

As in Rake, or the historical Make, it would be convenient to have file/directory task helpers, which would run based on the modification timestamps of the file/directory matching the task name.

task listing is completely broken

Running bin/phake -T from master branch:

PHP Notice:  Undefined property: phake\Node::$tasks in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 118

Notice: Undefined property: phake\Node::$tasks in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 118
PHP Fatal error:  Call to undefined method phake\Node::dependencies() in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 114

Fatal error: Call to undefined method phake\Node::dependencies() in /Users/mkruk/Sites/php/phake/lib/phake/Node.php on line 114

Is phake alive

Hello,
I see some usefull ticket in pr but no commit since some months so I'm wondering if this project is still alive ?

last tagged version 0.6.0 or 0.5.2

Hello,
Watching the commit history it seems that tag 0.5.2 is newer than 0.6.
Is that normal ?
Which one is the last stable version ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.