diff --git a/.gitignore b/.gitignore index 087ec833ac..4238818d5b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ /docs/ /src/.phutil_module_cache /conf/custom/* +/webroot/rsrc/custom /.divinercache .#* *# diff --git a/conf/default.conf.php b/conf/default.conf.php index d0d57a5764..d9270c7a24 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -973,6 +973,11 @@ return array( // "phd launch taskmaster". '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. // 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 diff --git a/scripts/celerity_mapper.php b/scripts/celerity_mapper.php index d563fb8cf5..5327c49275 100755 --- a/scripts/celerity_mapper.php +++ b/scripts/celerity_mapper.php @@ -149,27 +149,54 @@ $package_spec = array( require_once dirname(__FILE__).'/__init_script__.php'; -if ($argc != 2) { - $self = basename($argv[0]); - echo "usage: {$self} \n"; - exit(1); -} +$args = new PhutilArgumentParser($argv); +$args->setTagline('map static resources'); +$args->setSynopsis( + "**celerity_mapper.php** [--output __path__] [--with-custom] "); +$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 /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'); $runtime_map = array(); echo "Finding raw static resources...\n"; -$raw_files = id(new FileFinder($root)) +$finder = id(new FileFinder($root)) ->withType('f') ->withSuffix('png') ->withSuffix('jpg') ->withSuffix('gif') ->withSuffix('swf') ->withFollowSymlinks(true) - ->setGenerateChecksums(true) - ->find(); + ->setGenerateChecksums(true); +if (!$with_custom) { + $finder->excludePath('./rsrc/custom'); +} +$raw_files = $finder->find(); echo "Processing ".count($raw_files)." files"; foreach ($raw_files as $path => $hash) { @@ -194,13 +221,16 @@ $xformer = id(new CelerityResourceTransformer()) ->setRawResourceMap($runtime_map); echo "Finding transformable static resources...\n"; -$files = id(new FileFinder($root)) +$finder = id(new FileFinder($root)) ->withType('f') ->withSuffix('js') ->withSuffix('css') ->withFollowSymlinks(true) - ->setGenerateChecksums(true) - ->find(); + ->setGenerateChecksums(true); +if (!$with_custom) { + $finder->excludePath('./rsrc/custom'); +} +$files = $finder->find(); echo "Processing ".count($files)." files"; @@ -345,7 +375,5 @@ celerity_register_resource_map({$runtime_map}, {$package_map}); EOFILE; echo "Writing map...\n"; -Filesystem::writeFile( - $root.'/../src/__celerity_resource_map__.php', - $resource_map); +Filesystem::writeFile($celerity_path, $resource_map); echo "Done.\n"; diff --git a/src/infrastructure/celerity/CelerityResourceMap.php b/src/infrastructure/celerity/CelerityResourceMap.php index 5e79b883ca..0221959cc1 100644 --- a/src/infrastructure/celerity/CelerityResourceMap.php +++ b/src/infrastructure/celerity/CelerityResourceMap.php @@ -35,7 +35,10 @@ final class CelerityResourceMap { if (empty(self::$instance)) { self::$instance = new CelerityResourceMap(); $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) { throw new Exception("Failed to load Celerity resource map!"); }