#!/usr/bin/perl
# vim: syn=perl

use strict;
use Getopt::Long;
use Pod::Usage;

sub xsystem {
    system @_;
    die "@_ failed" if $? != 0;
}

my $help;
my $file_types = "css|js|gif|png|jpg|jpeg";
@ARGV and GetOptions(
    "help" => \$help,
    "file-types:s" => \$file_types,
) or pod2usage(1);
pod2usage(-verbose => 2, -exitval => 2) if $help;

my $project = $ARGV[0];

xsystem("ttree -f '' --define PROJECT='$project' --define FILE_TYPES='$file_types' -s /usr/share/yandex-dh-make-ystatic/debian.tt2 -d yandex-static/debian");
xsystem("chmod a+x yandex-static/debian/install.pl yandex-static/debian/rules");
xsystem("cd yandex-static && EDITOR='vim -e -s -c :wq' dch --create --package=yandex-static-$project --distribution=stable -v 1.0.0");

__END__

=head1 NAME

    dh-make-ystatic - Script to Debianize static files for use on static.yandex.net. Use in project root folder.

=head1 SYNOPSIS

    dh-make-ystatic [options] <project>

=head1 OPTIONS

    project       Specify a project id, recommend use lego:id. Required parameter.

    --file-types  Specify file types in pipe-separated format. Default value 'css|js|gif|png|jpg|jpeg'.

    --help        Show help message.

=head1 EXAMPLE

    dh-make-ystatic --project=video --file-types='css|js|gif|png|jpg|jpeg|swf'

=cut

