Index: bin/celerity =================================================================== --- /dev/null +++ bin/celerity @@ -0,0 +1 @@ +../scripts/setup/manage_celerity.php \ No newline at end of file Index: scripts/setup/manage_celerity.php =================================================================== --- /dev/null +++ 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); Index: src/__phutil_library_map__.php =================================================================== --- src/__phutil_library_map__.php +++ src/__phutil_library_map__.php @@ -94,12 +94,17 @@ '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 @@ ), 'AphrontWebpageResponse' => 'AphrontHTMLResponse', 'AuditActionMenuEventListener' => 'PhabricatorEventListener', + 'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow', + 'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow', 'CelerityPhabricatorResourceController' => 'CelerityResourceController', + 'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk', 'CelerityResourceController' => 'PhabricatorController', 'CelerityResourceGraph' => 'AbstractDirectedGraph', 'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase', + 'CelerityResourcesOnDisk' => 'CelerityResources', 'CommandBuildStepImplementation' => 'VariableBuildStepImplementation', 'ConduitAPIMethod' => array( Index: src/infrastructure/celerity/management/CelerityManagementMapWorkflow.php =================================================================== --- /dev/null +++ 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; + } + +} Index: src/infrastructure/celerity/management/CelerityManagementWorkflow.php =================================================================== --- /dev/null +++ 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; + } + +} Index: src/infrastructure/celerity/resources/CelerityResources.php =================================================================== --- /dev/null +++ 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; + } + +} Index: src/infrastructure/celerity/resources/CelerityResourcesOnDisk.php =================================================================== --- /dev/null +++ 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; + } + +}