Skip to content

Commit e5157a9

Browse files
committed
Scaffolding: Add node_modules to .Rbuildignore, creating it if necessary
- Fixes #9
1 parent 62d13a9 commit e5157a9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

R/scaffold.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ scaffoldReactWidget <- function(name, npmPkg = NULL, edit = interactive()){
3333
addWebpackConfig(name)
3434
addWidgetJS(name, edit)
3535
addExampleApp(name)
36+
updateRbuildignore()
3637
message("To install dependencies from npm run: yarn install")
3738
message("To build JavaScript run: yarn run webpack --mode=development")
3839
}
@@ -149,6 +150,18 @@ addExampleApp <- function(name) {
149150
}
150151
}
151152

153+
updateRbuildignore <- function() {
154+
ignore_file <- '.Rbuildignore'
155+
if (file.exists(ignore_file)
156+
&& !("^node_modules$" %in% readLines(ignore_file))) {
157+
message('Adding node_modules to existing .Rbuildignore')
158+
write("^node_modules$", ignore_file, append = TRUE)
159+
} else if (!file.exists(ignore_file)) {
160+
message('Creating .Rbuildignore and adding node_modules')
161+
write("^node_modules$", ignore_file)
162+
}
163+
}
164+
152165
# invoke file.edit in a way that will bind to the RStudio editor
153166
# when running inside RStudio
154167
fileEdit <- function(file) {

0 commit comments

Comments
 (0)