aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-02-05 10:10:46 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-02-05 10:10:46 +0100
commit8737fed602222ac9ab376e76318bbe306396e2e4 (patch)
treec6efb2a3b2d9850b8496c3b03e95fc6a6bf9ceb9
parent375d2542f61a1fdcf4b4e2690ee17b4c178f2d95 (diff)
downloadDist::Maker-8737fed602222ac9ab376e76318bbe306396e2e4.tar.gz
Dist::Maker-8737fed602222ac9ab376e76318bbe306396e2e4.tar.bz2
Add depend command
-rw-r--r--META6.json7
-rw-r--r--lib/Dist/Maker.rakumod8
-rw-r--r--lib/Dist/Maker/Bin.rakumod59
-rw-r--r--lib/Dist/Maker/Commands/Depend.rakumod44
-rw-r--r--lib/Dist/Maker/Util.rakumod15
-rw-r--r--lib/X/Dist/Maker/DuplicateDependency.rakumod33
-rw-r--r--lib/X/Dist/Maker/NoDistribution.rakumod33
7 files changed, 195 insertions, 4 deletions
diff --git a/META6.json b/META6.json
index 577451c..d48bafd 100644
--- a/META6.json
+++ b/META6.json
@@ -5,7 +5,9 @@
],
"depends": [
"Config",
- "IO::Path::XDG"
+ "IO::Path::XDG",
+ "JSON::Fast",
+ "Template::Mustache"
],
"description": "Easily develop Raku modules",
"license": "AGPL-3.0",
@@ -15,10 +17,13 @@
"provides": {
"Dist::Maker": "lib/Dist/Maker.rakumod",
"Dist::Maker::Bin": "lib/Dist/Maker/Bin.rakumod",
+ "Dist::Maker::Commands::Depend": "lib/Dist/Maker/Commands/Depend.rakumod",
"Dist::Maker::Commands::New": "lib/Dist/Maker/Commands/New.rakumod",
"Dist::Maker::Exception": "lib/Dist/Maker/Exception.rakumod",
"Dist::Maker::Util": "lib/Dist/Maker/Util.rakumod",
"X::Dist::Maker::Clobber": "lib/X/Dist/Maker/Clobber.rakumod",
+ "X::Dist::Maker::DuplicateDependency": "lib/X/Dist/Maker/DuplicateDependency.pm6",
+ "X::Dist::Maker::NoDistribution": "lib/X/Dist/Maker/NoDistribution.pm6",
"rdm": "bin/rdm"
},
"resources": [
diff --git a/lib/Dist/Maker.rakumod b/lib/Dist/Maker.rakumod
index a4a0312..b917f48 100644
--- a/lib/Dist/Maker.rakumod
+++ b/lib/Dist/Maker.rakumod
@@ -8,9 +8,15 @@ use IO::Path::XDG;
unit module Dist::Maker;
my Config $config .= new.read: {
+ main => {
+ quiet => False,
+ },
+ depend => {
+ zef-install => False,
+ },
new => {
path => $*HOME,
- }
+ },
};
sub dm-config-load () is export
diff --git a/lib/Dist/Maker/Bin.rakumod b/lib/Dist/Maker/Bin.rakumod
index 9974f37..61175cd 100644
--- a/lib/Dist/Maker/Bin.rakumod
+++ b/lib/Dist/Maker/Bin.rakumod
@@ -2,13 +2,66 @@
use v6.d;
+use JSON::Fast;
+
+use Dist::Maker::Commands::Depend;
use Dist::Maker::Commands::New;
use Dist::Maker::Exception;
use Dist::Maker::Util;
use Dist::Maker;
+use X::Dist::Maker::Clobber;
+use X::Dist::Maker::DuplicateDependency;
+use X::Dist::Maker::NoDistribution;
unit module Dist::Maker::Bin;
+multi sub MAIN (
+ 'depend',
+
+ #| The module to add to the dependencies.
+ Str $module,
+) 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 (!$module) { $module = dm-prompt('Dependency name'); }
+
+ if (%meta<depends> (cont) $module) {
+ X::Dist::Maker::DuplicateDependency.new(
+ :$module
+ ).throw
+ }
+
+ dist-maker-depend(
+ $module,
+ $meta-file,
+ );
+
+ if (!dm-config('main.quiet')) {
+ say "Added $module as dependency for %meta<name>";
+ }
+
+ if (dm-config('depend.zef-install')) {
+ run << zef install "$module" >>;
+ }
+}
+
#| Create a new module skeleton.
multi sub MAIN (
'new',
@@ -34,7 +87,7 @@ multi sub MAIN (
my $destination = $path.IO.add($name);
if ($destination.e) {
- ClobberException.new(
+ X::Dist::Maker::Clobber.new(
path => $destination.absolute,
).throw;
}
@@ -49,7 +102,9 @@ multi sub MAIN (
$path.IO,
);
- say "Created skeleton for $name at $destination";
+ if (!dm-config('main.quiet')) {
+ say "Created skeleton for $name at $destination";
+ }
}
=begin pod
diff --git a/lib/Dist/Maker/Commands/Depend.rakumod b/lib/Dist/Maker/Commands/Depend.rakumod
new file mode 100644
index 0000000..78bb5eb
--- /dev/null
+++ b/lib/Dist/Maker/Commands/Depend.rakumod
@@ -0,0 +1,44 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use JSON::Fast;
+
+use X::Dist::Maker::DuplicateDependency;
+
+unit module Dist::Maker::Commands::Depend;
+
+sub dist-maker-depend (
+ Str:D $module,
+ IO::Path:D $meta-json,
+) is export {
+ my %meta = $meta-json.slurp.&from-json;
+
+ if (%meta<depends> (cont) $module) {
+ X::Dist::Maker::DuplicateDependency.new(
+ :$module
+ ).throw
+ }
+
+ %meta<depends>.append($module);
+
+ $meta-json.spurt(%meta.&to-json(:sorted-keys) ~ "\n");
+}
+
+=begin pod
+
+=NAME Dist::Maker::Commands::Depend
+=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
diff --git a/lib/Dist/Maker/Util.rakumod b/lib/Dist/Maker/Util.rakumod
index 94f7adb..c463752 100644
--- a/lib/Dist/Maker/Util.rakumod
+++ b/lib/Dist/Maker/Util.rakumod
@@ -22,6 +22,21 @@ sub dm-prompt (
}
}
+#| Scour a directory upwards for a certain filename
+sub dm-scour (
+ Str:D $filename,
+ IO::Path:D $directory,
+ --> IO::Path
+) is export {
+ with ($directory.add($filename)) {
+ return $_ if $_.f;
+ }
+
+ return IO::Path if $directory.absolute eq '/';
+
+ samewith($filename, $directory.parent);
+}
+
=begin pod
=NAME Dist::Maker::Util
diff --git a/lib/X/Dist/Maker/DuplicateDependency.rakumod b/lib/X/Dist/Maker/DuplicateDependency.rakumod
new file mode 100644
index 0000000..7f7e2e3
--- /dev/null
+++ b/lib/X/Dist/Maker/DuplicateDependency.rakumod
@@ -0,0 +1,33 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use Dist::Maker::Exception;
+
+unit class X::Dist::Maker::DuplicateDependency does Dist::Maker::Exception;
+
+has $.module;
+
+method code () { 5 }
+
+method message () {
+ "$!module is already a dependency."
+}
+
+=begin pod
+
+=NAME X::Dist::Maker::DuplicateDependency
+=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
diff --git a/lib/X/Dist/Maker/NoDistribution.rakumod b/lib/X/Dist/Maker/NoDistribution.rakumod
new file mode 100644
index 0000000..f0083c3
--- /dev/null
+++ b/lib/X/Dist/Maker/NoDistribution.rakumod
@@ -0,0 +1,33 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use Dist::Maker::Exception;
+
+unit class X::Dist::Maker::NoDistribution does Dist::Maker::Exception;
+
+has $.path;
+
+method code () { 4 }
+
+method message () {
+ "$!path does not seem to contain a Raku module."
+}
+
+=begin pod
+
+=NAME X::Dist::Maker::NoDistribution
+=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