App-Buuilt-CLI

 view release on metacpan or  search on metacpan

lib/App/Buuilt/CLI.pm  view on Meta::CPAN

                my $dir = dir($directory);

                my $asset = -d $event->path ? dir $event->path : file $event->path;
                my $asset_relative = $asset->relative($assets);

                if ( $event->is_dir ) {

                    if ( $event->is_deleted ) {

                        $self->asset_delete($asset_relative);

                        printf STDERR ( "dir deleted  : %s\n", $asset_relative );
                    }

                } else {

                    if ( $event->is_created ) {

                        $self->asset_put( $asset_relative, $asset );
                        printf STDERR ( "file created :  %s\n", $asset_relative );

                    } elsif ( $event->is_modified ) {

                        $self->asset_put( $asset_relative, $asset );
                        printf STDERR ( "file modified: %s\n", $asset_relative );

                    } elsif ( $event->is_deleted ) {

                        $self->asset_delete($asset_relative);
                        printf STDERR ( "file deleted : %s\n", $asset_relative );
                    }

                }

            }

            # ... process @events ...
        },

        #parse_events => 1,    # Improves efficiency on certain platforms
    );

    # Run unless end
    AnyEvent->condvar->recv;

}

=head2 asset_put

    Put an asset example stylesheets/demo.css
    
=cut

sub asset_put {

    my ( $self, $asset_relative, $asset ) = @_;

    my $config = $self->config();

    my $ua = Mojo::UserAgent->new;
    my $tx = $ua->build_tx( PUT => $config->{host} . '/api/theme/assets/' . $asset_relative => $config );
    $tx->req->content->asset( Mojo::Asset::File->new( path => $asset ) );
    my $txr = $ua->start($tx);

    Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

}

=head2 asset_delete

    Delete an asset, example stylesheet/demo.css

=cut

sub asset_delete {

    my ( $self, $asset_relative ) = @_;

    my $config = $self->config();

    my $ua  = Mojo::UserAgent->new;
    my $tx  = $ua->build_tx( DELETE => $config->{host} . '/api/theme/assets/' . $asset_relative => $config );
    my $txr = $ua->start($tx);

    Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

}

1;
__END__

=encoding utf-8

=head1 NAME

App::Buuilt::CLI - Checkout, watch and upload theme assets for buuilt.it

=head1 SYNOPSIS

    use App::Buuilt::CLI;

=head1 DESCRIPTION

    App::Buuilt::CLI help you edit the assets for a buuilt-theme. You could checkout and watch for changes 


=head1 LICENSE

Copyright (C) Jens Gassmann.

    This library is free software; you can redistribute it and/or modify
    it under the same terms as Perl itself.

=head1 AUTHOR

    Jens Gassmann E<lt>jens.gassmann@atomix.deE<gt>

=cut



( run in 2.168 seconds using v1.01-cache-2.11-cpan-13bb782fe5a )