#!/usr/bin/env php
<?php

declare(strict_types = 1);

use \Dompdf\Cpdf;

require_once __DIR__ . '/../../vendor/autoload.php';

$filePath = $argv[1];
if (! file_exists($argv[1])) {
    echo 'File ' . $argv[1] . ' does not exist.' . "\n";
    exit(1);
}

echo 'Building cache for: ' . $filePath . "\n";
$cpdf = new Cpdf();
$cpdf->selectFont($filePath);

$generatedFile = $filePath . '.json';
if (! file_exists($generatedFile)) {
    echo 'Cache file was not generated.' . "\n";
    echo 'Messages: ' . $cpdf->messages . "\n";
    exit(1);
}

echo 'Built cache as: ' . $generatedFile . "\n";
