-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileToBase64.php
39 lines (34 loc) · 892 Bytes
/
fileToBase64.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
<?php
$target='./src/thipages/jsbuild/Base64Config.php';
$rollup='./config/rollup';
$template=<<<Template
<?php
namespace thipages\jsbuild;
class Base64Config {
public static function getContent() {
return [
#LIST#
];
}
}
Template;
$data=[];
foreach (array_diff(scandir($rollup), [".", ".."]) as $name) $data[]=[$rollup,$name];
$data[]=['./config/','package.json'];
//
$list=[];
foreach ($data as $item) {
$list[]=getStringArray([$item[0],$item[1],base64_encode(file_get_contents(join('/',$item)))],true);
}
$content=str_replace('#LIST#',join(",\n",$list), $template);
file_put_contents($target,$content);
echo($target.' created');
//
function quote($s) {
return "'".$s."'";
}
function getStringArray($list, $quoted) {
$c=[];
foreach ($list as $item) $c[]=$quoted?quote($item):$item;
return join("\n",["[",join(",\n",$c),"]"]);
}