diff --git a/NAMESPACE b/NAMESPACE index 58c7098c3..32a39307b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -132,6 +132,7 @@ export(use_git) export(use_git_hook) export(use_github) export(use_github_links) +export(use_mit_license) export(use_package) export(use_package_doc) export(use_rcpp) diff --git a/NEWS.md b/NEWS.md index 19f29452b..d06d57621 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # devtools 1.9.1.9000 +* Added `use_mit_license()`, which writes the necessary infrastructure to + declare and release an R package under the MIT license in a CRAN-compliant + way. (#995, @kevinushey) + * Be more verbose about which package is installed for revdep check (#926, @krlmlr). diff --git a/R/infrastructure.R b/R/infrastructure.R index d0ef48f19..c7e58acfd 100644 --- a/R/infrastructure.R +++ b/R/infrastructure.R @@ -625,3 +625,36 @@ use_cran_badge <- function(pkg = ".") { ) invisible(TRUE) } + +#' @rdname infrastructure +#' @section \code{use_mit_license}: +#' Adds the necessary infrastructure to declare your package as +#' distributed under the MIT license. +#' @param copyright_holder The copyright holder for this package. Defaults to +#' \code{getOption("devtools.name")}. +#' @export +use_mit_license <- function(pkg = ".", copyright_holder = getOption("devtools.name", "")) { + pkg <- as.package(pkg) + + # Update the DESCRIPTION + descPath <- file.path(pkg$path, "DESCRIPTION") + DESCRIPTION <- read_dcf(descPath) + DESCRIPTION$License <- "MIT + file LICENSE" + write_dcf(descPath, DESCRIPTION) + + # Update the license + licensePath <- file.path(pkg$path, "LICENSE") + if (file.exists(licensePath)) + if (!file.remove(licensePath)) + stop("Failed to remove license file '", licensePath, "'", call. = FALSE) + + # Write the MIT template + template <- c( + paste("YEAR:", format(Sys.Date(), "%Y")), + paste("COPYRIGHT HOLDER:", copyright_holder) + ) + + writeLines(template, con = licensePath) + message("* Added infrastructure for MIT license") + licensePath +} diff --git a/man/infrastructure.Rd b/man/infrastructure.Rd index 1bb7abedf..8c3f1437d 100644 --- a/man/infrastructure.Rd +++ b/man/infrastructure.Rd @@ -10,6 +10,7 @@ \alias{use_coverage} \alias{use_cran_badge} \alias{use_cran_comments} +\alias{use_mit_license} \alias{use_package_doc} \alias{use_rcpp} \alias{use_revdep} @@ -45,6 +46,9 @@ use_cran_comments(pkg = ".") use_code_of_conduct(pkg = ".") use_cran_badge(pkg = ".") + +use_mit_license(pkg = ".", copyright_holder = getOption("devtools.name", + "")) } \arguments{ \item{pkg}{package description, can be path or package name. See @@ -54,6 +58,9 @@ use_cran_badge(pkg = ".") numbers, letters, _ and -. I recommend using lower case.} \item{type}{CI tool to use. Currently supports codecov and coverall.} + +\item{copyright_holder}{The copyright holder for this package. Defaults to +\code{getOption("devtools.name")}.} } \description{ Add useful infrastructure to a package. @@ -132,6 +139,12 @@ Add a code of conduct to from \url{http://contributor-covenant.org}. Add a badge to show CRAN status and version number on the README } + +\section{\code{use_mit_license}}{ + +Adds the necessary infrastructure to declare your package as +distributed under the MIT license. +} \seealso{ Other infrastructure: \code{\link{use_build_ignore}}, \code{\link{use_data_raw}}, \code{\link{use_data}},