-
Notifications
You must be signed in to change notification settings - Fork 2
/
ci4-install.php
executable file
·84 lines (68 loc) · 2.23 KB
/
ci4-install.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
#!/usr/bin/env php
<?php
//--------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------
function runCommand(array $command): void
{
echo '[ci4-install] ' . implode(' ', $command) . PHP_EOL;
$descriptor = [
0 => STDIN,
1 => STDOUT,
2 => STDERR,
];
$process = proc_open($command, $descriptor, $pipes);
if (! is_resource($process)) {
throw new RuntimeException(
'Cannot execute command: "' . implode(' ', $command) . '"'
);
}
$status = proc_get_status($process);
while ($status['running']) {
usleep(100000);
$status = proc_get_status($process);
}
proc_close($process);
$exitCode = $status['exitcode'];
//echo $exitCode . PHP_EOL;
if ($exitCode !== 0) {
throw new RuntimeException(
'Command failed: "' . implode(' ', $command) . '"'
);
}
}
function updateFrameworkVersion(string $version): void
{
echo '[ci4-install] ' . 'update "codeigniter4/framework" version in composer.json' . PHP_EOL;
$composerJsonPath = "composer.json";
$composerJson = file_get_contents($composerJsonPath);
$newComposerJson = preg_replace(
'!"codeigniter4/framework": ".*?"!',
'"codeigniter4/framework": "^' . $version . '"',
$composerJson
);
file_put_contents($composerJsonPath, $newComposerJson);
}
//--------------------------------------------------------------------
// Main
//--------------------------------------------------------------------
if ($argc < 2) {
file_put_contents(
'php://stderr',
'Usage: php ci4-install.php <directory> [<version>]' . PHP_EOL
. ' Eg: php ci4-install.php ci4app 4.1.9' . PHP_EOL
);
exit(1);
}
$dir = $argv[1];
// install the latest version
if ($argc === 2) {
runCommand(['composer', 'create-project', 'codeigniter4/appstarter', $dir]);
exit(0);
}
// install the specific version
$version = $argv[2];
runCommand(['composer', 'create-project', 'codeigniter4/appstarter:' . $version, $dir]);
chdir($dir);
runCommand(['composer', 'require', '-W', 'codeigniter4/framework:' . $version]);
updateFrameworkVersion($version);