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.180 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.179 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.178 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.177 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.176 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.175 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.174 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.173 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.172 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.171 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.170 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.169 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.167 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.166 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.165 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.164 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.163 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.162 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.161 tracks/perl5/bin/exercise-gen.pl
trackler-2.2.1.160 tracks/perl5/bin/exercise-gen.pl