Skip to content

Commit fff5cd4

Browse files
authored
Merge pull request #405 from limzykenneth/master
Re-add release.php file
2 parents 78b1b45 + 9c42604 commit fff5cd4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

dist/download/release.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
$lib_version;
4+
5+
function download($url, $path) {
6+
# open file to write
7+
$fp = fopen ($path, 'w+');
8+
# start curl
9+
$ch = curl_init();
10+
curl_setopt( $ch, CURLOPT_URL, $url );
11+
# set return transfer to false
12+
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
13+
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
14+
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
15+
# increase timeout to download big file
16+
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
17+
# write data to local file
18+
curl_setopt( $ch, CURLOPT_FILE, $fp );
19+
# execute curl
20+
curl_exec( $ch );
21+
# close curl
22+
curl_close( $ch );
23+
# close local file
24+
fclose( $fp );
25+
26+
if (filesize($path) > 0) return true;
27+
}
28+
29+
function getLibVersionDate($f) {
30+
$handle = fopen($f, 'r');
31+
$line = fgets($handle);
32+
fclose($handle);
33+
preg_match('/v([^ ]*) /', $line, $matches);
34+
$v = $matches[1];
35+
preg_match('/v[^ ]* ([^ ]* [^ ]* [^ ]*) /', $line, $matches);
36+
$d = $matches[1];
37+
return array($v, $d);
38+
}
39+
40+
function updateFiles() {
41+
global $lib_version;
42+
$r = 'https://raw.githubusercontent.com/lmccart/p5.js-release/master/lib';
43+
download($r.'/p5.min.js', '../assets/js/p5.min.js');
44+
download($r.'/addons/p5.dom.min.js', '../assets/js/p5.dom.min.js');
45+
download($r.'/addons/p5.sound.min.js', '../assets/js/p5.sound.min.js');
46+
}
47+
48+
function updateAll() {
49+
updateFiles();
50+
51+
$v = getLibVersionDate('../assets/js/p5.min.js');
52+
$lib_version = $v[0];
53+
$lib_date = $v[1];
54+
55+
$contents = array('version'=>$lib_version, 'date'=>$lib_date);
56+
file_put_contents('version.json', json_encode($contents));
57+
58+
unlink('package.json');
59+
echo 'updated library version to v'.$lib_version.' ('.$lib_date.')<br>';
60+
}
61+
62+
updateAll();
63+
?>

0 commit comments

Comments
 (0)