Skip to content

Commit 906ac21

Browse files
author
epriestley
committedJan 1, 2014
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
1 parent 95a806a commit 906ac21

8 files changed

+192
-0
lines changed
 

‎bin/celerity

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../scripts/setup/manage_celerity.php

‎scripts/setup/manage_celerity.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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);

‎src/__phutil_library_map__.php

+9
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,17 @@
9494
'AuditActionMenuEventListener' => 'applications/audit/events/AuditActionMenuEventListener.php',
9595
'BuildStepImplementation' => 'applications/harbormaster/step/BuildStepImplementation.php',
9696
'CelerityAPI' => 'infrastructure/celerity/CelerityAPI.php',
97+
'CelerityManagementMapWorkflow' => 'infrastructure/celerity/management/CelerityManagementMapWorkflow.php',
98+
'CelerityManagementWorkflow' => 'infrastructure/celerity/management/CelerityManagementWorkflow.php',
9799
'CelerityPhabricatorResourceController' => 'infrastructure/celerity/CelerityPhabricatorResourceController.php',
100+
'CelerityPhabricatorResources' => 'infrastructure/celerity/resources/CelerityPhabricatorResources.php',
98101
'CelerityResourceController' => 'infrastructure/celerity/CelerityResourceController.php',
99102
'CelerityResourceGraph' => 'infrastructure/celerity/CelerityResourceGraph.php',
100103
'CelerityResourceMap' => 'infrastructure/celerity/CelerityResourceMap.php',
101104
'CelerityResourceTransformer' => 'infrastructure/celerity/CelerityResourceTransformer.php',
102105
'CelerityResourceTransformerTestCase' => 'infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php',
106+
'CelerityResources' => 'infrastructure/celerity/resources/CelerityResources.php',
107+
'CelerityResourcesOnDisk' => 'infrastructure/celerity/resources/CelerityResourcesOnDisk.php',
103108
'CeleritySpriteGenerator' => 'infrastructure/celerity/CeleritySpriteGenerator.php',
104109
'CelerityStaticResourceResponse' => 'infrastructure/celerity/CelerityStaticResourceResponse.php',
105110
'CommandBuildStepImplementation' => 'applications/harbormaster/step/CommandBuildStepImplementation.php',
@@ -2506,10 +2511,14 @@
25062511
),
25072512
'AphrontWebpageResponse' => 'AphrontHTMLResponse',
25082513
'AuditActionMenuEventListener' => 'PhabricatorEventListener',
2514+
'CelerityManagementMapWorkflow' => 'CelerityManagementWorkflow',
2515+
'CelerityManagementWorkflow' => 'PhabricatorManagementWorkflow',
25092516
'CelerityPhabricatorResourceController' => 'CelerityResourceController',
2517+
'CelerityPhabricatorResources' => 'CelerityResourcesOnDisk',
25102518
'CelerityResourceController' => 'PhabricatorController',
25112519
'CelerityResourceGraph' => 'AbstractDirectedGraph',
25122520
'CelerityResourceTransformerTestCase' => 'PhabricatorTestCase',
2521+
'CelerityResourcesOnDisk' => 'CelerityResources',
25132522
'CommandBuildStepImplementation' => 'VariableBuildStepImplementation',
25142523
'ConduitAPIMethod' =>
25152524
array(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
abstract class CelerityManagementWorkflow
4+
extends PhabricatorManagementWorkflow {
5+
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
}

0 commit comments

Comments
 (0)
Failed to load comments.