Page MenuHomePhabricator

D7864.diff
No OneTemporary

D7864.diff

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
+<?php
+
+$root = dirname(dirname(dirname(__FILE__)));
+require_once $root.'/scripts/__init_script__.php';
+
+$args = new PhutilArgumentParser($argv);
+$args->setTagline('manage celerity');
+$args->setSynopsis(<<<EOSYNOPSIS
+**celerity** __command__ [__options__]
+ Manage static resources.
+
+EOSYNOPSIS
+ );
+$args->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 @@
+<?php
+
+final class CelerityManagementMapWorkflow
+ extends CelerityManagementWorkflow {
+
+ public function didConstruct() {
+ $this
+ ->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 @@
+<?php
+
+abstract class CelerityManagementWorkflow
+ extends PhabricatorManagementWorkflow {
+
+}
Index: src/infrastructure/celerity/resources/CelerityPhabricatorResources.php
===================================================================
--- /dev/null
+++ src/infrastructure/celerity/resources/CelerityPhabricatorResources.php
@@ -0,0 +1,24 @@
+<?php
+
+/**
+ * Defines Phabricator's static resources.
+ */
+final class CelerityPhabricatorResources extends CelerityResourcesOnDisk {
+
+ public function getName() {
+ return 'phabricator';
+ }
+
+ public function getPathToResources() {
+ return $this->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 @@
+<?php
+
+/**
+ * Defines the location of static resources.
+ */
+abstract class CelerityResources {
+
+ abstract public function getName();
+ abstract public function getPathToMap();
+ abstract public function findBinaryResources();
+ abstract public function findTextResources();
+
+ public function getResourceHashKey() {
+ return PhabricatorEnv::getEnvConfig('celerity.resource-hash');
+ }
+
+ public static function getAll() {
+ static $resources_map;
+ if ($resources_map === null) {
+ $resources_map = array();
+
+ $resources_list = id(new PhutilSymbolLoader())
+ ->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 @@
+<?php
+
+/**
+ * Defines the location of static resources on disk.
+ */
+abstract class CelerityResourcesOnDisk extends CelerityResources {
+
+ abstract public function getPathToResources();
+
+ public function findBinaryResources() {
+ return $this->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;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Tue, May 14, 2:03 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6293437
Default Alt Text
D7864.diff (8 KB)

Event Timeline