aboutsummaryrefslogtreecommitdiff
path: root/lib/Dist/Maker/Commands/Add.rakumod
blob: 734d878b7ea942b6d608348fcd8ad7162410893c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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