1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Add packaging to Celerity.

This commit is contained in:
epriestley 2011-01-29 16:10:05 -08:00
parent 7b9c4c5f61
commit 0c8b04d5a8
6 changed files with 241 additions and 39 deletions

View file

@ -1,6 +1,31 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
$package_spec = array(
'core.pkg.css' => array(
'phabricator-core-css',
'phabricator-core-buttons-css',
'phabricator-standard-page-view',
'aphront-dialog-view-css',
'aphront-form-view-css',
'aphront-panel-view-css',
'aphront-side-nav-view-css',
'aphront-table-view-css',
'aphront-tokenizer-control-css',
'aphront-typeahead-control-css',
'phabricator-directory-css',
),
'differential.pkg.css' => array(
'differential-core-view-css',
'differential-changeset-view-css',
'differential-revision-detail-css',
'differential-revision-history-css',
'differential-table-of-contents-css',
),
);
require_once dirname(__FILE__).'/__init_script__.php'; require_once dirname(__FILE__).'/__init_script__.php';
if ($argc != 2) { if ($argc != 2) {
@ -39,6 +64,8 @@ echo "\n";
$runtime_map = array(); $runtime_map = array();
$hash_map = array();
$parser = new PhutilDocblockParser(); $parser = new PhutilDocblockParser();
foreach ($file_map as $path => $info) { foreach ($file_map as $path => $info) {
$data = Filesystem::readFile($info['disk']); $data = Filesystem::readFile($info['disk']);
@ -69,19 +96,50 @@ foreach ($file_map as $path => $info) {
$type = 'css'; $type = 'css';
} }
$path = '/res/'.substr($info['hash'], 0, 8).$path; $uri = '/res/'.substr($info['hash'], 0, 8).$path;
$hash_map[$provides] = $info['hash'];
$runtime_map[$provides] = array( $runtime_map[$provides] = array(
'path' => $path, 'uri' => $uri,
'type' => $type, 'type' => $type,
'requires' => $requires, 'requires' => $requires,
'disk' => $path,
); );
} }
$package_map = array();
foreach ($package_spec as $name => $package) {
$hashes = array();
foreach ($package as $symbol) {
if (empty($hash_map[$symbol])) {
throw new Exception(
"Package specification for '{$name}' includes '{$symbol}', but that ".
"symbol is not defined anywhere.");
}
$hashes[] = $symbol.':'.$hash_map[$symbol];
}
$key = substr(md5(implode("\n", $hashes)), 0, 8);
$package_map['packages'][$key] = array(
'name' => $name,
'symbols' => $package,
'uri' => '/res/pkg/'.$key.'/'.$name,
'type' => 'css', // TODO LOL
);
foreach ($package as $symbol) {
$package_map['reverse'][$symbol] = $key;
}
}
$runtime_map = var_export($runtime_map, true); $runtime_map = var_export($runtime_map, true);
$runtime_map = preg_replace('/\s+$/m', '', $runtime_map); $runtime_map = preg_replace('/\s+$/m', '', $runtime_map);
$runtime_map = preg_replace('/array \(/', 'array(', $runtime_map); $runtime_map = preg_replace('/array \(/', 'array(', $runtime_map);
$package_map = var_export($package_map, true);
$pacakge_map = preg_replace('/\s+$/m', '', $package_map);
$package_map = preg_replace('/array \(/', 'array(', $package_map);
$resource_map = <<<EOFILE $resource_map = <<<EOFILE
<?php <?php
@ -91,7 +149,7 @@ $resource_map = <<<EOFILE
* @generated * @generated
*/ */
celerity_register_resource_map({$runtime_map}); celerity_register_resource_map({$runtime_map}, {$pacakge_map});
EOFILE; EOFILE;

View file

@ -9,205 +9,287 @@
celerity_register_resource_map(array( celerity_register_resource_map(array(
'aphront-dialog-view-css' => 'aphront-dialog-view-css' =>
array( array(
'path' => '/res/771b987d/rsrc/css/aphront/dialog-view.css', 'uri' => '/res/771b987d/rsrc/css/aphront/dialog-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/aphront/dialog-view.css',
), ),
'aphront-form-view-css' => 'aphront-form-view-css' =>
array( array(
'path' => '/res/785ac1c6/rsrc/css/aphront/form-view.css', 'uri' => '/res/785ac1c6/rsrc/css/aphront/form-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/aphront/form-view.css',
), ),
'aphront-panel-view-css' => 'aphront-panel-view-css' =>
array( array(
'path' => '/res/fe62e634/rsrc/css/aphront/panel-view.css', 'uri' => '/res/fe62e634/rsrc/css/aphront/panel-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/aphront/panel-view.css',
), ),
'aphront-side-nav-view-css' => 'aphront-side-nav-view-css' =>
array( array(
'path' => '/res/0fc0545c/rsrc/css/aphront/side-nav-view.css', 'uri' => '/res/0fc0545c/rsrc/css/aphront/side-nav-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/aphront/side-nav-view.css',
), ),
'aphront-table-view-css' => 'aphront-table-view-css' =>
array( array(
'path' => '/res/52b0191f/rsrc/css/aphront/table-view.css', 'uri' => '/res/52b0191f/rsrc/css/aphront/table-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/aphront/table-view.css',
), ),
'aphront-tokenizer-control-css' => 'aphront-tokenizer-control-css' =>
array( array(
'path' => '/res/a3d23074/rsrc/css/aphront/tokenizer.css', 'uri' => '/res/a3d23074/rsrc/css/aphront/tokenizer.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
0 => 'aphront-typeahead-control-css', 0 => 'aphront-typeahead-control-css',
), ),
'disk' => '/rsrc/css/aphront/tokenizer.css',
), ),
'aphront-typeahead-control-css' => 'aphront-typeahead-control-css' =>
array( array(
'path' => '/res/928df9f0/rsrc/css/aphront/typeahead.css', 'uri' => '/res/928df9f0/rsrc/css/aphront/typeahead.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/aphront/typeahead.css',
), ),
'phabricator-standard-page-view' => 'phabricator-standard-page-view' =>
array( array(
'path' => '/res/1f93ada7/rsrc/css/application/base/standard-page-view.css', 'uri' => '/res/1f93ada7/rsrc/css/application/base/standard-page-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/base/standard-page-view.css',
), ),
'differential-changeset-view-css' => 'differential-changeset-view-css' =>
array( array(
'path' => '/res/658d181a/rsrc/css/application/differential/changeset-view.css', 'uri' => '/res/658d181a/rsrc/css/application/differential/changeset-view.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/differential/changeset-view.css',
), ),
'differential-core-view-css' => 'differential-core-view-css' =>
array( array(
'path' => '/res/525d1a12/rsrc/css/application/differential/core.css', 'uri' => '/res/525d1a12/rsrc/css/application/differential/core.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/differential/core.css',
), ),
'differential-revision-detail-css' => 'differential-revision-detail-css' =>
array( array(
'path' => '/res/11a36dad/rsrc/css/application/differential/revision-detail.css', 'uri' => '/res/230a67c6/rsrc/css/application/differential/revision-detail.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/differential/revision-detail.css',
), ),
'differential-revision-history-css' => 'differential-revision-history-css' =>
array( array(
'path' => '/res/755f3da3/rsrc/css/application/differential/revision-history.css', 'uri' => '/res/755f3da3/rsrc/css/application/differential/revision-history.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/differential/revision-history.css',
), ),
'differential-table-of-contents-css' => 'differential-table-of-contents-css' =>
array( array(
'path' => '/res/a4a7b2b5/rsrc/css/application/differential/table-of-contents.css', 'uri' => '/res/a4a7b2b5/rsrc/css/application/differential/table-of-contents.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/differential/table-of-contents.css',
), ),
'phabricator-directory-css' => 'phabricator-directory-css' =>
array( array(
'path' => '/res/6a000601/rsrc/css/application/directory/phabricator-directory.css', 'uri' => '/res/6a000601/rsrc/css/application/directory/phabricator-directory.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/application/directory/phabricator-directory.css',
), ),
'phabricator-core-buttons-css' => 'phabricator-core-buttons-css' =>
array( array(
'path' => '/res/6e348ba4/rsrc/css/core/buttons.css', 'uri' => '/res/6e348ba4/rsrc/css/core/buttons.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/core/buttons.css',
), ),
'phabricator-core-css' => 'phabricator-core-css' =>
array( array(
'path' => '/res/39ce37c2/rsrc/css/core/core.css', 'uri' => '/res/39ce37c2/rsrc/css/core/core.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/core/core.css',
), ),
'syntax-highlighting-css' => 'syntax-highlighting-css' =>
array( array(
'path' => '/res/fb673ece/rsrc/css/core/syntax.css', 'uri' => '/res/fb673ece/rsrc/css/core/syntax.css',
'type' => 'css', 'type' => 'css',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/css/core/syntax.css',
), ),
'javelin-behavior-aphront-basic-tokenizer' => 'javelin-behavior-aphront-basic-tokenizer' =>
array( array(
'path' => '/res/8317d761/rsrc/js/application/core/behavior-tokenizer.js', 'uri' => '/res/8317d761/rsrc/js/application/core/behavior-tokenizer.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
0 => 'javelin-lib-dev', 0 => 'javelin-lib-dev',
), ),
'disk' => '/rsrc/js/application/core/behavior-tokenizer.js',
), ),
'javelin-behavior-differential-populate' => 'javelin-behavior-differential-populate' =>
array( array(
'path' => '/res/9982573c/rsrc/js/application/differential/behavior-populate.js', 'uri' => '/res/9982573c/rsrc/js/application/differential/behavior-populate.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
0 => 'javelin-lib-dev', 0 => 'javelin-lib-dev',
), ),
'disk' => '/rsrc/js/application/differential/behavior-populate.js',
), ),
'javelin-init-dev' => 'javelin-init-dev' =>
array( array(
'path' => '/res/c57a9e89/rsrc/js/javelin/init.dev.js', 'uri' => '/res/c57a9e89/rsrc/js/javelin/init.dev.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/js/javelin/init.dev.js',
), ),
'javelin-init-prod' => 'javelin-init-prod' =>
array( array(
'path' => '/res/f0172c54/rsrc/js/javelin/init.min.js', 'uri' => '/res/f0172c54/rsrc/js/javelin/init.min.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/js/javelin/init.min.js',
), ),
'javelin-lib-dev' => 'javelin-lib-dev' =>
array( array(
'path' => '/res/3e747182/rsrc/js/javelin/javelin.dev.js', 'uri' => '/res/3e747182/rsrc/js/javelin/javelin.dev.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/js/javelin/javelin.dev.js',
), ),
'javelin-lib-prod' => 'javelin-lib-prod' =>
array( array(
'path' => '/res/9438670e/rsrc/js/javelin/javelin.min.js', 'uri' => '/res/9438670e/rsrc/js/javelin/javelin.min.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/js/javelin/javelin.min.js',
), ),
'javelin-typeahead-dev' => 'javelin-typeahead-dev' =>
array( array(
'path' => '/res/c81c0f01/rsrc/js/javelin/typeahead.dev.js', 'uri' => '/res/c81c0f01/rsrc/js/javelin/typeahead.dev.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/js/javelin/typeahead.dev.js',
), ),
'javelin-typeahead-prod' => 'javelin-typeahead-prod' =>
array( array(
'path' => '/res/1da2d984/rsrc/js/javelin/typeahead.min.js', 'uri' => '/res/1da2d984/rsrc/js/javelin/typeahead.min.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(
), ),
'disk' => '/rsrc/js/javelin/typeahead.min.js',
),
), array (
'packages' =>
array (
'4efe7b58' =>
array (
'name' => 'core.pkg.css',
'symbols' =>
array (
0 => 'phabricator-core-css',
1 => 'phabricator-core-buttons-css',
2 => 'phabricator-standard-page-view',
3 => 'aphront-dialog-view-css',
4 => 'aphront-form-view-css',
5 => 'aphront-panel-view-css',
6 => 'aphront-side-nav-view-css',
7 => 'aphront-table-view-css',
8 => 'aphront-tokenizer-control-css',
9 => 'aphront-typeahead-control-css',
10 => 'phabricator-directory-css',
),
'uri' => '/res/pkg/4efe7b58/core.pkg.css',
'type' => 'css',
),
'69b11588' =>
array (
'name' => 'differential.pkg.css',
'symbols' =>
array (
0 => 'differential-core-view-css',
1 => 'differential-changeset-view-css',
2 => 'differential-revision-detail-css',
3 => 'differential-revision-history-css',
4 => 'differential-table-of-contents-css',
),
'uri' => '/res/pkg/69b11588/differential.pkg.css',
'type' => 'css',
),
),
'reverse' =>
array (
'phabricator-core-css' => '4efe7b58',
'phabricator-core-buttons-css' => '4efe7b58',
'phabricator-standard-page-view' => '4efe7b58',
'aphront-dialog-view-css' => '4efe7b58',
'aphront-form-view-css' => '4efe7b58',
'aphront-panel-view-css' => '4efe7b58',
'aphront-side-nav-view-css' => '4efe7b58',
'aphront-table-view-css' => '4efe7b58',
'aphront-tokenizer-control-css' => '4efe7b58',
'aphront-typeahead-control-css' => '4efe7b58',
'phabricator-directory-css' => '4efe7b58',
'differential-core-view-css' => '69b11588',
'differential-changeset-view-css' => '69b11588',
'differential-revision-detail-css' => '69b11588',
'differential-revision-history-css' => '69b11588',
'differential-table-of-contents-css' => '69b11588',
), ),
)); ));

