-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbuild.php
executable file
·213 lines (186 loc) · 5.99 KB
/
build.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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<pre>
<?
// Build Pico ready content and data files content
/*
error_reporting(E_ALL);
ini_set('display_errors', '1');
*/
ini_set('memory_limit', '32M');
set_time_limit(0);
include "lib/Parsedown.php";
$Parsedown = new Parsedown();
$c_file = file_get_contents(__DIR__ . "/components/components.json");
$c = json_decode($c_file, true);
foreach ($c["components"] as $component) {
$dir = __DIR__ . "/components/" . ucwords($component) . "/";
if (is_dir($dir)) {
$b_file = file_get_contents($dir . "bower.json");
$bower = json_decode($b_file, true);
$p_file = file_get_contents($dir . "package.json");
$package = json_decode($p_file, true);
// Parse JS
$file = false;
$source = false;
foreach ($bower["main"] as $s) {
if (strpos($s, ".js") > -1) {
$source = $s;
}
}
$doc = array();
echo $source . "\n";
if ($source) {
echo $source . "\n";
$file = file_get_contents($dir . $source);
// Match /** ... */ style block comments
preg_match_all("/(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)/", $file, $matches);
foreach($matches[0] as $content) {
if (strpos($content, "@plugin") > -1) {
$doc = array_merge(parseContent($content), $doc);
} else if (strpos($content, "@options") > -1) {
$params = parseContent($content);
$doc["options"] = $params["params"];
} else if (strpos($content, "@events") > -1) {
$doc["events"] = parseContent($content);
} else if (strpos($content, "@method") > -1) {
if (!isset($doc["methods"]) || !is_array($doc["methods"])) {
$doc["methods"] = array();
}
$m = parseContent($content);
if (strpos($content, "private")) {
$m["private"] = true;
}
if (strpos($content, "global")) {
$m["global"] = true;
}
$doc["methods"][] = $m;
}
}
}
// Parse main
$main = array();
$main["js"] = array();
$main["css"] = array();
foreach ($bower["main"] as $m) {
if (strpos($m, ".js") > -1) {
$main["js"][] = $m;
} else if (strpos($m, ".css") > -1) {
$main["css"][] = $m;
}
}
// Parse readme
$readme = file_get_contents($dir . "README.md");
$readme_parts = split("---", $readme, 2);
$readme_parsed = $Parsedown->text($readme_parts[1]);
// Build json
$json = array(
"name" => $package["name"],
"description" => str_ireplace("Part of the Formstone Library.", "", $package["description"]),
"version" => $package["version"],
"demo" => $package["demo"],
"repository" => $package["repository"]["url"],
"documentation" => $doc,
"files" => $main,
"extra" => $readme_parsed
);
// Parse demo
$demo_file = file_get_contents($package["demo"]);
if (trim($demo_file) !== "") {
$demo_resources_start = strpos($demo_file, '<!--[DEMO:START-RESOURCES]-->');
$demo_resources_end = strpos($demo_file, '<!--[DEMO:END-RESOURCES]-->') - $demo_resources_start;
$demo_content_start = strpos($demo_file, '<!--[DEMO:START-CONTENT]-->');
$demo_content_end = strpos($demo_file, '<!--[DEMO:END-CONTENT]-->') - $demo_content_start;
$json["demo_resources"] = substr($demo_file, $demo_resources_start, $demo_resources_end);
$json["demo_content"] = substr($demo_file, $demo_content_start, $demo_content_end);
}
// Build page
$markdown = "/* \n";
$markdown .= "Template: component \n";
$markdown .= "Title: " . $package["name"];
$markdown .= " \n";
$markdown .= "Description: " . str_ireplace("Part of the Formstone Library.", "", $package["description"]);
$markdown .= " \n";
$markdown .= "Data: " . $package["id"] . ".md";
$markdown .= " \n";
$markdown .= "*/ \n";
// Store content
file_put_contents(__DIR__ . "/content/components/" . $component . ".json", trim(json_encode($json)));
file_put_contents(__DIR__ . "/content/components/" . $component . ".md", trim($markdown));
echo "COMPLETE: " . $component . "\n";
} else {
echo "NOT FOUND: " . $component . "\n";
}
}
// Bust Component Cache
$files = glob(__DIR__ . "/lib/cache/pages/components-*");
foreach ($files as $file) {
if (!is_dir($file)) {
unlink($file);
}
}
function parseContent($content) {
$return = array();
$parts = explode("\n", $content);
$keys = array(
"name",
"description",
"version",
"example",
"param",
"event",
"return"
);
foreach ($parts as $p) {
foreach ($keys as $key) {
if (strpos($p, "@$key ") > -1) {
$part = explode("@$key ", $p);
$part = trim(end($part));
// Split down params, events and returns
if (in_array($key, array("param","event","return"))) {
if ($key != "return") {
$pp = explode(" ", $part, 2);
$part = array(
"name" => trim($pp[0])
);
} else {
$pp[1] = $part;
$part = array();
}
if (isset($pp[1])) {
// 0 - all
// 1 - type
// 2 - default
// 3 - description
// Patterns: \[([^\]]*)\]|\<([^\]]*)\>|\"([^\]]*)\"
preg_match_all("/\\[([^\\]]*)\\]|\\<([^\\]]*)\\>|\\\"([^\\]]*)\\\"/us", $pp[1], $matches);
foreach ($matches[1] as $match) {
$match = trim($match);
if ($match !== "") $part["type"] = $match;
}
foreach ($matches[2] as $match) {
$match = trim($match);
if ($match !== "") $part["default"] = $match;
}
foreach ($matches[3] as $match) {
$match = trim($match);
if ($match !== "") $part["description"] = $match;
}
}
}
if ($key == "param") {
if (!is_array($return["params"])) {
$return["params"] = array();
}
$return["params"][] = $part;
} else if ($key == "event") {
$return[] = $part;
} else {
$return[$key] = $part;
}
}
}
}
return $return;
}
die("\nFINISHED");
?>
</pre>