Skip to content

Commit

Permalink
#2: No longer need to be in project root dir to run dest
Browse files Browse the repository at this point in the history
  • Loading branch information
gryphonshafer committed Nov 19, 2015
1 parent 8279470 commit aa1b660
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Revision history for App::Dest

{{$NEXT}}
- Require Perl 5.16 minimum version
- Action scripts can have extensions
- Loads of test coverage improvments, up to >80% now
- Require Perl 5.16 minimum version
- No longer need to be in project root dir to run dest

1.13 2015-09-06 21:00:46-07:00 America/Los_Angeles
- Bug fix for dest.watch adding files to watch list
Expand Down
29 changes: 18 additions & 11 deletions lib/App/Dest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use strict;
use warnings;
use 5.016;

use Cwd 'getcwd';
use File::Basename qw( dirname basename );
use File::Copy::Recursive 'dircopy';
use File::DirCompare ();
Expand Down Expand Up @@ -57,7 +58,7 @@ sub add {
$dir //= '';
$dir =~ s|/$||;

die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();
die "No directory specified; usage: dest add [directory]\n" unless ($dir);
die "Directory specified does not exist\n" unless ( -d $dir );
die "Directory $dir already added\n" if ( grep { $dir eq $_ } $self->_watches );
Expand Down Expand Up @@ -133,8 +134,7 @@ sub list {

sub status {
my ($self) = @_;

die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();

if ( -f 'dest.watch' ) {
my $diff = Text::Diff::diff( '.dest/watch', 'dest.watch' );
Expand Down Expand Up @@ -198,9 +198,8 @@ sub diff {
}

sub update {
my $self = shift;

die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
my $self = shift;
_find_root_dir();

if ( -f 'dest.watch' ) {
my @watches = $self->_watches;
Expand Down Expand Up @@ -258,14 +257,14 @@ sub update {

sub verify {
my ( $self, $path ) = @_;
die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();
return $self->_action( $path, 'verify' );
}

sub deploy {
my ( $self, $name, $redeploy ) = @_;
die "File to deploy required; usage: dest deploy file\n" unless ($name);
die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();
my $rv = $self->_action( $name, 'deploy', $redeploy );
dircopy( $_, ".dest/$_" ) for ( grep { s|/deploy[^/]*$|| } keys %seen_files );
return $rv;
Expand All @@ -274,7 +273,7 @@ sub deploy {
sub revert {
my ( $self, $name ) = @_;
die "File to revert required; usage: dest revert file\n" unless ($name);
die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();
my $rv = $self->_action( ".dest/$name", 'revert' );
rmtree(".dest/$_") for ( map { s|^.dest/||; $_ } grep { s|/revert[^/]*$|| } keys %seen_files );
return $rv;
Expand All @@ -293,7 +292,7 @@ sub revdeploy {

sub clean {
my ($self) = @_;
die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();
for ( $self->_watches ) {
rmtree(".dest/$_");
dircopy( $_, ".dest/$_" );
Expand All @@ -303,7 +302,7 @@ sub clean {

sub preinstall {
my ($self) = @_;
die "Not in project root directory or project not initialized\n" unless ( -d '.dest' );
_find_root_dir();
for ( $self->_watches ) {
rmtree(".dest/$_");
mkdir(".dest/$_");
Expand All @@ -317,6 +316,14 @@ sub watches {
return 0;
}

sub _find_root_dir {
while ( getcwd() ne '/' ) {
return if ( -d '.dest' );
chdir('..');
}
die "Failed to find project root dir; run init in project root dir to resolve\n";
}

sub _watches {
open( my $watch, '<', '.dest/watch' ) or die "Unable to read .dest/watch file\n";
return sort { $a cmp $b } map { chomp; $_ } <$watch>;
Expand Down

0 comments on commit aa1b660

Please sign in to comment.