View file

@ -89,7 +89,7 @@ class AphrontDefaultApplicationConfiguration
), ),
'/res/' => array( '/res/' => array(
'(?<hash>[a-f0-9]{8})/(?<path>.+\.(?:css|js))$' '(?<package>pkg/)?(?<hash>[a-f0-9]{8})/(?<path>.+\.(?:css|js))$'
=> 'CelerityResourceController', => 'CelerityResourceController',
), ),

View file

@ -20,10 +20,12 @@ class CelerityResourceController extends AphrontController {
private $path; private $path;
private $hash; private $hash;
private $package;
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->path = $data['path']; $this->path = $data['path'];
$this->hash = $data['hash']; $this->hash = $data['hash'];
$this->package = !empty($data['package']);
} }
public function processRequest() { public function processRequest() {
@ -38,14 +40,31 @@ class CelerityResourceController extends AphrontController {
$type = $matches[1]; $type = $matches[1];
$root = dirname(phutil_get_library_root('phabricator')); $root = dirname(phutil_get_library_root('phabricator'));
if ($this->package) {
$map = CelerityResourceMap::getInstance();
$paths = $map->resolvePackage($this->hash);
if (!$paths) {
return new Aphront404Response();
}
try {
$data = array();
foreach ($paths as $path) {
$data[] = Filesystem::readFile($root.'/webroot/'.$path);
}
$data = implode("\n\n", $data);
} catch (Exception $ex) {
return new Aphront404Response();
}
} else {
try { try {
$data = Filesystem::readFile($root.'/webroot/'.$path); $data = Filesystem::readFile($root.'/webroot/'.$path);
} catch (Exception $ex) { } catch (Exception $ex) {
return new Aphront404Response(); return new Aphront404Response();
} }
}
$response = new AphrontFileResponse(); $response = new AphrontFileResponse();
$response->setContent($data); $response->setContent($data);

View file

@ -20,6 +20,7 @@ final class CelerityResourceMap {
private static $instance; private static $instance;
private $resourceMap; private $resourceMap;
private $packageMap;
public static function getInstance() { public static function getInstance() {
if (empty(self::$instance)) { if (empty(self::$instance)) {
@ -67,9 +68,49 @@ final class CelerityResourceMap {
$map[$symbol] = $info; $map[$symbol] = $info;
} }
public function setPackageMap($package_map) {
$this->packageMap = $package_map;
} }
function celerity_register_resource_map(array $map) { public function packageResources(array $resolved_map) {
$packaged = array();
$handled = array();
foreach ($resolved_map as $symbol => $info) {
if (isset($handled[$symbol])) {
continue;
}
if (empty($this->packageMap['reverse'][$symbol])) {
$packaged[$symbol] = $info;
} else {
$package = $this->packageMap['reverse'][$symbol];
$package_info = $this->packageMap['packages'][$package];
$packaged[$package_info['name']] = $package_info;
foreach ($package_info['symbols'] as $symbol) {
$handled[$symbol] = true;
}
}
}
return $packaged;
}
public function resolvePackage($package_hash) {
$package = idx($this->packageMap['packages'], $package_hash);
if (!$package) {
return null;
}
$paths = array();
foreach ($package['symbols'] as $symbol) {
$paths[] = $this->resourceMap[$symbol]['disk'];
}
return $paths;
}
}
function celerity_register_resource_map(array $map, array $package_map) {
$instance = CelerityResourceMap::getInstance(); $instance = CelerityResourceMap::getInstance();
$instance->setResourceMap($map); $instance->setResourceMap($map);
$instance->setPackageMap($package_map);
} }

View file

@ -21,6 +21,7 @@ final class CelerityStaticResourceResponse {
private $symbols = array(); private $symbols = array();
private $needsResolve = true; private $needsResolve = true;
private $resolved; private $resolved;
private $packaged;
private $metadata = array(); private $metadata = array();
private $metadataBlock = 0; private $metadataBlock = 0;
private $behaviors = array(); private $behaviors = array();
@ -57,6 +58,7 @@ final class CelerityStaticResourceResponse {
if ($this->needsResolve) { if ($this->needsResolve) {
$map = CelerityResourceMap::getInstance(); $map = CelerityResourceMap::getInstance();
$this->resolved = $map->resolveResources(array_keys($this->symbols)); $this->resolved = $map->resolveResources(array_keys($this->symbols));
$this->packaged = $map->packageResources($this->resolved);
$this->needsResolve = false; $this->needsResolve = false;
} }
return $this; return $this;
@ -65,7 +67,7 @@ final class CelerityStaticResourceResponse {
public function renderResourcesOfType($type) { public function renderResourcesOfType($type) {
$this->resolveResources(); $this->resolveResources();
$output = array(); $output = array();
foreach ($this->resolved as $resource) { foreach ($this->packaged as $resource) {
if ($resource['type'] == $type) { if ($resource['type'] == $type) {
$output[] = $this->renderResource($resource); $output[] = $this->renderResource($resource);
} }
@ -76,10 +78,10 @@ final class CelerityStaticResourceResponse {
private function renderResource(array $resource) { private function renderResource(array $resource) {
switch ($resource['type']) { switch ($resource['type']) {
case 'css': case 'css':
$path = phutil_escape_html($resource['path']); $path = phutil_escape_html($resource['uri']);
return '<link rel="stylesheet" type="text/css" href="'.$path.'" />'; return '<link rel="stylesheet" type="text/css" href="'.$path.'" />';
case 'js': case 'js':
$path = phutil_escape_html($resource['path']); $path = phutil_escape_html($resource['uri']);
return '<script type="text/javascript" src="'.$path.'">'. return '<script type="text/javascript" src="'.$path.'">'.
'</script>'; '</script>';
} }