~mclehman/version-chronologic

9ca18a0368feda2179feedd52c718a4275e0af75 — 0xFORDCOMMA 4 years ago 2173cdf
Make META6.json updates more declarative with some meta magic.
2 files changed, 29 insertions(+), 10 deletions(-)

M META6.json
M bin/ryov
M META6.json => META6.json +1 -1
@@ 14,5 14,5 @@
  "scripts": {
    "test": "zef test ."
  },
  "version": "2020.01.04.4"
  "version": "2020.01.05"
}
\ No newline at end of file

M bin/ryov => bin/ryov +28 -9
@@ 19,18 19,37 @@ multi MAIN('bump', Bool :$breaking = False) {
    meta-dispatch 'bump', :$breaking;
}

sub break-meta6($path) {
class X::Ryov::BadUpdate is Exception {
    method message() {
        "Bad update, both transform and value provided";
    }
}

sub update-meta6($path, $key, :$transform, :$value) {
    my %meta6 = $path.slurp.&from-json;
    %meta6<api>++;
    if $transform.defined and $value.defined {
        X::Ryov::BadUpdate.new.throw;
    }
    if $transform.defined {
        %meta6{$key} = $transform(%meta6{$key});
    }
    if $value.defined {
        %meta6{$key} = $value;
    }
    $path.spurt: to-json %meta6, :sorted-keys;
    say "API version bumped to %meta6<api>";
    return %meta6{$key};
}

sub break-meta6($path) {
    my $res = update-meta6 $path, 'api', transform => { $_ + 1 };
    say "API version bumped to $res";
}

sub bump-meta6($path, Bool :$breaking) {
    my %meta6 = $path.slurp.&from-json;
    my $version = Version::Chronological::Ryov.new: %meta6<version>;
    $version.bump: :$breaking;
    %meta6<version> = $version.Str;
    $path.spurt: to-json %meta6, :sorted-keys;
    say "Bumped to %meta6<version>";
    my $res = update-meta6 $path,
                           'version',
                           transform => {
                               Version::Chronological::Ryov.new($_).bump(:$breaking).Str
                           };
    say "Bumped to $res";
}