aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-02-05 20:49:34 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-02-05 20:49:34 +0100
commit4cc2df337db7376523a2aa941e3cd25b58a07d5f (patch)
treea29fc832a95850f7855a2a2ba84630184c52fef9
parent1cd323319d417acd8cfd22096123fae9aa83945a (diff)
downloadDist::Maker-4cc2df337db7376523a2aa941e3cd25b58a07d5f.tar.gz
Dist::Maker-4cc2df337db7376523a2aa941e3cd25b58a07d5f.tar.bz2
Add support for short licenses in new files
-rw-r--r--lib/Dist/Maker.rakumod4
-rw-r--r--lib/Dist/Maker/Bin.rakumod51
-rw-r--r--lib/Dist/Maker/Config.rakumod21
3 files changed, 64 insertions, 12 deletions
diff --git a/lib/Dist/Maker.rakumod b/lib/Dist/Maker.rakumod
index 1f3e34d..d744d60 100644
--- a/lib/Dist/Maker.rakumod
+++ b/lib/Dist/Maker.rakumod
@@ -10,6 +10,10 @@ unit module Dist::Maker;
my Config $config .= new.read: {
main => {
quiet => False,
+ license-warnings => True,
+ },
+ add => {
+ prepend-license-lines => '',
},
depend => {
zef-install => False,
diff --git a/lib/Dist/Maker/Bin.rakumod b/lib/Dist/Maker/Bin.rakumod
index bef08b6..a14b4fc 100644
--- a/lib/Dist/Maker/Bin.rakumod
+++ b/lib/Dist/Maker/Bin.rakumod
@@ -59,9 +59,42 @@ multi sub MAIN (
my $contents = Str;
my $template = xdg-config-home.add('rdm/templates/provide.raku');
+ my %variables =
+ :%meta,
+ this => {
+ :$provide,
+ },
+ date => {
+ year => DateTime.now.year,
+ }
+ ;
if ($template.f) {
my $body;
+ my $license = xdg-config-home.add("rdm/templates/licenses/{%meta<license>.fc}-short.txt");
+
+ if ($license.f) {
+ my $license-header = Template::Mustache.render(
+ $license.slurp,
+ %variables,
+ ).trim;
+
+ my $prepend = dm-config('add.prepend-license-lines');
+
+ if ($prepend) {
+ $license-header .= lines
+ .map($prepend ~ *)
+ .map(*.trim)
+ .join("\n")
+ ;
+ }
+
+ %variables<license> = $license-header;
+ } else {
+ if (dm-config('main.license-warnings')) {
+ note "No short license template for %meta<license> ($license.absolute())";
+ }
+ }
if ($kind) {
my $kind-template = $template
@@ -71,25 +104,19 @@ multi sub MAIN (
if ($kind-template.f) {
$body = Template::Mustache.render(
$kind-template.slurp,
- {
- :%meta,
- this => {
- :$provide,
- },
- },
+ %variables,
);
} else {
note "No template found at $kind-template.absolute()";
}
}
- $contents = Template::Mustache.render($template.slurp, {
- :%meta,
+ say to-json(%(|%variables, body => 'nani'));
+
+ $contents = Template::Mustache.render($template.slurp, %(
+ |%variables,
body => $body.?trim // '# TODO',
- this => {
- :$provide,
- }
- });
+ ));
}
my $file = dist-maker-add(
diff --git a/lib/Dist/Maker/Config.rakumod b/lib/Dist/Maker/Config.rakumod
index 2359459..6cbc53e 100644
--- a/lib/Dist/Maker/Config.rakumod
+++ b/lib/Dist/Maker/Config.rakumod
@@ -23,6 +23,17 @@ for each command, plus a I<main> for general configuration.
=defn quiet (= False)
When set to C<True>, output of C<Dist::Maker> commands will be reduced.
+=defn license-warnings (= True)
+When enabled, C<Dist::Maker> will show a warning whenever it tries to read a
+license template, but could not find one.
+
+=head3 add
+
+=defn prepend-license-lines (= '')
+When set to a non-empty string, this string will be prepended to all lines of
+the license used when adding a new file. When adding new files, the I<short>
+version of the license will be used.
+
=head3 depend
=defn zef-install (= False)
@@ -96,6 +107,16 @@ This variable contains information on the current object being added.
Currently, this only comes with the C<provide> field, which holds the name of
the new provide unit.
+=head3 licenses
+
+C<Dist::Maker> will use license files if there are templates for them. The
+files must be named after the license key of the module, foldcased, followed by
+either C<-full> or C<-short>, with a C<.txt> extension.
+
+When creating a new module, the C<-full> version will be used to populate the
+C<LICENSE.txt> in a project. When adding a file to an existing project, the
+C<-short> version will be used.
+
=end pod
# vim: ft=raku noet sw=8 ts=8