-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathplugin-build
executable file
·141 lines (109 loc) · 3.02 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
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
#!/usr/bin/env php
<?php
if ( $argc < 2 ) {
die( "Usage: " . basename( $argv[0] ) . " <version>\nRun from the folder containing the build config files.\n" );
}
$version = $argv[1];
$publish = false;
foreach ( $argv as $arg ) {
if ( '-p' === $arg ) {
$publish = true;
}
}
$build_cfg_dir = getcwd();
$parent_dir = dirname( $build_cfg_dir );
// Defaults - override in config.php
$src_dir = $parent_dir;
$zip_dir = $build_cfg_dir;
$tmp_dir = "$build_cfg_dir/tmp";
$cleanup = true;
$config_file = "$build_cfg_dir/config.php";
if ( ! file_exists( $config_file ) ) {
echo "Could not find the config.php file in the current folder.\n";
exit;
}
include $config_file;
if ( ! isset( $plugin_slug ) ) {
$plugin_slug = basename( $src_dir );
}
$dest_dir = "$tmp_dir/$plugin_slug";
if ( ! isset( $main_plugin_file ) ) {
$main_plugin_file = "$src_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_cfg_dir/version-check.php";
if ( file_exists( $version_check_hook ) ) {
include $version_check_hook;
$messages = '';
foreach ( $version_checks as $file => $regexes ) {
$file = "$src_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 "$dest_dir" 2>/dev/null`;
if ( ! is_dir( $tmp_dir ) ) {
mkdir( $tmp_dir );
}
mkdir( $dest_dir );
$filter_file = "$build_cfg_dir/filter";
// Use this hook to override the default filter file
$filter_hook = "$build_cfg_dir/filter.php";
if ( file_exists( $filter_hook ) ) {
include $filter_hook;
}
`rsync -r --filter=". $filter_file" "$src_dir"/* "$dest_dir"`;
chdir( $tmp_dir );
// Use this hook to do anything before we zip up
$pre_zip_hook = "$build_cfg_dir/pre-zip.php";
if ( file_exists( $pre_zip_hook ) ) {
include $pre_zip_hook;
}
if ( ! isset( $zip_name ) ) {
$zip_name = "$plugin_slug-$version.zip";
} else {
$zip_name = "$zip_name-$version.zip";
}
if ( file_exists( $zip_dir . '/' . $zip_name ) ) {
echo "\nRemoving existing zip: " . $zip_dir . '/' . $zip_name . "\n\n" ;
// Ensure we don't add files to an existing zip
unlink( $zip_dir . '/' . $zip_name );
}
echo `zip -r $zip_name $plugin_slug -x "*.DS_Store"`;
if ( $zip_dir != $tmp_dir ) {
`mv $zip_name "$zip_dir"/`;
}
if ( $cleanup ) {
`rm -Rf "$dest_dir"`;
}