Skip to content

Commit

Permalink
set a default build dir and auto-create it
Browse files Browse the repository at this point in the history
The most common case does not need to know or care where the build
directory is, because they're using `statocles daemon` to test it.

Additionally, cleaning the directory should always be as simple as `rm
-rf <BUILDDIR>`, which means we should automatically create the build
dir every time.

Fixes #233
Fixes #234
  • Loading branch information
preaction committed Feb 7, 2015
1 parent 1bf5f44 commit 0d9b5b5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
18 changes: 16 additions & 2 deletions lib/Statocles/Site.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,22 @@ also the store the C<daemon> command reads to serve the site.
has build_store => (
is => 'ro',
isa => Store,
required => 1,
coerce => Store->coercion,
default => sub {
my $path = '.statocles-build';
if ( !-d $path ) {
# Automatically make the build directory
mkdir $path;
}
return Store->coercion->( $path );
},
coerce => sub {
my ( $arg ) = @_;
if ( !ref $arg && !-d $arg ) {
# Automatically make the build directory
mkdir $arg;
}
return Store->coercion->( $arg );
},
);

=attr deploy
Expand Down
31 changes: 27 additions & 4 deletions t/site.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,39 @@ use Mojo::URL;
my $SHARE_DIR = path( __DIR__, 'share' );

subtest 'constructor' => sub {
my $cwd = cwd;
my $tmp = tempdir;
chdir $tmp;
mkdir '.statocles-build';

my %required = (
deploy => '.',
);

test_constructor(
'Statocles::Site',
required => {
build_store => '.',
deploy => '.',
},
required => \%required,
default => {
theme => Statocles::Theme->new( store => '::default' ),
build_store => Statocles::Store::File->new( path => '.statocles-build' ),
},
);

chdir $cwd;

subtest 'build dir gets created automatically' => sub {
my $tmp = tempdir;
chdir $tmp;

lives_ok { Statocles::Site->new( %required ) };
ok -d '.statocles-build', 'directory was created';

lives_ok { Statocles::Site->new( build_store => 'builddir', %required ) };
ok -d 'builddir', 'directory was created';

chdir $cwd;
};

};

subtest 'site writes application' => sub {
Expand Down

0 comments on commit 0d9b5b5

Please sign in to comment.