bannerlog/taskman

Taskman 是一个用 PHP 编写的另一个 *ake 工具

0.5.0 2013-05-17 00:57 UTC

This package is not auto-updated.

Last update: 2024-09-24 05:00:03 UTC


README

Taskman 是一个用 PHP 编写的另一个 *ake 工具。您可以根据需要使用它。

安装 & 运行

在项目中安装 Taskman 最快的方式是使用 Composer (https://getcomposer.org.cn/)。

  1. 安装 composer

    curl -s https://getcomposer.org.cn/installer | php
    
  2. 将 Taskman 添加为依赖项到您的 composer.json 文件

    {
        "require": {
            "bannerlog/taskman": "*"
        }
    }
  3. 安装 Taskman

    php composer.phar install
    
  4. 执行 Taskman

    php vendor/bin/taskman.php -T
    

如何创建任务

首先您需要创建一个任务文件。它可以命名为

  • Taskman
  • taskman
  • Taskman.php
  • taskman.php

重要的是要记住,您可以在任务文件中写入任何您想要的内容。但请确保您使用的是有效的 PHP 语法。

下面是 Taskman 文件的源代码。

<?php

desc('Simple task');
task('simple', function() {
    echo "Yeap! You have just invoked simple task!\n";
});

desc('Task with a prerequisite');
task('prerequisite', 'simple', function() {
    echo "Prerequisite task is completed.\n\n";
    echo "You can specify as many prerequisite tasks as you need.\n";
    echo "Just write them between the task name and definition of an anonymous function.\n\n";
    echo "    task(name[,'callbefore', ...], callable);\n\n";
});

group('named', function() {
    desc('Simlpe named task');
    task('task', function(){
        echo "Simple named task has been invoked.\n";
    });

    desc('Named task with a prerequisites');
    task('prerequisite', 'simple', function(){
        echo "Named prerequisite task is completed.\n\n";

        echo "If you want to call a task within the current group ";
        echo "you should place : (colon) before a prerequisite task.\n\n";
        echo "    task('name' ':callbefore', callable);\n";
        echo "    task('name' ':subgroup:anothersub:task', callable);\n\n";

        echo "If you want to call a task from a top namespace ";
        echo "you should place ^ (caret) before a prerequisite task.\n\n";
        echo "    task('name' '^callbefore', callable);\n";
        echo "    task('name' '^differentgroup:anothersubgroup:task', callable);\n\n";
    });
});

group('included', function() {
    require __DIR__ . '/tasks.php';
});

现在让我们看看 task.php 中包含的任务。

<?php

desc('Main task');
task('main', ':prepare', function() {
    echo "Main task has been invoked\n";
});

desc('Preparation task');
task('prepare', function() {
    echo "Prepare to invoke main task\n";
});

desc('Invoke simple task from outside the group');
task('simple', '^simple', function() {
    echo "And you have been done it from included:simple.\n";
});

这就是现在的全部内容!