forked from haarg/wgdev
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exports asset tree to file tree
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package WGDev::Command::Snapshot; | ||
use strict; | ||
use warnings; | ||
use 5.008008; | ||
|
||
our $VERSION = '0.2.0'; | ||
|
||
use WGDev::Command::Base; | ||
use Carp; | ||
BEGIN { our @ISA = qw(WGDev::Command::Base) } | ||
|
||
use WGDev::X (); | ||
|
||
sub config_options { | ||
return qw( | ||
to=s | ||
); | ||
} | ||
|
||
sub process { | ||
my $self = shift; | ||
|
||
require Cwd; | ||
require File::Spec; | ||
require File::Path; | ||
require File::Slurp::Tree; | ||
|
||
my $to = $self->option('to') || Cwd::getcwd; | ||
print "Writing to: $to\n"; | ||
File::Path::make_path("$to"); | ||
require Encode; | ||
for my $asset_spec ( $self->arguments ? $self->arguments : 'root' ) { | ||
my $asset = eval { $self->wgd->asset->find($asset_spec) }; | ||
if ( !$asset ) { | ||
warn $@; | ||
next; | ||
} | ||
my %tree; | ||
my $assets = $asset->getLineageIterator(['self', 'descendants']); | ||
while ( my $asset = $assets->() ) { | ||
my $url = $asset->get('url'); | ||
File::Path::make_path("$to/$url"); | ||
$tree{"${url}_"} = Encode::encode('utf8', $self->wgd->asset->serialize($asset)); | ||
} | ||
File::Slurp::Tree::spew_tree( $to => \%tree ); | ||
} | ||
return 1; | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 NAME | ||
WGDev::Command::Snapshot - Snapshots asset tree to a file tree | ||
=head1 SYNOPSIS | ||
wgd snapshot [--to dir] <asset> [<asset> ...] | ||
=head1 DESCRIPTION | ||
Snapshots asset tree to file tree. | ||
=head1 OPTIONS | ||
=over 8 | ||
=item C<--to> | ||
Target directory (defaults to current directory). | ||
=item C<< <asset> >> | ||
Either an asset URL, ID, class name. As many can be specified as desired. | ||
=back | ||
=head1 AUTHOR | ||
Patrick Donelan <pat@patspam.com> | ||
=head1 LICENSE | ||
Copyright (c) Patrick Donelan. | ||
This library is free software; you can redistribute it and/or modify it under | ||
the same terms as Perl itself. | ||
=cut | ||