/
phulpfile.php
98 lines (87 loc) · 2.85 KB
/
phulpfile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
use Phulp\Output as out;
// Define the default task
$phulp->task('default', function ($phulp) {
out::out(out::colorize('Arguments:', 'green'));
out::out(print_r($phulp->getArguments(), true));
$phulp->start(['clean', 'iterate_src_folder', 'sync_command', 'async_command']);
if ($phulp->getArgument('repeat-clean', false)) {
out::out(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::out(sprintf(
'%s %s' . PHP_EOL,
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::out($line . PHP_EOL); },
'onStdErr' => function ($line) { },
'onFinish' => function ($exitCode, $stdOut, $stdErr) { },
]
);
$exitCode = $command->getExitCode();
$stdout = $command->getStdout();
$stderr = $command->getStderr();
out::out('done' . PHP_EOL);
});
// 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::out('done' . PHP_EOL);
});
// Define the watch task
$phulp->task('watch', function ($phulp) {
// Phulp will watch 'src' folder
$phulp->watch(
$phulp->src(['src/*php']),
function ($phulp, $distFile) {
out::out(sprintf(
'%s %s' . PHP_EOL,
out::colorize('File Changed ->', 'green'),
out::colorize($distFile->getFullPath() . DIRECTORY_SEPARATOR . $distFile->getName(), 'blue')
));
$phulp->start(['default']);
}
);
});