mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 06:42:42 +01:00
Allow specifying custom celerity resource map
Summary: We have custom static resources. We currently include them in Phabricator's celerity resource map which is causing some pain - we need to regenerate the file without our custom resources before pushing upstream, we need to discard our changes before pulling from upstream and we need to rebuild with our changes to run Phabricator. This diff allows writing and reading the map in other location. The plan is this - I will run `celerity_mapper.php` twice - once to build Phabricator-only resources (to push to upstream) and once to build Phabricator + ours resoruces to put in our directory. Better solution would be to create a map just with our resources and read and combine it with Phabricator resources. But it is complicated because we have dependencies on Phabricator resources. Test Plan: `celerity_mapper.php webroot` `celerity_mapper.php webroot ../facebook/src/__celerity_resource_map__.php` Delete Phabricator's celerity map, set 'celerity.resource-path' and successfully load Phabricator. Reviewers: epriestley, edward Reviewed By: epriestley CC: aran, Koolvin Maniphest Tasks: T721 Differential Revision: https://secure.phabricator.com/D2630
This commit is contained in:
parent
06b0f0d8ab
commit
8883c9494f
4 changed files with 53 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
||||||
/docs/
|
/docs/
|
||||||
/src/.phutil_module_cache
|
/src/.phutil_module_cache
|
||||||
/conf/custom/*
|
/conf/custom/*
|
||||||
|
/webroot/rsrc/custom
|
||||||
/.divinercache
|
/.divinercache
|
||||||
.#*
|
.#*
|
||||||
*#
|
*#
|
||||||
|
|
|
@ -973,6 +973,11 @@ return array(
|
||||||
// "phd launch <N> taskmaster".
|
// "phd launch <N> taskmaster".
|
||||||
'phd.start-taskmasters' => 4,
|
'phd.start-taskmasters' => 4,
|
||||||
|
|
||||||
|
// Path to custom celerity resource map. Absolute or relative to
|
||||||
|
// 'phabricator/src'. Defaults to '__celerity_resource_map__.php'.
|
||||||
|
// See also `scripts/celerity_mapper.php`.
|
||||||
|
'celerity.resource-path' => null,
|
||||||
|
|
||||||
// This value is an input to the hash function when building resource hashes.
|
// This value is an input to the hash function when building resource hashes.
|
||||||
// It has no security value, but if you accidentally poison user caches (by
|
// It has no security value, but if you accidentally poison user caches (by
|
||||||
// pushing a bad patch or having something go wrong with a CDN, e.g.) you can
|
// pushing a bad patch or having something go wrong with a CDN, e.g.) you can
|
||||||
|
|
|
@ -149,27 +149,54 @@ $package_spec = array(
|
||||||
|
|
||||||
require_once dirname(__FILE__).'/__init_script__.php';
|
require_once dirname(__FILE__).'/__init_script__.php';
|
||||||
|
|
||||||
if ($argc != 2) {
|
$args = new PhutilArgumentParser($argv);
|
||||||
$self = basename($argv[0]);
|
$args->setTagline('map static resources');
|
||||||
echo "usage: {$self} <webroot>\n";
|
$args->setSynopsis(
|
||||||
exit(1);
|
"**celerity_mapper.php** [--output __path__] [--with-custom] <webroot>");
|
||||||
}
|
$args->parse(
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'name' => 'output',
|
||||||
|
'param' => 'path',
|
||||||
|
'default' => '../src/__celerity_resource_map__.php',
|
||||||
|
'help' => "Set the path for resource map. It is usually useful for ".
|
||||||
|
"'celerity.resource-path' configuration.",
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'with-custom',
|
||||||
|
'help' => 'Include resources in <webroot>/rsrc/custom/.',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'name' => 'webroot',
|
||||||
|
'wildcard' => true,
|
||||||
|
),
|
||||||
|
));
|
||||||
|
|
||||||
$root = Filesystem::resolvePath($argv[1]);
|
$root = $args->getArg('webroot');
|
||||||
|
if (count($root) != 1 || !is_dir(reset($root))) {
|
||||||
|
$args->printHelpAndExit();
|
||||||
|
}
|
||||||
|
$root = Filesystem::resolvePath(reset($root));
|
||||||
|
|
||||||
|
$celerity_path = Filesystem::resolvePath($args->getArg('output'), $root);
|
||||||
|
$with_custom = $args->getArg('with-custom');
|
||||||
|
|
||||||
$resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash');
|
$resource_hash = PhabricatorEnv::getEnvConfig('celerity.resource-hash');
|
||||||
$runtime_map = array();
|
$runtime_map = array();
|
||||||
|
|
||||||
echo "Finding raw static resources...\n";
|
echo "Finding raw static resources...\n";
|
||||||
$raw_files = id(new FileFinder($root))
|
$finder = id(new FileFinder($root))
|
||||||
->withType('f')
|
->withType('f')
|
||||||
->withSuffix('png')
|
->withSuffix('png')
|
||||||
->withSuffix('jpg')
|
->withSuffix('jpg')
|
||||||
->withSuffix('gif')
|
->withSuffix('gif')
|
||||||
->withSuffix('swf')
|
->withSuffix('swf')
|
||||||
->withFollowSymlinks(true)
|
->withFollowSymlinks(true)
|
||||||
->setGenerateChecksums(true)
|
->setGenerateChecksums(true);
|
||||||
->find();
|
if (!$with_custom) {
|
||||||
|
$finder->excludePath('./rsrc/custom');
|
||||||
|
}
|
||||||
|
$raw_files = $finder->find();
|
||||||
|
|
||||||
echo "Processing ".count($raw_files)." files";
|
echo "Processing ".count($raw_files)." files";
|
||||||
foreach ($raw_files as $path => $hash) {
|
foreach ($raw_files as $path => $hash) {
|
||||||
|
@ -194,13 +221,16 @@ $xformer = id(new CelerityResourceTransformer())
|
||||||
->setRawResourceMap($runtime_map);
|
->setRawResourceMap($runtime_map);
|
||||||
|
|
||||||
echo "Finding transformable static resources...\n";
|
echo "Finding transformable static resources...\n";
|
||||||
$files = id(new FileFinder($root))
|
$finder = id(new FileFinder($root))
|
||||||
->withType('f')
|
->withType('f')
|
||||||
->withSuffix('js')
|
->withSuffix('js')
|
||||||
->withSuffix('css')
|
->withSuffix('css')
|
||||||
->withFollowSymlinks(true)
|
->withFollowSymlinks(true)
|
||||||
->setGenerateChecksums(true)
|
->setGenerateChecksums(true);
|
||||||
->find();
|
if (!$with_custom) {
|
||||||
|
$finder->excludePath('./rsrc/custom');
|
||||||
|
}
|
||||||
|
$files = $finder->find();
|
||||||
|
|
||||||
echo "Processing ".count($files)." files";
|
echo "Processing ".count($files)." files";
|
||||||
|
|
||||||
|
@ -345,7 +375,5 @@ celerity_register_resource_map({$runtime_map}, {$package_map});
|
||||||
EOFILE;
|
EOFILE;
|
||||||
|
|
||||||
echo "Writing map...\n";
|
echo "Writing map...\n";
|
||||||
Filesystem::writeFile(
|
Filesystem::writeFile($celerity_path, $resource_map);
|
||||||
$root.'/../src/__celerity_resource_map__.php',
|
|
||||||
$resource_map);
|
|
||||||
echo "Done.\n";
|
echo "Done.\n";
|
||||||
|
|
|
@ -35,7 +35,10 @@ final class CelerityResourceMap {
|
||||||
if (empty(self::$instance)) {
|
if (empty(self::$instance)) {
|
||||||
self::$instance = new CelerityResourceMap();
|
self::$instance = new CelerityResourceMap();
|
||||||
$root = phutil_get_library_root('phabricator');
|
$root = phutil_get_library_root('phabricator');
|
||||||
$ok = include_once $root.'/__celerity_resource_map__.php';
|
$path = PhabricatorEnv::getEnvConfig(
|
||||||
|
'celerity.resource-map',
|
||||||
|
'__celerity_resource_map__.php');
|
||||||
|
$ok = include_once Filesystem::resolvePath($path, $root);
|
||||||
if (!$ok) {
|
if (!$ok) {
|
||||||
throw new Exception("Failed to load Celerity resource map!");
|
throw new Exception("Failed to load Celerity resource map!");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue