forked from infinum/eightshift-libs
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuildCli.php
More file actions
99 lines (86 loc) · 2.11 KB
/
BuildCli.php
File metadata and controls
99 lines (86 loc) · 2.11 KB
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
99
<?php
/**
* Class that registers WPCLI command for BuildCli.
*
* @package EightshiftLibs\Build
*/
declare(strict_types=1);
namespace EightshiftLibs\Build;
use EightshiftLibs\Cli\AbstractCli;
/**
* Class BuildCli
*/
class BuildCli extends AbstractCli
{
/**
* Output dir relative path
*
* @var string
*/
public const OUTPUT_DIR = '../../../';
/**
* Get WPCLI command name
*
* @return string
*/
public function getCommandName(): string
{
return 'init_build';
}
/**
* Define default develop props
*
* @param array $args WPCLI eval-file arguments.
*
* @return array
*/
public function getDevelopArgs(array $args): array
{
return [
'root' => $args[1] ?? './',
];
}
/**
* Get WPCLI command doc.
*
* @return array
*/
public function getDoc(): array
{
return [
'shortdesc' => 'Initialize Command for building your project with one command, generally used on CI deployments.',
'synopsis' => [
[
'type' => 'assoc',
'name' => 'root',
'description' => 'Define project root relative to initialization file of WP CLI.',
'optional' => true,
],
[
'type' => 'assoc',
'name' => 'project_name',
'description' => 'Set project file name, if theme use theme folder name, if plugin use plugin folder name.',
'optional' => true,
],
[
'type' => 'assoc',
'name' => 'project_type',
'description' => 'Set project file name, if theme use theme folder name, if plugin use plugin folder name. Default is themes.',
'optional' => true,
],
],
];
}
public function __invoke(array $args, array $assocArgs) // phpcs:ignore
{
// Get Props.
$root = $assocArgs['root'] ?? static::OUTPUT_DIR;
// Read the template contents, and replace the placeholders with provided variables.
$class = $this->getExampleTemplate(__DIR__, $this->getClassShortName());
// Replace stuff in file.
$class = $this->renameProjectName($assocArgs, $class);
$class = $this->renameProjectType($assocArgs, $class);
// Output final class to new file/folder and finish.
$this->outputWrite($root . 'bin', 'build.sh', $class, $assocArgs);
}
}