Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle more bower cases with bower install in scaffoldWidget #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions R/scaffold.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ addWidgetJS <- function(name, edit){
# This function uses bower to install a javascript package along with
# its dependencies.
installBowerPkg <- function(pkg){
bowerPath = findBower()

# check if bower is installed
if (findBower() == ""){
if (is.null(bowerPath) || bowerPath == ""){
stop(
"Please install bower from http://bower.io",
call. = FALSE
Expand All @@ -185,15 +187,16 @@ installBowerPkg <- function(pkg){
findBower <- function(){
# a slightly more robust finder of bower for windows
# which does not require PATH environment variable to be set
bowerPath = if(Sys.which("bower") == "") {

# try to find the easy case
bowerPath = Sys.which("bower")

if(bowerPath == "" && identical(.Platform$OS.type,"windows")) {
# if it does not find Sys.which('bower')
# also check APPDATA to see if found there
if(identical(.Platform$OS.type,"windows")) {
Sys.which(file.path(Sys.getenv("APPDATA"),"npm","bower."))
}
} else {
Sys.which("bower")
# also check APPDATA if Windows to see if found there
bowerPath = Sys.which(file.path(Sys.getenv("APPDATA"),"npm","bower."))
}

return(bowerPath)
}

Expand All @@ -216,6 +219,11 @@ readBower <- function(pkg, src = "inst/htmlwidgets/lib"){

# Get YAML configuration for widget
getConfig <- function(pkg, src = "inst/htmlwidgets/lib"){
# handle bower when in github shorthand or with full git path
# by using basename and removing .git from basename
# see http://bower.io/#install-bower
# "A package can be a GitHub shorthand, a Git endpoint, a URL, and more."
pkg = gsub(basename(pkg),pattern="([.]*)(.git)",replacement="")
deps = readBower(pkg, src)$deps
all = c(names(deps),pkg)
config = lapply(all, function(pkg){
Expand Down