-
Notifications
You must be signed in to change notification settings - Fork 0
/
changelog-md-to-wordpress-plugin-readme-txt.php
62 lines (43 loc) · 1.95 KB
/
changelog-md-to-wordpress-plugin-readme-txt.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
<?php
$file_changelog_md = 'CHANGELOG.md';
$file_readme_txt = 'readme.txt';
$content_changelog_md = \file_get_contents( __DIR__ . '/' . $file_changelog_md );
$content_readme_txt = \file_get_contents( __DIR__ . '/' . $file_readme_txt );
$marker_start = '<!-- Start changelog -->';
$marker_end = '<!-- End changelog -->';
$md_changelog_marker_start_position = \strpos( $content_changelog_md, $marker_start );
$md_changelog_marker_end_position = \strpos( $content_changelog_md, $marker_end );
$txt_changelog_marker_start_position = \strpos( $content_readme_txt, $marker_start );
$txt_changelog_marker_end_position = \strpos( $content_readme_txt, $marker_end );
if ( false === $md_changelog_marker_start_position ) {
echo 'No changelog start marker found in CHANGELOG.md file.';
exit( 1 );
}
if ( false === $md_changelog_marker_end_position ) {
echo 'No changelog end marker found in CHANGELOG.md file.';
exit( 1 );
}
if ( false === $txt_changelog_marker_start_position ) {
echo 'No changelog start marker found in readme.txt file.';
exit( 1 );
}
if ( false === $txt_changelog_marker_end_position ) {
echo 'No changelog end marker found in readme.txt file.';
exit( 1 );
}
$md_changelog_marker_start_position += \strlen( $marker_start );
$changelog_content = \substr(
$content_changelog_md,
$md_changelog_marker_start_position,
$md_changelog_marker_end_position - $md_changelog_marker_start_position
);
$changelog_content_updated = \preg_replace_callback(
'/^(#{1,6})\s/m',
function ( $matches ) {
return \str_repeat( '#', \strlen( $matches[1] ) + 1 ) . ' ';
},
$changelog_content
);
$txt_changelog_marker_start_position += \strlen( $marker_start );
$content_readme_txt_updated = \substr( $content_readme_txt, 0, $txt_changelog_marker_start_position ) . $changelog_content_updated . \substr( $content_readme_txt, $txt_changelog_marker_end_position );
\file_put_contents( __DIR__ . '/' . $file_readme_txt, $content_readme_txt_updated );