-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin-build
105 lines (79 loc) · 2.21 KB
/
plugin-build
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
#!/usr/bin/php
<?php
$script_dir = dirname( __FILE__ );
$run_dir = getcwd();
$build_dir = "$run_dir/build";
if ( !is_dir( $build_dir ) ) {
echo "Cannot find 'build' folder in the current folder.\n";
exit;
}
if ( $argc != 3 ) {
die( "Usage: $argv[0] <plugin-slug>[.php] <version>\n" );
}
$plugin_slug = basename( $argv[1], '.php' );
$version = $argv[2];
$tmp_dir = "$build_dir/tmp";
$dest_dir = "$tmp_dir/$plugin_slug";
$main_plugin_file = "$run_dir/$plugin_slug.php";
if ( !file_exists( $main_plugin_file ) ) {
echo "Cannot find main plugin file $main_plugin_file.\n";
exit;
}
/*
* version-check.php example:
* $version_checks = array(
* "$plugin_slug.php" => array(
* '@Version:\s+(.*)\n@' => 'header'
* )
* );
*
*/
$version_check_hook = "$build_dir/version-check.php";
if ( file_exists( $version_check_hook ) ) {
include $version_check_hook;
$messages = '';
foreach ( $version_checks as $file => $regexes ) {
$file = "$run_dir/$file";
if ( !file_exists( $file ) ) {
$messages .= "Whoa! Couldn't find $file\n";
continue;
}
$file_content = file_get_contents( $file );
if ( !$file_content ) {
$messages .= "Whoa! Could not read contents of $file\n";
continue;
}
foreach ( $regexes as $regex => $context ) {
if ( !preg_match( $regex, $file_content, $matches ) ) {
$messages .= "Whoa! Couldn't find $context version number in $file\n";
continue;
}
if ( trim( $matches[1] ) != trim( $version ) ) {
$messages .= "Whoa! " . ucfirst( $context ) . " version number is currently $matches[1] in $file\n";
}
}
}
if ( $messages ) {
die( $messages );
}
}
`rm -Rf $tmp_dir 2>/dev/null`;
mkdir( $tmp_dir );
mkdir( $dest_dir );
$filter_file = "$build_dir/filter";
// Use this hook to override the default filter file
$filter_hook = "$build_dir/filter.php";
if ( file_exists( $filter_hook ) ) {
include $filter_hook;
}
`rsync -r --filter=". $filter_file" $run_dir/* $dest_dir`;
chdir( $tmp_dir );
// Use this hook to do anything before we zip up
$pre_zip_hook = "$build_dir/pre-zip.php";
if ( file_exists( $pre_zip_hook ) ) {
include $pre_zip_hook;
}
$zip_name = "$plugin_slug-$version.zip";
echo `zip -r $zip_name $plugin_slug`;
`mv $zip_name $run_dir/`;
`rm -Rf $tmp_dir`;