aboutsummaryrefslogtreecommitdiff
path: root/lib/Dist/Maker/Commands/Add.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Dist/Maker/Commands/Add.rakumod')
-rw-r--r--lib/Dist/Maker/Commands/Add.rakumod54
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/Dist/Maker/Commands/Add.rakumod b/lib/Dist/Maker/Commands/Add.rakumod
new file mode 100644
index 0000000..734d878
--- /dev/null
+++ b/lib/Dist/Maker/Commands/Add.rakumod
@@ -0,0 +1,54 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use JSON::Fast;
+
+unit module Dist::Maker::Commands::Add;
+
+sub dist-maker-add (
+ Str:D $provide,
+ IO::Path:D $meta-json,
+ Str :$contents,
+ Bool:D :$sanity-checks = True,
+ --> IO::Path
+) is export {
+ my %meta = $meta-json.slurp.&from-json;
+
+ if (%meta<provides>.keys ∋ $provide) {
+ X::Dist::Maker::DuplicateProvide.new(
+ :$provide,
+ ).throw
+ }
+
+ my $provide-file = $meta-json
+ .parent
+ .add("lib/{$provide.subst('::', '/', :g)}.rakumod")
+ ;
+
+ $provide-file.parent.mkdir;
+ $provide-file.spurt($contents // '');
+
+ %meta<provides>{$provide} = $provide-file.relative($meta-json.parent);
+ $meta-json.spurt(to-json(%meta, :sorted-keys) ~ "\n");
+
+ $provide-file;
+}
+
+=begin pod
+
+=NAME Dist::Maker::Commands::Add
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+=VERSION 0.0.0
+
+=head1 Synopsis
+
+=head1 Description
+
+=head1 Examples
+
+=head1 See also
+
+=end pod
+
+# vim: ft=perl6 noet