From 906ac21e543d434f79d5088000127ead6bc49dd9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 31 Dec 2013 18:02:41 -0800 Subject: [PATCH] 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 --- bin/celerity | 1 + scripts/setup/manage_celerity.php | 21 +++++++ src/__phutil_library_map__.php | 9 +++ .../CelerityManagementMapWorkflow.php | 27 +++++++++ .../management/CelerityManagementWorkflow.php | 6 ++ .../CelerityPhabricatorResources.php | 24 ++++++++ .../celerity/resources/CelerityResources.php | 47 +++++++++++++++ .../resources/CelerityResourcesOnDisk.php | 57 +++++++++++++++++++ 8 files changed, 192 insertions(+) create mode 120000 bin/celerity create mode 100755 scripts/setup/manage_celerity.php create mode 100644 src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php create mode 100644 src/infrastructure/celerity/management/CelerityManagementWorkflow.php create mode 100644 src/infrastructure/celerity/resources/CelerityPhabricatorResources.php create mode 100644 src/infrastructure/celerity/resources/CelerityResources.php create mode 100644 src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php diff --git a/bin/celerity b/bin/celerity new file mode 120000 index 0000000000..f4558cb181 --- /dev/null +++ b/bin/celerity @@ -0,0 +1 @@ +../scripts/setup/manage_celerity.php \ No newline at end of file diff --git a/scripts/setup/manage_celerity.php b/scripts/setup/manage_celerity.php new file mode 100755 index 0000000000..4a559711c2 --- /dev/null +++ b/scripts/setup/manage_celerity.php @@ -0,0 +1,21 @@ +#!/usr/bin/env php +setTagline('manage celerity'); +$args->setSynopsis(<<parseStandardArguments(); + +$workflows = id(new PhutilSymbolLoader()) + ->setAncestorClass('CelerityManagementWorkflow') + ->loadObjects(); +$workflows[] = new PhutilHelpArgumentWorkflow(); +$args->parseWorkflows($workflows); diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 3089f31ce5..3d6c2a19cf 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -94,12 +94,17 @@ phutil_register_library_map(array( 'AuditActionMenuEventListener' => 'applications/audit/events/AuditActionMenuEventListener.php', 'BuildStepImplementation' => 'applications/harbormaster/step/BuildStepImplementation.php', 'CelerityAPI' => 'infrastructure/celerity/CelerityAPI.php', + 'CelerityManagementMapWorkflow' => 'infrastructure/celerity/management/CelerityManagementMapWorkflow.php', + 'CelerityManagementWorkflow' => 'infrastructure/celerity/management/CelerityManagementWorkflow.php', 'CelerityPhabricatorResourceController' => 'infrastructure/celerity/CelerityPhabricatorResourceController.php', + 'CelerityPhabricatorResources' => 'infrastructure/celerity/resources/CelerityPhabricatorResources.php', 'CelerityResourceController' => 'infrastructure/celerity/CelerityResourceController.php', 'CelerityResourceGraph' => 'infrastructure/celerity/CelerityResourceGraph.php', 'CelerityResourceMap' => 'infrastructure/celerity/CelerityResourceMap.php', 'CelerityResourceTransformer' => 'infrastructure/celerity/CelerityResourceTransformer.php', 'CelerityResourceTransformerTestCase' => 'infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php', + 'CelerityResources' => 'infrastructure/celerity/resources/CelerityResources.php', + 'CelerityResourcesOnDisk' => 'infrastructure/celerity/resources/CelerityResourcesOnDisk.php', 'CeleritySpriteGenerator' => 'infrastructure/celerity/CeleritySpriteGenerator.php', 'CelerityStaticResourceResponse' => 'infrastructure/celerity/CelerityStaticResourceResponse.php', 'CommandBuildStepImplementation' => 'applications/harbormaster/step/CommandBuildStepImplementation.php', @@ -2506,10 +2511,14 @@ phutil_register_library_map(array( ), 'AphrontWebpageResponse' => 'AphrontHTMLResponse', 'AuditActionMenuEventListener' => 'PhabricatorEventListener', + 'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow', + 'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow', 'CelerityPhabricatorResourceController' => 'CelerityResourceController', + 'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk', 'CelerityResourceController' => 'PhabricatorController', 'CelerityResourceGraph' => 'AbstractDirectedGraph', 'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase', + 'CelerityResourcesOnDisk' => 'CelerityResources', 'CommandBuildStepImplementation' => 'VariableBuildStepImplementation', 'ConduitAPIMethod' => array( diff --git a/src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php b/src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php new file mode 100644 index 0000000000..5f69baccbc --- /dev/null +++ b/src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php @@ -0,0 +1,27 @@ +setName('map') + ->setExamples('**map** [options]') + ->setSynopsis(pht('Rebuild static resource maps.')) + ->setArguments( + array()); + } + + public function execute(PhutilArgumentParser $args) { + $resources_map = CelerityResources::getAll(); + + foreach ($resources_map as $name => $resources) { + // TODO: This does not do anything useful yet. + var_dump($resources->findBinaryResources()); + var_dump($resources->findTextResources()); + } + + return 0; + } + +} diff --git a/src/infrastructure/celerity/management/CelerityManagementWorkflow.php b/src/infrastructure/celerity/management/CelerityManagementWorkflow.php new file mode 100644 index 0000000000..6d23fe5480 --- /dev/null +++ b/src/infrastructure/celerity/management/CelerityManagementWorkflow.php @@ -0,0 +1,6 @@ +getPhabricatorPath('webroot/rsrc/'); + } + + public function getPathToMap() { + return $this->getPhabricatorPath('resources/celerity/map.php'); + } + + private function getPhabricatorPath($to_file) { + return dirname(phutil_get_library_root('phabricator')).'/'.$to_file; + } + +} diff --git a/src/infrastructure/celerity/resources/CelerityResources.php b/src/infrastructure/celerity/resources/CelerityResources.php new file mode 100644 index 0000000000..e7253ead8a --- /dev/null +++ b/src/infrastructure/celerity/resources/CelerityResources.php @@ -0,0 +1,47 @@ +setAncestorClass('CelerityResources') + ->loadObjects(); + + foreach ($resources_list as $resources) { + $name = $resources->getName(); + if (empty($resources_map[$name])) { + $resources_map[$name] = $resources; + } else { + $old = get_class($resources_map[$name]); + $new = get_class($resources); + throw new Exception( + pht( + 'Celerity resource maps must have unique names, but maps %s and '. + '%s share the same name, "%s".', + $old, + $new, + $name)); + } + } + } + + return $resources_map; + } + +} diff --git a/src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php b/src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php new file mode 100644 index 0000000000..47c91b48c0 --- /dev/null +++ b/src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php @@ -0,0 +1,57 @@ +findResourcesWithSuffixes($this->getBinaryFileSuffixes()); + } + + public function findTextResources() { + return $this->findResourcesWithSuffixes($this->getTextFileSuffixes()); + } + + protected function getBinaryFileSuffixes() { + return array( + 'png', + 'jpg', + 'gif', + 'swf', + ); + } + + protected function getTextFileSuffixes() { + return array( + 'js', + 'css', + ); + } + + private function findResourcesWithSuffixes(array $suffixes) { + $root = $this->getPathToResources(); + + $finder = id(new FileFinder($root)) + ->withType('f') + ->withFollowSymlinks(true) + ->setGenerateChecksums(true); + + foreach ($suffixes as $suffix) { + $finder->withSuffix($suffix); + } + + $raw_files = $finder->find(); + + $results = array(); + foreach ($raw_files as $path => $hash) { + $readable = '/'.Filesystem::readablePath($path, $root); + $results[$readable] = $hash; + } + + return $results; + } + +}