-
Notifications
You must be signed in to change notification settings - Fork 2
/
builds
executable file
·163 lines (142 loc) · 3.67 KB
/
builds
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env php
<?php
define('LATEST_RELEASE', '^4.0');
define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
/*
* --------------------------------------------------------------------
* Stability Toggle
* --------------------------------------------------------------------
* Use this script to toggle the CodeIgniter dependency between the
* latest stable release and the most recent development update.
*
* Usage: php builds [release|development]
*/
// Determine the requested stability
if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development']))
{
echo 'Usage: php builds [release|development]' . PHP_EOL;
exit;
}
$dev = $argv[1] == 'development';
$modified = [];
/* Locate each file and update it for the requested stability */
// Composer.json
$file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
if (is_file($file))
{
// Make sure we can read it
if ($contents = file_get_contents($file))
{
if ($array = json_decode($contents, true))
{
// Development
if ($dev)
{
// Set 'minimum-stability'
$array['minimum-stability'] = 'dev';
$array['prefer-stable'] = true;
// Make sure the repo is configured
if (! isset($array['repositories']))
{
$array['repositories'] = [];
}
// Check for the CodeIgniter repo
$found = false;
foreach ($array['repositories'] as $repository)
{
if ($repository['url'] == GITHUB_URL)
{
$found = true;
break;
}
}
// Add the repo if it was not found
if (! $found)
{
$array['repositories'][] = [
'type' => 'vcs',
'url' => GITHUB_URL,
];
}
// Define the "require"
$array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
unset($array['require']['codeigniter4/framework']);
}
// Release
else
{
// Clear 'minimum-stability'
unset($array['minimum-stability']);
// If the repo is configured then clear it
if (isset($array['repositories']))
{
// Check for the CodeIgniter repo
foreach ($array['repositories'] as $i => $repository)
{
if ($repository['url'] == GITHUB_URL)
{
unset($array['repositories'][$i]);
break;
}
}
if (empty($array['repositories']))
{
unset($array['repositories']);
}
}
// Define the "require"
$array['require']['codeigniter4/framework'] = LATEST_RELEASE;
unset($array['require']['codeigniter4/codeigniter4']);
}
// Write out a new composer.json
file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . PHP_EOL);
$modified[] = $file;
}
else
{
echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
}
}
else
{
echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
}
}
// Paths config and PHPUnit XMLs
$files = [
__DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
];
foreach ($files as $file)
{
if (is_file($file))
{
$contents = file_get_contents($file);
// Development
if ($dev)
{
$contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
}
// Release
else
{
$contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
}
file_put_contents($file, $contents);
$modified[] = $file;
}
}
if (empty($modified))
{
echo 'No files modified' . PHP_EOL;
}
else
{
echo 'The following files were modified:' . PHP_EOL;
foreach ($modified as $file)
{
echo " * {$file}" . PHP_EOL;
}
echo 'Run `composer update` to sync changes with your vendor folder' . PHP_EOL;
}