Help language development. Donate to The Perl Foundation

Collection-Raku-Documentation zef:finanalyst last updated on 2023-01-15

use v6.d;
use RakuConfig;
use Collection;
use File::Directory::Tree;
use Collection::RefreshPlugins;

unit module Collection::RakuDoc;


multi sub MAIN('Update') is export {
    say "Updating the Raku Documentation collection in 「~/{ $*CWD.relative($*HOME) }」";

multi sub MAIN('Init') is export {
    say "Initialising a Raku Documentation collection in 「~/{ $*CWD.relative($*HOME) }」";
    exit note qq:to/NOTE/ if + $*CWD.dir;
        The directory 「~/{$*CWD.relative($*HOME)}」 is not empty. Aborting. Try 「Raku-Doc Update」 instead.
    my %config = get-config;
    say qq:to/USE/;
        Raku Documentation Collection has now been initialised.
        The default configuration file "config.raku" for the Collection
        will clone the Raku Documentation repository into 「{ %config<source-obtain> }」
        in this directory. The cloning will only take place on the next use of

        To prevent or change this default, the configuration file "config.raku"
        in this directory must be edited.
        If there is a local version of the Raku Documentation documents,
        point the "source-obtain" and "source-refresh" keys to the correct location.

        Run "Raku-Doc" without options to generate Documentation files.

        Viewing the documentation in the browser requires Cro::WebApp (see README).
        View documentation files in browser at url 'localhost:30000'.

        The README file contains more information about possible options
multi sub MAIN( *% ) {
    exit note 'No config file is present. Please run 「Raku-Doc \'Init\'」 first'
        unless 'config.raku'.IO.f;
    refresh( % );
    collect( % )
multi sub MAIN(Str:D $mode, |c) {
    exit note 'No config file is present. Please run 「Raku-Doc \'Init\'」 first'
        unless 'config.raku'.IO.f;
    collect($mode,  |c)
sub get-site {
    ''.IO.unlink if ''.IO ~~ :e & :f;
    my $rv = run(<
        wget -q
    (exit note 'Could not download Documention Collection files') if $rv.exitcode;
    my $unzip = run( 'unzip', '-ou' , '', :err );
    my $unzip-err = $unzip.err.slurp(:close);
    (exit note("unzip error when unpacking Raku collection files. Error is:" ~ $unzip-err))
        if $unzip-err;