Skip to content

Commit

Permalink
add 'use_mit_license()' (closes #995)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Jan 15, 2016
1 parent 5d20cc8 commit cbecc9a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).

Expand Down
33 changes: 33 additions & 0 deletions R/infrastructure.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<Author>")) {
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
}
13 changes: 13 additions & 0 deletions man/infrastructure.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cbecc9a

Please sign in to comment.