@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Begin construction of `bin/celerity map`

Summary:
Ref T4222. Moves us toward a more modern Celerity CLI, and moves map discovery into the classtree. This is a little bit bulky (and means you can't ship completely standalone celerity maps) but has the advantage of being completely standard, and we could subclass maps into an auto-discovering map later if we have a need for it.

This doesn't affect the existing Celerity stuff. I'm going to build the new stuff in parallel, and then swap us over at the end.

Test Plan: Ran `bin/celerity map`, got reasonable-looking output.

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7864

+192
+1
bin/celerity
··· 1 + ../scripts/setup/manage_celerity.php
+21
scripts/setup/manage_celerity.php
··· 1 + #!/usr/bin/env php 2 + <?php 3 + 4 + $root = dirname(dirname(dirname(__FILE__))); 5 + require_once $root.'/scripts/__init_script__.php'; 6 + 7 + $args = new PhutilArgumentParser($argv); 8 + $args->setTagline('manage celerity'); 9 + $args->setSynopsis(<<<EOSYNOPSIS 10 + **celerity** __command__ [__options__] 11 + Manage static resources. 12 + 13 + EOSYNOPSIS 14 + ); 15 + $args->parseStandardArguments(); 16 + 17 + $workflows = id(new PhutilSymbolLoader()) 18 + ->setAncestorClass('CelerityManagementWorkflow') 19 + ->loadObjects(); 20 + $workflows[] = new PhutilHelpArgumentWorkflow(); 21 + $args->parseWorkflows($workflows);
+9
src/__phutil_library_map__.php
··· 94 94 'AuditActionMenuEventListener' => 'applications/audit/events/AuditActionMenuEventListener.php', 95 95 'BuildStepImplementation' => 'applications/harbormaster/step/BuildStepImplementation.php', 96 96 'CelerityAPI' => 'infrastructure/celerity/CelerityAPI.php', 97 + 'CelerityManagementMapWorkflow' => 'infrastructure/celerity/management/CelerityManagementMapWorkflow.php', 98 + 'CelerityManagementWorkflow' => 'infrastructure/celerity/management/CelerityManagementWorkflow.php', 97 99 'CelerityPhabricatorResourceController' => 'infrastructure/celerity/CelerityPhabricatorResourceController.php', 100 + 'CelerityPhabricatorResources' => 'infrastructure/celerity/resources/CelerityPhabricatorResources.php', 98 101 'CelerityResourceController' => 'infrastructure/celerity/CelerityResourceController.php', 99 102 'CelerityResourceGraph' => 'infrastructure/celerity/CelerityResourceGraph.php', 100 103 'CelerityResourceMap' => 'infrastructure/celerity/CelerityResourceMap.php', 101 104 'CelerityResourceTransformer' => 'infrastructure/celerity/CelerityResourceTransformer.php', 102 105 'CelerityResourceTransformerTestCase' => 'infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php', 106 + 'CelerityResources' => 'infrastructure/celerity/resources/CelerityResources.php', 107 + 'CelerityResourcesOnDisk' => 'infrastructure/celerity/resources/CelerityResourcesOnDisk.php', 103 108 'CeleritySpriteGenerator' => 'infrastructure/celerity/CeleritySpriteGenerator.php', 104 109 'CelerityStaticResourceResponse' => 'infrastructure/celerity/CelerityStaticResourceResponse.php', 105 110 'CommandBuildStepImplementation' => 'applications/harbormaster/step/CommandBuildStepImplementation.php', ··· 2506 2511 ), 2507 2512 'AphrontWebpageResponse' => 'AphrontHTMLResponse', 2508 2513 'AuditActionMenuEventListener' => 'PhabricatorEventListener', 2514 + 'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow', 2515 + 'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow', 2509 2516 'CelerityPhabricatorResourceController' => 'CelerityResourceController', 2517 + 'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk', 2510 2518 'CelerityResourceController' => 'PhabricatorController', 2511 2519 'CelerityResourceGraph' => 'AbstractDirectedGraph', 2512 2520 'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase', 2521 + 'CelerityResourcesOnDisk' => 'CelerityResources', 2513 2522 'CommandBuildStepImplementation' => 'VariableBuildStepImplementation', 2514 2523 'ConduitAPIMethod' => 2515 2524 array(
+27
src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php
··· 1 + <?php 2 + 3 + final class CelerityManagementMapWorkflow 4 + extends CelerityManagementWorkflow { 5 + 6 + public function didConstruct() { 7 + $this 8 + ->setName('map') 9 + ->setExamples('**map** [options]') 10 + ->setSynopsis(pht('Rebuild static resource maps.')) 11 + ->setArguments( 12 + array()); 13 + } 14 + 15 + public function execute(PhutilArgumentParser $args) { 16 + $resources_map = CelerityResources::getAll(); 17 + 18 + foreach ($resources_map as $name => $resources) { 19 + // TODO: This does not do anything useful yet. 20 + var_dump($resources->findBinaryResources()); 21 + var_dump($resources->findTextResources()); 22 + } 23 + 24 + return 0; 25 + } 26 + 27 + }
+6
src/infrastructure/celerity/management/CelerityManagementWorkflow.php
··· 1 + <?php 2 + 3 + abstract class CelerityManagementWorkflow 4 + extends PhabricatorManagementWorkflow { 5 + 6 + }
+24
src/infrastructure/celerity/resources/CelerityPhabricatorResources.php
··· 1 + <?php 2 + 3 + /** 4 + * Defines Phabricator's static resources. 5 + */ 6 + final class CelerityPhabricatorResources extends CelerityResourcesOnDisk { 7 + 8 + public function getName() { 9 + return 'phabricator'; 10 + } 11 + 12 + public function getPathToResources() { 13 + return $this->getPhabricatorPath('webroot/rsrc/'); 14 + } 15 + 16 + public function getPathToMap() { 17 + return $this->getPhabricatorPath('resources/celerity/map.php'); 18 + } 19 + 20 + private function getPhabricatorPath($to_file) { 21 + return dirname(phutil_get_library_root('phabricator')).'/'.$to_file; 22 + } 23 + 24 + }
+47
src/infrastructure/celerity/resources/CelerityResources.php
··· 1 + <?php 2 + 3 + /** 4 + * Defines the location of static resources. 5 + */ 6 + abstract class CelerityResources { 7 + 8 + abstract public function getName(); 9 + abstract public function getPathToMap(); 10 + abstract public function findBinaryResources(); 11 + abstract public function findTextResources(); 12 + 13 + public function getResourceHashKey() { 14 + return PhabricatorEnv::getEnvConfig('celerity.resource-hash'); 15 + } 16 + 17 + public static function getAll() { 18 + static $resources_map; 19 + if ($resources_map === null) { 20 + $resources_map = array(); 21 + 22 + $resources_list = id(new PhutilSymbolLoader()) 23 + ->setAncestorClass('CelerityResources') 24 + ->loadObjects(); 25 + 26 + foreach ($resources_list as $resources) { 27 + $name = $resources->getName(); 28 + if (empty($resources_map[$name])) { 29 + $resources_map[$name] = $resources; 30 + } else { 31 + $old = get_class($resources_map[$name]); 32 + $new = get_class($resources); 33 + throw new Exception( 34 + pht( 35 + 'Celerity resource maps must have unique names, but maps %s and '. 36 + '%s share the same name, "%s".', 37 + $old, 38 + $new, 39 + $name)); 40 + } 41 + } 42 + } 43 + 44 + return $resources_map; 45 + } 46 + 47 + }
+57
src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php
··· 1 + <?php 2 + 3 + /** 4 + * Defines the location of static resources on disk. 5 + */ 6 + abstract class CelerityResourcesOnDisk extends CelerityResources { 7 + 8 + abstract public function getPathToResources(); 9 + 10 + public function findBinaryResources() { 11 + return $this->findResourcesWithSuffixes($this->getBinaryFileSuffixes()); 12 + } 13 + 14 + public function findTextResources() { 15 + return $this->findResourcesWithSuffixes($this->getTextFileSuffixes()); 16 + } 17 + 18 + protected function getBinaryFileSuffixes() { 19 + return array( 20 + 'png', 21 + 'jpg', 22 + 'gif', 23 + 'swf', 24 + ); 25 + } 26 + 27 + protected function getTextFileSuffixes() { 28 + return array( 29 + 'js', 30 + 'css', 31 + ); 32 + } 33 + 34 + private function findResourcesWithSuffixes(array $suffixes) { 35 + $root = $this->getPathToResources(); 36 + 37 + $finder = id(new FileFinder($root)) 38 + ->withType('f') 39 + ->withFollowSymlinks(true) 40 + ->setGenerateChecksums(true); 41 + 42 + foreach ($suffixes as $suffix) { 43 + $finder->withSuffix($suffix); 44 + } 45 + 46 + $raw_files = $finder->find(); 47 + 48 + $results = array(); 49 + foreach ($raw_files as $path => $hash) { 50 + $readable = '/'.Filesystem::readablePath($path, $root); 51 + $results[$readable] = $hash; 52 + } 53 + 54 + return $results; 55 + } 56 + 57 + }