reisraff/phulp

PHP 任务管理器

2.1.1 2019-08-01 17:47 UTC

README

phulp

PHP 任务管理器

Latest Stable Version Total Downloads Latest Unstable Version License Build Status

原因

有时候我需要 Gulp 这样的工具来处理我的 PHP 项目,但我不想只为了安装 Gulp 而安装 npm。我想“我需要一个像 Gulp 一样的工具,但它是 PHP 的”。经过一点研究,我发现 Phing,但它并不专注于 CSS/JS 和相关前端内容的压缩和管理。

所以,我决定写 Phulp,Gulp 的 PHP 版本!还有一个小小的发现:它比 Gulp 快。

PS:我使用了 PHP 7 进行了基准测试

文档

插件

像 Gulp 一样,我们也有插件,你也可以创建自己的。

你可以在 Phulp 页面 的插件部分找到可用的插件。

要使你的插件在 Phulp 插件页面上可用,请在你的项目 composer.json 文件中添加关键词 "phulpplugin",并且别忘了留下一个酷炫的 composer.json 描述。

并且将你的 GitHub 项目标记为 "phulpplugin""phulp",以便在 GitHub 上可搜索。

用法

安装
$ composer require --dev reisraff/phulp
创建你的 Phulpfile(配置文件,描述所有任务)
<?php

use Phulp\Output as out;

// Define the default task
$phulp->task('default', function ($phulp) {
    out::outln(out::colorize('Arguments:', 'green'));
    out::outln(print_r($phulp->getArguments(), true));

    $phulp->start(['clean', 'iterate_src_folder', 'sync_command', 'async_command']);
    if ($phulp->getArgument('repeat-clean', false)) {
        out::outln(out::colorize('Repeating "clean"', 'green'));
        $phulp->start(['clean']);
    }
});

// Define the clean task
$phulp->task('clean', function ($phulp) {
    if (! file_exists('dist')) {
        mkdir('dist');
    }
    $phulp->src(['dist/*'])
        ->pipe($phulp->clean());
});

// Define the iterate_src_folder task
$phulp->task('iterate_src_folder', function ($phulp) {
    // Define the source folder
    $phulp->src(['src/*php'])
        ->pipe($phulp->iterate(function ($file) {
            out::outln(sprintf(
                '%s %s',
                out::colorize('Iterated ->', 'green'),
                out::colorize($file->getFullPath() . DIRECTORY_SEPARATOR . $file->getName(), 'blue')
            ));
        }))
        ->pipe($phulp->dest('dist/'));
});

// Define the sync_command task
$phulp->task('sync_command', function ($phulp) {
    $command = $phulp->exec(
        'sleep 1 && echo $MSG',
        [
            'env' => [
                'MSG' => 'Sync-command'
            ],
            'cwd' => '/tmp',
            'sync' => true, // defines sync,
            'quiet' => true,
            'onStdOut' => function ($line) { out::outln($line); },
            'onStdErr' => function ($line) { },
            'onFinish' => function ($exitCode, $stdOut, $stdErr) { },
        ]
    );

    $exitCode = $command->getExitCode();
    $stdout = $command->getStdout();
    $stderr = $command->getStderr();

    out::outln('done');
});

// Define the async_command task
$phulp->task('async_command', function ($phulp) {
    $command = $phulp->exec(
        'sleep 1 && echo $MSG',
        [
            'env' => [
                'MSG' => 'Async-command'
            ],
            'cwd' => '/tmp',
            'sync' => false, // defines async,
            'quiet' => false,
            'onStdOut' => function ($line) { },
            'onStdErr' => function ($line) { },
            'onFinish' => function ($exitCode, $stdOut, $stdErr) { },
        ]
    );

    out::outln('done');
});

// Define the watch task
$phulp->task('watch', function ($phulp) {
    // Phulp will watch 'src' folder
    $phulp->watch(
        $phulp->src(['src/*php']),
        function ($phulp, $distFile) {
            out::outln(sprintf(
                '%s %s',
                out::colorize('File Changed ->', 'green'),
                out::colorize($distFile->getFullPath() . DIRECTORY_SEPARATOR . $distFile->getName(), 'blue')
            ));
            $phulp->start(['default']);
        }
    );
});
运行

Phulpfile 目录上运行 phulp

如果你没有配置 bin 目录

$ vendor/bin/phulp --help
$ vendor/bin/phulp # Will run the `default` task
$ vendor/bin/phulp --arg=repeat-clean:true # Will run the `default` task with the argument repeat-clean with value `true`
$ vendor/bin/phulp --autoload=/my/autoload/path/autoload.php # Will run the `default` task adding a alternative autoload php file
$ vendor/bin/phulp watch # Will run the `watch` task
完整文档

文档

示例

https://github.com/reisraff/phulp/blob/master/example/phulpfile.php

运行示例文件

$ composer install
$ cd example
$ ../bin/phulp
$ ../bin/phulp watch

贡献指南

克隆

$ git clone git@github.com:reisraff/phulp.git
$ cd phulp
$ composer install

测试

首先安装依赖项,然后你可以运行

$ bin/phulp test

待办事项

此存储库的“问题”页面正在用于待办事项管理。

致谢

@reisraff