R/Makefile.R

Defines functions create_Makefile

Documented in create_Makefile

##' Create a Makefile in each chapter of the report
##'
##' @return invisible NULL
##' @importFrom git2r repository
##' @importFrom git2r add
##' @export
create_Makefile <- function() {
    cat(sprintf("Makefile: %s\n", basename(getwd())))

    if (in_chapter()) {
        lines <- c(".PHONY: pdf",
                   "pdf:",
                   "\tRscript -e \"mill::to_pdf()\"",
                   "",
                   ".PHONY: import",
                   "import:",
                   paste0("\tRscript -e \"mill::import(); ",
                          "mill::from_docx(git2r::repository()); ",
                          "git2r::status()\""),
                   "",
                   ".PHONY: check",
                   "check:",
                   "\tRscript -e \"mill::check()\"",
                   "",
                   ".PHONY: harvest_dry_run",
                   "harvest_dry_run:",
                   "\tRscript ../../assets/harvest-workspace.R FALSE",
                   "",
                   ".PHONY: harvest",
                   "harvest:",
                   "\tRscript ../../assets/harvest-workspace.R TRUE",
                   "",
                   ".PHONY: clear-checks",
                   "clear-checks:",
                   "\tRscript -e \"mill::clear_checks()\"",
                   "",
                   ".PHONY: spell_check",
                   "spell_check:",
                   "\tRscript -e \"mill::spell_checking()\"",
                   "",
                   ".PHONY: diff",
                   "diff:",
                   "\tRscript -e \"mill::create_patch()\"",
                   "",
                   ".PHONY: patch",
                   "patch:",
                   "\tRscript -e \"mill::apply_patch()\"",
                   "",
                   ".PHONY: patch_force",
                   "patch_force:",
                   "\tRscript -e \"mill::apply_patch(force = TRUE)\"",
                   "",
                   ".PHONY: build_figures",
                   "build_figures:",
                   "\tRscript \\",
                   "\t    -e \"mill::build_figures()\" \\",
                   "\t    -e \"warnings()\" \\",
                   "\t    -e \"git2r::status()\"",
                   "",
                   ".PHONY: makefile",
                   "makefile:",
                   "\tRscript -e \"mill::create_Makefile()\"",
                   "",
                   ".PHONY: clean",
                   "clean:",
                   "\tRscript -e \"mill::cleanup()\"")

        writeLines(lines, "Makefile")
        add(repository("../.."),
            paste0("chapters/", basename(getwd()), "/Makefile"))
    } else if (in_report()) {
        lines <- c(".PHONY: all",
                   "all: standard",
                   "",
                   ".PHONY: web",
                   "web:",
                   "\tRscript -e \"mill::to_pdf(web = TRUE)\"",
                   "",
                   ".PHONY: printer",
                   "printer:",
                   "\tcd assets/new-cover/;make",
                   "\t# Rscript bleed.R",
                   "\tcp assets/new-cover/cover.pdf cover.pdf",
                   "\t# cp build/bleeding_report.pdf report_printer.pdf",
                   "\tpdftk build/report.pdf cat 3-126 output print.pdf",
                   "\tcd assets/new-cover/;make clean",
                   "",
                   ".PHONY: standard",
                   "standard:",
                   "\tRscript -e 'mill::to_pdf()'",
                   "",
                   ".PHONY: check",
                   "check:",
                   "\tRscript -e \"mill::check()\"",
                   "",
                   ".PHONY: clear-checks",
                   "clear-checks:",
                   "\tRscript -e \"mill::clear_checks()\"",
                   "",
                   ".PHONY: harvest_dry_run",
                   "harvest_dry_run:",
                   "\tRscript assets/harvest-workspace.R FALSE",
                   "",
                   ".PHONY: harvest",
                   "harvest:",
                   "\tRscript assets/harvest-workspace.R TRUE",
                   "",
                   ".PHONY: import",
                   "import:",
                   paste0("\tRscript -e \"mill::import(); ",
                          "mill::from_docx(git2r::repository()); ",
                          "git2r::status()\""),
                   "",
                   ".PHONY: import-force",
                   "import-force:",
                   paste0("\tRscript -e \"mill::import(); ",
                          "mill::from_docx(git2r::repository(), ",
                          "force = TRUE)\""),
                   "",
                   ".PHONY: diff",
                   "diff:",
                   "\tRscript -e \"mill::create_patch()\"",
                   "",
                   ".PHONY: patch",
                   "patch:",
                   "\tRscript -e \"mill::apply_patch()\"",
                   "",
                   ".PHONY: makefile",
                   "makefile:",
                   "\tRscript -e \"mill::create_Makefile()\"",
                   "",
                   ".PHONY: spell_check",
                   "spell_check:",
                   "\tRscript -e \"(mill::spell_checking())\"",
                   "",
                   ".PHONY: build_figures",
                   "build_figures:",
                   "\tRscript \\",
                   "\t    -e \"mill::build_figures()\" \\",
                   "\t    -e \"warnings()\" \\",
                   "\t    -e \"git2r::status()\"",
                   "",
                   ".PHONY: docker_build",
                   "docker_build:",
                   "\tcd assets/docker;make",
                   "",
                   "clean:",
                   "\tRscript -e \"mill::cleanup()\"")

        writeLines(lines, "Makefile")
        add(repository(), "Makefile")

        lapply(list.files("chapters"), function(chapter) {
            wd <- setwd(paste0("chapters/", chapter))
            create_Makefile()
            setwd(wd)
        })
    }

    invisible()
}
SVA-SE/mill documentation built on June 21, 2020, 4:09 a.m.