diff options
Diffstat (limited to 'lib/Dist/Maker/Bin.rakumod')
-rw-r--r-- | lib/Dist/Maker/Bin.rakumod | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/lib/Dist/Maker/Bin.rakumod b/lib/Dist/Maker/Bin.rakumod index 30c2211..bef08b6 100644 --- a/lib/Dist/Maker/Bin.rakumod +++ b/lib/Dist/Maker/Bin.rakumod @@ -2,8 +2,11 @@ use v6.d; +use IO::Path::XDG; use JSON::Fast; +use Template::Mustache; +use Dist::Maker::Commands::Add; use Dist::Maker::Commands::Depend; use Dist::Maker::Commands::New; use Dist::Maker::Exception; @@ -11,16 +14,102 @@ use Dist::Maker::Util; use Dist::Maker; use X::Dist::Maker::Clobber; use X::Dist::Maker::DuplicateDependency; +use X::Dist::Maker::DuplicateProvide; use X::Dist::Maker::NoDistribution; unit module Dist::Maker::Bin; -#| Add a dependency. +#| Add a new file. +multi sub MAIN ( + 'add', + + #| The name of the new unit. + Str $provide is copy = Str, + + #| The kind of provide to create. See Dist::Maker::Commands::Add for + #| more information. + Str :$kind = Str, +) is export { + CATCH { + when Dist::Maker::Exception { + note $_.message; + exit $_.code; + } + } + + dm-config-load; + + my $meta-file = dm-scour('META6.json', $*CWD); + + if (!$meta-file) { + X::Dist::Maker::NoDistribution.new( + path => $*CWD, + ).throw + } + + my %meta = from-json($meta-file.slurp); + + if (!$provide) { $provide = dm-prompt('Unit name') } + + if (%meta<provides>.keys ∋ $provide) { + X::Dist::Maker::DuplicateProvide.new( + :$provide, + ).throw + } + + my $contents = Str; + my $template = xdg-config-home.add('rdm/templates/provide.raku'); + + if ($template.f) { + my $body; + + if ($kind) { + my $kind-template = $template + .parent + .add("kinds/$kind.raku"); + + if ($kind-template.f) { + $body = Template::Mustache.render( + $kind-template.slurp, + { + :%meta, + this => { + :$provide, + }, + }, + ); + } else { + note "No template found at $kind-template.absolute()"; + } + } + + $contents = Template::Mustache.render($template.slurp, { + :%meta, + body => $body.?trim // '# TODO', + this => { + :$provide, + } + }); + } + + my $file = dist-maker-add( + $provide, + $meta-file, + :$contents, + :!sanity-checks + ); + + if (!dm-config('main.quiet')) { + say "Added $file to provide $provide for %meta<name>"; + } +} + +#| Add a module to depend on. multi sub MAIN ( 'depend', - #| The module to add to the dependencies. - Str $module, + #| The name of the module. + Str $module is copy = Str, ) is export { CATCH { when Dist::Maker::Exception { @@ -43,7 +132,7 @@ multi sub MAIN ( if (!$module) { $module = dm-prompt('Dependency name'); } - if (%meta<depends> (cont) $module) { + if (%meta<depends> ∋ $module) { X::Dist::Maker::DuplicateDependency.new( :$module ).throw |