Copy file attachment edges to new storage
[phabricator.git] / scripts / celerity / generate_sprites.php
blobccdd194b36bdef0b91d76087c2d6b9542098150c
1 #!/usr/bin/env php
2 <?php
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
9 **sprites**
10 Rebuild CSS sprite sheets.
12 EOHELP
14 $args->parseStandardArguments();
15 $args->parse(
16 array(
17 array(
18 'name' => 'force',
19 'help' => pht('Force regeneration even if sources have not changed.'),
21 ));
23 $root = dirname(phutil_get_library_root('phabricator'));
24 $webroot = $root.'/webroot/rsrc';
25 $webroot = Filesystem::readablePath($webroot);
27 $generator = new CeleritySpriteGenerator();
29 $sheets = array(
30 'tokens' => $generator->buildTokenSheet(),
31 'login' => $generator->buildLoginSheet(),
34 list($err) = exec_manual('optipng');
35 if ($err) {
36 $have_optipng = false;
37 echo phutil_console_format(
38 "<bg:red> %s </bg> %s\n%s\n",
39 pht('WARNING'),
40 pht('`%s` not found in PATH.', 'optipng'),
41 pht('Sprites will not be optimized! Install `%s`!', 'optipng'));
42 } else {
43 $have_optipng = true;
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)) {
56 continue;
61 $sheet
62 ->generateCSS($webroot."/css/sprite-{$name}.css")
63 ->generateManifest($root."/resources/sprite/manifest/{$name}.json");
65 foreach ($sheet->getScales() as $scale) {
66 if ($scale == 1) {
67 $sheet_name = "sprite-{$name}.png";
68 } else {
69 $sheet_name = "sprite-{$name}-X{$scale}.png";
72 $full_path = "{$webroot}/image/{$sheet_name}";
73 $sheet->generateImage($full_path, $scale);
75 if ($have_optipng) {
76 echo pht('Optimizing...')."\n";
77 phutil_passthru('optipng -o7 -clobber %s', $full_path);
82 echo pht('Done.')."\n";