Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Build script now successfully builds db and restarts app
  • Loading branch information
zoffixznet committed Nov 12, 2015
1 parent 4103b34 commit 6a05e9e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -15,4 +15,6 @@ mojo-app/public/sass/.sass-cache/
mojo-app/public/sass/cerulean.scss
mojo-app/public/sass/cerulean/
mojo-app/public/packed/
mojo-app/modulesperl6.db
mojo-app/modulesperl6.db
mojo-app/bin/hypnotoad.pid
mojo-app/secrets
17 changes: 12 additions & 5 deletions mojo-app/lib/ModulesPerl6.pm
@@ -1,10 +1,11 @@
package ModulesPerl6;

# TODO: figure out where to secretly store secrets file on the final server
use constant SECRETS_FILE => '/tmp/secrets';
use constant SECRETS_FILE => 'secrets';

use Mojo::Base 'Mojolicious';

use File::Spec::Functions qw/catfile/;
use Mojo::Util qw/slurp/;
use ModulesPerl6::Model::Dists;
use ModulesPerl6::Model::BuildStats;
Expand All @@ -15,13 +16,17 @@ sub startup {
# SETUP
$self->config(hypnotoad => {listen => ['http://*:3333']});
$self->moniker('ModulesPerl6');

my $secrets_file = -r SECRETS_FILE
? SECRETS_FILE : catfile qw/.. web github-token/;

$self->secrets([
-r SECRETS_FILE ? slurp SECRETS_FILE : 'Perl 6 is awesome!'
-r $secrets_file ? slurp $secrets_file : 'Perl 6 is awesome!'
]);

# ASSETS
$self->plugin(bootstrap3 =>
theme => { cerulean => 'https://bootswatch.com/cerulean/_bootswatch.scss' }
$self->plugin(bootstrap3 => theme =>
{ cerulean => 'https://bootswatch.com/cerulean/_bootswatch.scss' }
);
$self->asset('app.css' => '/sass/main.scss');
$self->asset('app.js' => '/js/main.js' );
Expand All @@ -47,7 +52,9 @@ sub startup {
$r->get('/dist/:dist')->to('root#dist')->name('dist');
$r->get('/kwalitee/:dist')->to('root#kwalitee')->name('kwalitee');

$r->any('/NIY')->to('root#NIY')->name('NIY');
$r->any('/not_implemented_yet')
->to('root#not_implemented_yet')
->name('not_implemented_yet');
}

1;
Expand Down
8 changes: 4 additions & 4 deletions mojo-app/lib/ModulesPerl6/Controller/Root.pm
Expand Up @@ -16,7 +16,7 @@ sub index {
# TODO: fix the model so we don't need to make 2 calls to ->find
%found_dists = map +( "$_->{name}\0$_->{author_id}" => 1 ),
$self->dists->find({ name => \$q })->each,
$self->dists->find({ description => \$q })->each;;
$self->dists->find({ description => \$q })->each;
}

for ( @$dists ) {
Expand All @@ -28,7 +28,7 @@ sub index {

$self->stash(
dists => $dists,
$self->build_stats->stats(qw/dists_num last_updated/)->%*
$self->build_stats->stats(qw/dists_num last_updated/)->%*,
);
}

Expand All @@ -44,10 +44,10 @@ sub dist {
}

sub kwalitee {
shift->redirect_to('NIY');
shift->redirect_to('not_implemented_yet');
}

sub NIY {
sub not_implemented_yet {
shift->render( text => 'Not Implemented Yet' );
}
1;
2 changes: 1 addition & 1 deletion mojo-app/lib/ModulesPerl6/Model/Dists.pm
Expand Up @@ -45,7 +45,7 @@ sub add {
$dist->{travis_status} ||= 'not setup';
$dist->{date_updated} ||= 0;
$dist->{date_added} ||= 0;
$dist->{kwalitee} = ModulesPerl6::Metrics::Kwalitee->new->kwalitee({
$dist->{kwalitee} //= ModulesPerl6::Metrics::Kwalitee->new->kwalitee({
map +( $_ => $dist->{$_} ),
qw/has_readme panda has_tests travis/,
});
Expand Down
22 changes: 15 additions & 7 deletions web/lib/P6Project.pm
Expand Up @@ -6,6 +6,7 @@ use 5.010;

use lib '../mojo-app/lib';
use ModulesPerl6::Model::Dists;
use ModulesPerl6::Model::BuildStats;
use constant DB_FILE => 'modulesperl6.db';

#We need ::SSL for Mojo::UserAgent, which is too shy about reporting it missing
Expand All @@ -21,7 +22,7 @@ use P6Project::HTML;
use P6Project::SpriteMaker;
use JSON;
use File::Slurp;
use File::Copy qw/copy/;
use File::Copy qw/move/;
use Time::Moment;

sub new {
Expand Down Expand Up @@ -160,32 +161,39 @@ sub write_dist_db {

{ # let model go out of scope, so the db file gets finished off
unlink DB_FILE;
my $m = ModulesPerl6::Model::Dists->new( db_file => DB_FILE );
my $m = ModulesPerl6::Model::Dists->new( db_file => DB_FILE )->deploy;
$m->add(
map +{
name => $_->{name},
url => $_->{url},
description => $_->{description},
author => $_->{auth},
author_id => $_->{auth},
logo => $_->{logo_sprite},
has_readme => $_->{badge_has_readme} ? 1 : 0,
panda => $_->{badge_panda}
? 2 : $_->{badge_panda_nos11} : 1 : 0,
? 2 : $_->{badge_panda_nos11} ? 1 : 0,
has_tests => $_->{badge_has_tests},
travis => $_->{travis_status},
travis_status=> $_->{travis_status},
stars => $_->{stargazers},
issues => $_->{open_issues},
date_updated => eval {
Time::Moment->from_string($_->{last_updated_full})
->epoch
} // 0,
date_added => Time::Moment->now->epoch,
# to be fixed to proper date_added date
# TODO: fix to proper date_added date
}, sort_by { $_->{name} } values %{ $self->projects }
);
}

move DB_FILE, catfile $self->{output_dir}, DB_FILE;
ModulesPerl6::Model::BuildStats->new( db_file => DB_FILE )->deploy->update(
dists_num => scalar(keys %{ $self->projects }),
last_updated => time(),
);

move DB_FILE, catfile $self->{output_dir}, '..', 'mojo-app', DB_FILE;
system hypnotoad => catfile $self->{output_dir},
qw/.. mojo-app bin ModulesPerl6.pl/;

$self;
}
Expand Down

0 comments on commit 6a05e9e

Please sign in to comment.