|
144 | 144 |
|
145 | 145 | $root = Filesystem::resolvePath($argv[1]);
|
146 | 146 |
|
147 |
| -echo "Finding static resources...\n"; |
| 147 | +$resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash'); |
| 148 | +$runtime_map = array(); |
| 149 | + |
| 150 | +echo "Finding raw static resources...\n"; |
| 151 | +$raw_files = id(new FileFinder($root)) |
| 152 | + ->withType('f') |
| 153 | + ->withSuffix('png') |
| 154 | + ->withSuffix('jpg') |
| 155 | + ->withSuffix('gif') |
| 156 | + ->withSuffix('swf') |
| 157 | + ->withFollowSymlinks(true) |
| 158 | + ->setGenerateChecksums(true) |
| 159 | + ->find(); |
| 160 | + |
| 161 | +echo "Processing ".count($raw_files)." files"; |
| 162 | +foreach ($raw_files as $path => $hash) { |
| 163 | + echo "."; |
| 164 | + $path = '/'.Filesystem::readablePath($path, $root); |
| 165 | + $type = CelerityResourceTransformer::getResourceType($path); |
| 166 | + |
| 167 | + $hash = md5($hash.$path.$resource_hash); |
| 168 | + $uri = '/res/'.substr($hash, 0, 8).$path; |
| 169 | + |
| 170 | + $runtime_map[$path] = array( |
| 171 | + 'hash' => $hash, |
| 172 | + 'uri' => $uri, |
| 173 | + 'disk' => $path, |
| 174 | + 'type' => $type, |
| 175 | + ); |
| 176 | +} |
| 177 | +echo "\n"; |
| 178 | + |
| 179 | +$xformer = id(new CelerityResourceTransformer()) |
| 180 | + ->setMinify(false) |
| 181 | + ->setRawResourceMap($runtime_map); |
| 182 | + |
| 183 | +echo "Finding transformable static resources...\n"; |
148 | 184 | $files = id(new FileFinder($root))
|
149 | 185 | ->withType('f')
|
150 | 186 | ->withSuffix('js')
|
|
155 | 191 |
|
156 | 192 | echo "Processing ".count($files)." files";
|
157 | 193 |
|
158 |
| -$resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash'); |
159 |
| - |
160 | 194 | $file_map = array();
|
161 |
| -foreach ($files as $path => $hash) { |
| 195 | +foreach ($files as $path => $raw_hash) { |
162 | 196 | echo ".";
|
163 |
| - $name = '/'.Filesystem::readablePath($path, $root); |
164 |
| - $file_map[$name] = array( |
165 |
| - 'hash' => md5($hash.$name.$resource_hash), |
| 197 | + $path = '/'.Filesystem::readablePath($path, $root); |
| 198 | + $data = Filesystem::readFile($root.$path); |
| 199 | + |
| 200 | + $data = $xformer->transformResource($path, $data); |
| 201 | + $hash = md5($data); |
| 202 | + $hash = md5($hash.$path.$resource_hash); |
| 203 | + |
| 204 | + $file_map[$path] = array( |
| 205 | + 'hash' => $hash, |
166 | 206 | 'disk' => $path,
|
167 | 207 | );
|
168 | 208 | }
|
169 | 209 | echo "\n";
|
170 | 210 |
|
171 |
| -$runtime_map = array(); |
172 | 211 | $resource_graph = array();
|
173 | 212 | $hash_map = array();
|
174 | 213 |
|
175 | 214 | $parser = new PhutilDocblockParser();
|
176 | 215 | foreach ($file_map as $path => $info) {
|
177 |
| - $data = Filesystem::readFile($info['disk']); |
| 216 | + $type = CelerityResourceTransformer::getResourceType($path); |
| 217 | + |
| 218 | + $data = Filesystem::readFile($root.$info['disk']); |
178 | 219 | $matches = array();
|
179 | 220 | $ok = preg_match('@/[*][*].*?[*]/@s', $data, $matches);
|
180 | 221 | if (!$ok) {
|
|
202 | 243 |
|
203 | 244 | $provides = reset($provides);
|
204 | 245 |
|
205 |
| - $type = 'js'; |
206 |
| - if (preg_match('/\.css$/', $path)) { |
207 |
| - $type = 'css'; |
208 |
| - } |
209 |
| - |
210 | 246 | $uri = '/res/'.substr($info['hash'], 0, 8).$path;
|
211 | 247 |
|
212 | 248 | $hash_map[$provides] = $info['hash'];
|
|
0 commit comments