Changeset View
Changeset View
Standalone View
Standalone View
scripts/celerity_mapper.php
| Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| $args = new PhutilArgumentParser($argv); | $args = new PhutilArgumentParser($argv); | ||||
| $args->setTagline('map static resources'); | $args->setTagline('map static resources'); | ||||
| $args->setSynopsis( | $args->setSynopsis( | ||||
| "**celerity_mapper.php** [--output __path__] [--with-custom] <webroot>"); | "**celerity_mapper.php** [--output __path__] [--with-custom] <webroot>"); | ||||
| $args->parse( | $args->parse( | ||||
| array( | array( | ||||
| 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', | 'name' => 'webroot', | ||||
| 'wildcard' => true, | 'wildcard' => true, | ||||
| ), | ), | ||||
| )); | )); | ||||
| $root = $args->getArg('webroot'); | $root = $args->getArg('webroot'); | ||||
| if (count($root) != 1 || !is_dir(reset($root))) { | if (count($root) != 1 || !is_dir(reset($root))) { | ||||
| $args->printHelpAndExit(); | $args->printHelpAndExit(); | ||||
| } | } | ||||
| $root = Filesystem::resolvePath(reset($root)); | $root = Filesystem::resolvePath(reset($root)); | ||||
| $celerity_path = Filesystem::resolvePath($args->getArg('output'), $root); | $celerity_path = Filesystem::resolvePath( | ||||
| $with_custom = $args->getArg('with-custom'); | '../src/__celerity_resource_map__.php', | ||||
| $root); | |||||
| $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"; | ||||
| $finder = 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); | ||||
| if (!$with_custom) { | |||||
| $finder->excludePath('./rsrc/custom'); | |||||
| } | |||||
| $raw_files = $finder->find(); | $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) { | ||||
| echo "."; | echo "."; | ||||
| $path = '/'.Filesystem::readablePath($path, $root); | $path = '/'.Filesystem::readablePath($path, $root); | ||||
| $type = CelerityResourceTransformer::getResourceType($path); | $type = CelerityResourceTransformer::getResourceType($path); | ||||
| Show All 15 Lines | |||||
| echo "Finding transformable static resources...\n"; | echo "Finding transformable static resources...\n"; | ||||
| $finder = 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); | ||||
| if (!$with_custom) { | |||||
| $finder->excludePath('./rsrc/custom'); | |||||
| } | |||||
| $files = $finder->find(); | $files = $finder->find(); | ||||
| echo "Processing ".count($files)." files"; | echo "Processing ".count($files)." files"; | ||||
| $file_map = array(); | $file_map = array(); | ||||
| foreach ($files as $path => $raw_hash) { | foreach ($files as $path => $raw_hash) { | ||||
| echo "."; | echo "."; | ||||
| $path = '/'.Filesystem::readablePath($path, $root); | $path = '/'.Filesystem::readablePath($path, $root); | ||||
| ▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines | |||||