-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboFile.php
66 lines (57 loc) · 2.33 KB
/
RoboFile.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
<?php
if (file_exists($composer = __DIR__ . '/vendor/autoload.php')) {
require_once $composer;
}
class RoboFile extends \Robo\Tasks
{
use \Generoi\Robo\Task\Placeholder\loadTasks;
public $machineName = 'wp-image-resizer';
public $name = 'WP Image Resizer';
public $namespace = 'ImageResizer';
public $description = 'A plugin which provides dynamic image sizes through a CDN';
public function rename($machineName = null, $options = [
'force' => false,
'namespace' => null,
'description' => null,
'name' => null,
])
{
$name = $options['name'];
$namespace = $options['namespace'];
$description = $options['description'];
if (empty($machineName)) {
$machineName = $this->askDefault('Machine name', $this->machineName);
}
if (empty($name)) {
$name = $this->askDefault('Plugin name', $this->name);
}
if (empty($namespace)) {
$namespace = $this->askDefault('Namespace', $this->namespace);
}
if (empty($description)) {
$description = $this->askDefault('Description', $this->description);
}
$result = $this->taskPlaceholderFind("$this->machineName|$this->name|$this->namespace|$this->description")
->directories(['src'])
->io($this->io())
->run();
$files = $result['files'];
if (count($files) > 0) {
if (empty($options['force'])) {
$options['force'] = $this->io()->confirm(sprintf('Do you want to replace names in these files?'));
}
if (!empty($options['force'])) {
$this->taskPlaceholderReplace($this->machineName)->with($machineName)->in($files)->run();
$this->taskPlaceholderReplace($this->name)->with($name)->in($files)->run();
$this->taskPlaceholderReplace($this->namespace)->with($namespace)->in($files)->run();
$this->taskPlaceholderReplace($this->description)->with($description)->in($files)->run();
}
if (in_array('./composer.json', $files)) {
$this->taskComposerDumpAutoload()->run();
}
}
if ($this->machineName !== $machineName) {
$this->_rename("{$this->machineName}.php", "{$machineName}.php");
}
}
}