4 require_once dirname(dirname(__FILE__
)).'/__init_script__.php';
6 $args = new PhutilArgumentParser($argv);
7 $args->setTagline(pht('regenerate CSS sprite sheets'));
8 $args->setSynopsis(<<<EOHELP
10 Rebuild CSS sprite sheets.
14 $args->parseStandardArguments();
19 'help' => pht('Force regeneration even if sources have not changed.'),
23 $root = dirname(phutil_get_library_root('phabricator'));
24 $webroot = $root.'/webroot/rsrc';
25 $webroot = Filesystem
::readablePath($webroot);
27 $generator = new CeleritySpriteGenerator();
30 'tokens' => $generator->buildTokenSheet(),
31 'login' => $generator->buildLoginSheet(),
34 list($err) = exec_manual('optipng');
36 $have_optipng = false;
37 echo phutil_console_format(
38 "<bg:red> %s </bg> %s\n%s\n",
40 pht('`%s` not found in PATH.', 'optipng'),
41 pht('Sprites will not be optimized! Install `%s`!', 'optipng'));
46 foreach ($sheets as $name => $sheet) {
48 $sheet->setBasePath($root);
50 $manifest_path = $root.'/resources/sprite/manifest/'.$name.'.json';
51 if (!$args->getArg('force')) {
52 if (Filesystem
::pathExists($manifest_path)) {
53 $data = Filesystem
::readFile($manifest_path);
54 $data = phutil_json_decode($data);
55 if (!$sheet->needsRegeneration($data)) {
62 ->generateCSS($webroot."/css/sprite-{$name}.css")
63 ->generateManifest($root."/resources/sprite/manifest/{$name}.json");
65 foreach ($sheet->getScales() as $scale) {
67 $sheet_name = "sprite-{$name}.png";
69 $sheet_name = "sprite-{$name}-X{$scale}.png";
72 $full_path = "{$webroot}/image/{$sheet_name}";
73 $sheet->generateImage($full_path, $scale);
76 echo pht('Optimizing...')."\n";
77 phutil_passthru('optipng -o7 -clobber %s', $full_path);
82 echo pht('Done.')."\n";