Skip to content

Commit f229f98

Browse files
committed
Add source switcher to starter repo
1 parent 5da55b4 commit f229f98

1 file changed

Lines changed: 162 additions & 0 deletions

File tree

admin/starter/builds

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
define('LATEST_RELEASE', '^4@rc');
5+
define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
6+
7+
/*
8+
* --------------------------------------------------------------------
9+
* Stability Toggle
10+
* --------------------------------------------------------------------
11+
* Use this script to toggle the CodeIgniter dependency between the
12+
* latest stable release and the most recent development update.
13+
*
14+
* Usage: php builds [release|development]
15+
*/
16+
17+
// Determine the requested stability
18+
if (empty($argv[1]) || ! in_array($argv[1], ['release', 'development']))
19+
{
20+
echo 'Usage: php builds [release|development]' . PHP_EOL;
21+
exit;
22+
}
23+
24+
$dev = $argv[1] == 'development';
25+
$modified = [];
26+
27+
/* Locate each file and update it for the requested stability */
28+
29+
// Composer.json
30+
$file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json';
31+
32+
if (is_file($file))
33+
{
34+
// Make sure we can read it
35+
if ($contents = file_get_contents($file))
36+
{
37+
if ($array = json_decode($contents, true))
38+
{
39+
// Development
40+
if ($dev)
41+
{
42+
// Set 'minimum-stability'
43+
$array['minimum-stability'] = 'dev';
44+
45+
// Make sure the repo is configured
46+
if (! isset($array['repositories']))
47+
{
48+
$array['repositories'] = [];
49+
}
50+
51+
// Check for the CodeIgniter repo
52+
$found = false;
53+
foreach ($array['repositories'] as $repository)
54+
{
55+
if ($repository['url'] == GITHUB_URL)
56+
{
57+
$found = true;
58+
break;
59+
}
60+
}
61+
62+
// Add the repo if it was not found
63+
if (! $found)
64+
{
65+
$array['repositories'][] = [
66+
'type' => 'vcs',
67+
'url' => GITHUB_URL,
68+
];
69+
}
70+
71+
// Define the "require"
72+
$array['require']['codeigniter4/codeigniter4'] = 'dev-develop';
73+
unset($array['require']['codeigniter4/framework']);
74+
}
75+
76+
// Release
77+
else
78+
{
79+
// Clear 'minimum-stability'
80+
unset($array['minimum-stability']);
81+
82+
// If the repo is configured then clear it
83+
if (isset($array['repositories']))
84+
{
85+
// Check for the CodeIgniter repo
86+
foreach ($array['repositories'] as $i => $repository)
87+
{
88+
if ($repository['url'] == GITHUB_URL)
89+
{
90+
unset($array['repositories'][$i]);
91+
break;
92+
}
93+
}
94+
if (empty($array['repositories']))
95+
{
96+
unset($array['repositories']);
97+
}
98+
}
99+
100+
// Define the "require"
101+
$array['require']['codeigniter4/framework'] = LATEST_RELEASE;
102+
unset($array['require']['codeigniter4/codeigniter4']);
103+
}
104+
105+
// Write out a new composer.json
106+
file_put_contents($file, json_encode($array, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES) . PHP_EOL);
107+
$modified[] = $file;
108+
}
109+
else
110+
{
111+
echo 'Warning: Unable to decode composer.json! Skipping...' . PHP_EOL;
112+
}
113+
}
114+
else
115+
{
116+
echo 'Warning: Unable to read composer.json! Skipping...' . PHP_EOL;
117+
}
118+
}
119+
120+
// Paths config and PHPUnit XMLs
121+
$files = [
122+
__DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php',
123+
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist',
124+
__DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml',
125+
];
126+
127+
foreach ($files as $file)
128+
{
129+
if (is_file($file))
130+
{
131+
$contents = file_get_contents($file);
132+
133+
// Development
134+
if ($dev)
135+
{
136+
$contents = str_replace('vendor/codeigniter4/framework', 'vendor/codeigniter4/codeigniter4', $contents);
137+
}
138+
139+
// Release
140+
else
141+
{
142+
$contents = str_replace('vendor/codeigniter4/codeigniter4', 'vendor/codeigniter4/framework', $contents);
143+
}
144+
145+
file_put_contents($file, $contents);
146+
$modified[] = $file;
147+
}
148+
}
149+
150+
if (empty($modified))
151+
{
152+
echo 'No files modified' . PHP_EOL;
153+
}
154+
else
155+
{
156+
echo 'The following files were modified:' . PHP_EOL;
157+
foreach ($modified as $file)
158+
{
159+
echo " * {$file}" . PHP_EOL;
160+
}
161+
echo 'Run `composer update` to sync changes with your vendor folder' . PHP_EOL;
162+
}

0 commit comments

Comments
 (0)