@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 108 lines 3.2 kB view raw
1<?php 2 3final class CelerityManagementGenerateSpritesWorkflow 4 extends CelerityManagementWorkflow { 5 6 protected function didConstruct() { 7 $this 8 ->setName('sprites') 9 ->setExamples('**sprites** [options]') 10 ->setSynopsis(pht('Rebuild CSS sprite sheets.')) 11 ->setArguments( 12 array( 13 array( 14 'name' => 'force', 15 'help' => pht('Force regeneration even no sources have changed.'), 16 ), 17 array( 18 'name' => 'no-map', 19 'help' => 20 pht( 21 'Do not invoke `%s` after updating sprites', 22 'celerity map'), 23 ), 24 )); 25 } 26 27 public function execute(PhutilArgumentParser $args) { 28 $resources_map = CelerityPhysicalResources::getAll(); 29 30 $console = PhutilConsole::getConsole(); 31 32 $root = dirname(phutil_get_library_root('phorge')); 33 $webroot = $root.'/webroot/rsrc'; 34 $webroot = Filesystem::readablePath($webroot); 35 36 $generator = new CeleritySpriteGenerator(); 37 38 $sheets = array( 39 'tokens' => $generator->buildTokenSheet(), 40 'login' => $generator->buildLoginSheet(), 41 ); 42 43 list($err) = exec_manual('optipng'); 44 if ($err) { 45 $have_optipng = false; 46 $console->writeErr( 47 "<bg:red> %s </bg> %s\n%s\n", 48 pht('WARNING'), 49 pht('`%s` not found in PATH.', 'optipng'), 50 pht('Sprites will not be optimized! Install `%s`!', 'optipng')); 51 } else { 52 $have_optipng = true; 53 } 54 55 foreach ($sheets as $name => $sheet) { 56 57 $sheet->setBasePath($root); 58 59 $manifest_path = $root.'/resources/sprite/manifest/'.$name.'.json'; 60 if (!$args->getArg('force')) { 61 if (Filesystem::pathExists($manifest_path)) { 62 $data = Filesystem::readFile($manifest_path); 63 $data = phutil_json_decode($data); 64 if (!$sheet->needsRegeneration($data)) { 65 continue; 66 } 67 } 68 } 69 70 $sheet 71 ->generateCSS($webroot."/css/sprite-{$name}.css") 72 ->generateManifest($root."/resources/sprite/manifest/{$name}.json"); 73 74 foreach ($sheet->getScales() as $scale) { 75 if ($scale == 1) { 76 $sheet_name = "sprite-{$name}.png"; 77 } else { 78 $sheet_name = "sprite-{$name}-X{$scale}.png"; 79 } 80 81 $full_path = "{$webroot}/image/{$sheet_name}"; 82 $sheet->generateImage($full_path, $scale); 83 84 if ($have_optipng) { 85 $console->writeOut("%s\n", pht('Optimizing...')); 86 phutil_passthru('optipng -o7 -clobber %s', $full_path); 87 } 88 } 89 } 90 91 $run_map = !$args->getArg('no-map'); 92 93 if ($run_map) { 94 $console->writeOut( 95 "%s\n", 96 pht('Done generating sprites - updating map...')); 97 $map_flow = id($args->getWorkflows())['map']; 98 // this is very hacky, but it works because `map` has no arguments. 99 $map_flow->execute($args); 100 } else { 101 $console->writeOut("%s\n", pht('Done.')); 102 return 0; 103 } 104 105 } 106 107 108}