Completed
Push — master ( 62f458...38bc07 )
by Milo
01:55
created

release.php ➔ exclaim()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
#!/usr/bin/env php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 9 and the first side effect is on line 1.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
<?php
4
5
/**
6
 * Highlights important output
7
 * @param string $msg
8
 */
9
function exclaim($msg)
10
{
11
    echo "\n\033[1;36m" . $msg . "\033[0m\n";
12
}
13
14
15
/* Get version number of latest releases */
16
$products = file_get_contents('http://code.highcharts.com/products.js');
17
preg_match_all('/\d\.\d+\.\d+/', $products, $matches);
18
$ver = $matches[0][0];
19
$stockVer = $matches[0][1];
20
$mapsVer = $matches[0][2];
21
22
/* Prompt for version numbers */
23
echo "\nEnter the HIGHCHARTS version [$ver]: ";
24
$ver = trim(fgets(STDIN)) ?: $ver;
25
echo "\nEnter the HIGHSTOCK version [$stockVer]: ";
26
$stockVer = trim(fgets(STDIN)) ?: $stockVer;
27
echo "\nEnter the HIGHMAPS version [$mapsVer]: ";
28
$mapsVer = trim(fgets(STDIN)) ?: $mapsVer;
29
30
31
exclaim("Fetching archives");
32
$dir = dirname(dirname(__FILE__)) . '/highcharts/assets';
33
if (!is_dir($dir) || !chdir($dir)) {
34
    echo "Error: Directory '$dir' is inaccessible.\n";
35
    return false;
36
}
37
38
echo `
39
rm -rfv $dir/*
40
wget http://code.highcharts.com/zips/Highcharts-$ver.zip
41
wget http://code.highcharts.com/zips/Highstock-$stockVer.zip
42
wget http://code.highcharts.com/zips/Highmaps-$mapsVer.zip
43
unzip Highcharts-$ver.zip js/\*
44
unzip -n Highstock-$stockVer.zip js/\*
45
unzip -n Highmaps-$mapsVer.zip js/\*
46
mv js/* .
47
rmdir js
48
rm *.zip
49
`;
50
51
52
exclaim("Purging extraneous assets");
53
echo `rm -rfv parts* *debug* .htaccess`;
54
55
56
exclaim("Creating missing src files");
57
echo `
58
for file in $(find . -name '*.js' ! -name '*.src.js'); do 
59
     cp -nv "\$file" \${file%.js}.src.js
60
done
61
`;
62
63
exclaim("Updating Changelog");
64
$fileName = dirname(dirname(__FILE__)) . '/CHANGELOG.md';
65
$changelogLink = " See the Highcharts [changelog](http://highcharts.com/documentation/changelog) for more information about what's new in this version.";
66
$changelogEntry = "### [v$ver](https://github.com/miloschuman/yii2-highcharts/releases/tag/v$ver) ($date) ###\n"
67
    . "* Upgraded Highcharts JS library to the latest release ($ver).$changelogLink";
68
$contents = file_get_contents($fileName);
69
$contents = str_replace($changelogLink, '', $contents);
70
$contents = str_replace("===\n", "===\n\n$changelogEntry\n", $contents);
71
file_put_contents($fileName, $contents);
72
73
74
exclaim("Done, bitch!");
75
exclaim("Don't forget to UPDATE README.md!");
76