Sha256: b265b527eef1b164ba8170d86d46bf651bd2418858cecafce1b3d68c1f2c4a26

Contents?: true

Size: 1.65 KB

Versions: 73

Compression:

Stored size: 1.65 KB

Contents

#!/usr/bin/env perl
use feature qw(lexical_subs say);
use YAML 'LoadFile';
use Path::Tiny qw(:DEFAULT cwd);
use FindBin;
use lib "$FindBin::Bin/../lib";
use Exercism::Generator;

my $base_dir = path(__FILE__)->realpath->parent->parent;

my @exercises;

if (@ARGV) {
  if ($ARGV[0] eq '--all') {
    push @exercises, $_->basename foreach $base_dir->child('exercises')->children;
  } else {
    @exercises = @ARGV;
  }
} else {
  say 'No args given; working in current directory.';
  if ( path('.meta/exercise-data.yaml')->is_file ) {
    push @exercises, cwd->basename;
  } else {
    say '.meta/exercise-data.yaml not found in current directory; exiting.';
    exit;
  }
}

my @dir_not_found;
my @yaml_not_found;
for my $exercise (@exercises) {
  my $exercise_dir = $base_dir->child("exercises/$exercise");
  my $yaml = $exercise_dir->child('.meta/exercise-data.yaml');

  unless ($exercise_dir->is_dir) {
    push @dir_not_found, $exercise;
    next;
  }
  unless ($yaml->is_file) {
    push @yaml_not_found, $exercise;
    next;
  }
  print "Generating $exercise... ";

  my $data = LoadFile $yaml;
  my $generator = Exercism::Generator->new({exercise => $exercise, data => $data});
  $exercise_dir->child("$exercise.t")->spew($generator->test);
  $exercise_dir->child("$exercise.t")->chmod(0755);
  $exercise_dir->child('.meta/solutions/'.$data->{exercise}.'.pm')->spew($generator->example);
  $exercise_dir->child($data->{exercise}.'.pm')->spew($generator->stub);

  say 'Generated.';
}

if (@dir_not_found)  {warn 'exercise directory does not exist for: ' . join ' ', @dir_not_found}
if (@yaml_not_found) {warn '.meta/exercise-data.yaml not found for: ' . join ' ', @yaml_not_found}

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.138 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.137 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.136 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.135 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.134 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.133 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.132 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.131 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.130 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.129 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.128 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.127 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.126 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.125 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.124 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.123 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.122 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.121 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.120 tracks/perl5/bin/exercise-gen.pl