aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-07-05 16:43:12 +0200
committerPatrick Spek <p.spek@tyil.nl>2020-07-05 16:43:12 +0200
commit0ea6f7e0fb22b93ac977a267fcd21ec9f4bfca05 (patch)
tree1688e49382f16dfca44bf82956e0b74bd4baf3f3
parent437e2c914ebcb33490883452cb41504bda460be2 (diff)
downloadDist::Maker-0ea6f7e0fb22b93ac977a267fcd21ec9f4bfca05.tar.gz
Dist::Maker-0ea6f7e0fb22b93ac977a267fcd21ec9f4bfca05.tar.bz2
Add dist command
-rw-r--r--META6.json2
-rw-r--r--lib/App/Rakumod.rakumod3
-rw-r--r--lib/App/Rakumod/Bin.rakumod67
-rw-r--r--lib/X/App/Rakumod/MissingBinDep.rakumod40
-rw-r--r--lib/X/App/Rakumod/MissingDistFile.rakumod29
5 files changed, 141 insertions, 0 deletions
diff --git a/META6.json b/META6.json
index 3a7d4c7..ab4246a 100644
--- a/META6.json
+++ b/META6.json
@@ -26,6 +26,8 @@
"X::App::Rakumod::Clobber": "lib/X/App/Rakumod/Clobber.rakumod",
"X::App::Rakumod::DuplicateDependency": "lib/X/App/Rakumod/DuplicateDependency.rakumod",
"X::App::Rakumod::DuplicateProvide": "lib/X/App/Rakumod/DuplicateProvide.rakumod",
+ "X::App::Rakumod::MissingBinDep": "lib/X/App/Rakumod/MissingBinDep.rakumod",
+ "X::App::Rakumod::MissingDistFile": "lib/X/App/Rakumod/MissingDistFile.rakumod",
"X::App::Rakumod::MissingTemplate": "lib/X/App/Rakumod/MissingTemplate.rakumod",
"X::App::Rakumod::NoDistribution": "lib/X/App/Rakumod/NoDistribution.rakumod",
"rakumod": "bin/rakumod"
diff --git a/lib/App/Rakumod.rakumod b/lib/App/Rakumod.rakumod
index d0e520d..9bc2cbb 100644
--- a/lib/App/Rakumod.rakumod
+++ b/lib/App/Rakumod.rakumod
@@ -37,6 +37,9 @@ sub rakumod-cli-init (
depend => {
zef-install => False,
},
+ dist => {
+ directory => xdg-data-home().add('rakumod/dist'),
+ },
new => {
path => $*HOME,
},
diff --git a/lib/App/Rakumod/Bin.rakumod b/lib/App/Rakumod/Bin.rakumod
index 4bc86ef..98133e9 100644
--- a/lib/App/Rakumod/Bin.rakumod
+++ b/lib/App/Rakumod/Bin.rakumod
@@ -2,6 +2,7 @@
use v6.d;
+use File::Which;
use IO::Path::XDG;
use JSON::Fast;
use Log;
@@ -16,6 +17,8 @@ use App::Rakumod;
use X::App::Rakumod::Clobber;
use X::App::Rakumod::DuplicateDependency;
use X::App::Rakumod::DuplicateProvide;
+use X::App::Rakumod::MissingBinDep;
+use X::App::Rakumod::MissingDistFile;
use X::App::Rakumod::NoDistribution;
unit module App::Rakumod::Bin;
@@ -174,6 +177,70 @@ multi sub MAIN (
}
}
+#| Create a distributable archive of a module.
+multi sub MAIN (
+ 'dist',
+) is export {
+ CATCH {
+ when App::Rakumod::Exception {
+ note $_.message;
+ exit $_.code;
+ }
+ }
+
+ rakumod-cli-init;
+
+ .debug('Checking for tar') with $Log::instance;
+
+ my $tar = which('tar');
+
+ X::App::Rakumod::MissingBinDep.new(dep => 'tar').throw unless $tar;
+
+ my $meta-file = rakumod-scour('META6.json', $*CWD);
+ my %meta = from-json($meta-file.slurp);
+ my $distname = %meta<name>.subst('::', '-', :g) ~ '-' ~ %meta<version>;
+ my $output = $App::Rakumod::config.get('dist.directory').add("$distname.tar.gz");
+ my @files = (
+ |%meta<provides>.values,
+ |%meta<resources>.map({ "resources/$_" }),
+ 'META6.json',
+ 'LICENSE.txt',
+ 'README.rakudoc',
+ );
+
+ # Ensure all files actually exist
+ for @files -> $file {
+ .notice("Including $file in $distname") with $Log::instance;
+
+ next if $file.IO.f;
+
+ X::App::Rakumod::MissingDistFile.new(file => $file.IO).throw;
+ }
+
+ # Ensure the output directory exists
+ if (!$output.parent.d) {
+ .notice("Creating dist directory at {$output.parent}") with $Log::instance;
+ $output.parent.mkdir;
+ }
+
+ my @cmd = «
+ "$tar"
+ -c
+ -f "$output"
+ --transform "s/^./$distname/"
+ --owner=0
+ --group=0
+ --numeric-owner
+ {@files.map({ "./$_" }).sort}
+ »;
+
+ .debug('> ' ~ @cmd.join(' ')) with $Log::instance;
+
+ run(@cmd);
+
+ say "Dist created of {%meta<name>}:ver<{%meta<version>}> at {$output.absolute}";
+}
+
#| Create a new module skeleton.
multi sub MAIN (
'new',
diff --git a/lib/X/App/Rakumod/MissingBinDep.rakumod b/lib/X/App/Rakumod/MissingBinDep.rakumod
new file mode 100644
index 0000000..d5bed08
--- /dev/null
+++ b/lib/X/App/Rakumod/MissingBinDep.rakumod
@@ -0,0 +1,40 @@
+#!/usr/bin/env false
+
+use v6.d;
+
+use App::Rakumod::Exception;
+
+unit class X::App::Rakumod::MissingBinDep does App::Rakumod::Exception;
+
+has $.dep;
+
+method code () { 7 }
+
+method message () {
+ "Could not find $!dep in your \$PATH. Please install this program using your distribution's package manager."
+}
+
+=begin pod
+
+=NAME X::App::Rakumod::MissingBinDep
+=VERSION 0.0.0
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+
+=begin LICENSE
+Copyright © 2020
+
+This program is free software: you can redistribute it and/or modify it under
+the terms of the GNU Affero General Public License as published by the Free
+Software Foundation, version 3.
+
+This program is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License along
+with this program. If not, see &lt;https://www.gnu.org/licenses/&gt;
+=end LICENSE
+
+=end pod
+
+# vim: ft=raku noet sw=8 ts=8
diff --git a/lib/X/App/Rakumod/MissingDistFile.rakumod b/lib/X/App/Rakumod/MissingDistFile.rakumod
new file mode 100644
index 0000000..d99585a
--- /dev/null
+++ b/lib/X/App/Rakumod/MissingDistFile.rakumod
@@ -0,0 +1,29 @@
+#! /usr/bin/env false
+
+use v6.d;
+
+use App::Rakumod::Exception;
+
+unit class X::App::Rakumod::MissingDistFile does App::Rakumod::Exception;
+
+has IO::Path $.file;
+
+method code () { 8 }
+
+method message () {
+ "A file that should be included in your module's distribution is missing: $!file.absolute()"
+}
+
+=begin pod
+
+=NAME X::App::Rakumod::MissingDistFile
+=VERSION 0.0.0
+=AUTHOR Patrick Spek <p.spek@tyil.work>
+
+=begin LICENSE
+
+=end LICENSE
+
+=end pod
+
+# vim: ft=raku noet sw=8 ts=8