-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
generate-gutenberg-php.php
executable file
·62 lines (50 loc) · 1.21 KB
/
generate-gutenberg-php.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
#!/usr/bin/env php
<?php
/**
* Generates the production (plugin build) version of `gutenberg.php`,
* containing alternate `define` statements from the development version.
*
* @package gutenberg-build
*/
$f = fopen( dirname( __DIR__ ) . '/gutenberg.php', 'r' );
$plugin_version = null;
$inside_defines = false;
/**
* Prints `define` statements for the production version of `gutenberg.php`
* (the plugin entry point).
*/
function print_production_defines() {
global $plugin_version;
echo "define( 'GUTENBERG_VERSION', '$plugin_version' );\n";
$git_commit = trim( shell_exec( 'git rev-parse HEAD' ) );
echo "define( 'GUTENBERG_GIT_COMMIT', '$git_commit' );\n";
}
while ( true ) {
$line = fgets( $f );
if ( false === $line ) {
break;
}
if (
! $plugin_version &&
preg_match( '@^\s*\*\s*Version:\s*([0-9.]+)@', $line, $matches )
) {
$plugin_version = $matches[1];
}
switch ( trim( $line ) ) {
case '### BEGIN AUTO-GENERATED DEFINES':
$inside_defines = true;
echo $line;
print_production_defines();
break;
case '### END AUTO-GENERATED DEFINES':
$inside_defines = false;
echo $line;
break;
default:
if ( ! $inside_defines ) {
echo $line;
}
break;
}
}
fclose( $f );