mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-17 18:21:11 +01:00
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
This commit is contained in:
parent
95a806ada3
commit
906ac21e54
8 changed files with 192 additions and 0 deletions
1
bin/celerity
Symbolic link
1
bin/celerity
Symbolic link
|
@ -0,0 +1 @@
|
|||
../scripts/setup/manage_celerity.php
|
21
scripts/setup/manage_celerity.php
Executable file
21
scripts/setup/manage_celerity.php
Executable file
|
@ -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);
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
|
||||
abstract class CelerityManagementWorkflow
|
||||
extends PhabricatorManagementWorkflow {
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
47
src/infrastructure/celerity/resources/CelerityResources.php
Normal file
47
src/infrastructure/celerity/resources/CelerityResources.php
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue