@@ -32,6 +32,9 @@ scaffoldReactWidget <- function(name, npmPkg = NULL, edit = interactive()){
3232 addPackageJSON(toDepJSON(npmPkg ))
3333 addWebpackConfig(name )
3434 addWidgetJS(name , edit )
35+ addExampleApp(name )
36+ message(" To install dependencies from npm run: yarn install" )
37+ message(" To build JavaScript run: yarn run webpack --mode=development" )
3538}
3639
3740toDepJSON <- function (npmPkg ) {
@@ -48,12 +51,12 @@ slurp <- function(file) {
4851 ), collapse = " \n " )
4952}
5053
54+ capName = function (name ){
55+ paste0(toupper(substring(name , 1 , 1 )), substring(name , 2 ))
56+ }
57+
5158addWidgetConstructor <- function (name , package , edit ){
5259 tpl <- slurp(' templates/widget_r.txt' )
53-
54- capName = function (name ){
55- paste0(toupper(substring(name , 1 , 1 )), substring(name , 2 ))
56- }
5760 if (! file.exists(file_ <- sprintf(" R/%s.R" , name ))){
5861 cat(
5962 sprintf(tpl , name , name , package , name , name , name , name , name , name , package , name , capName(name ), name , name , name ),
@@ -93,6 +96,7 @@ addPackageJSON <- function(npmPkg) {
9396 tpl <- sprintf(slurp(' templates/widget_package.json.txt' ), npmPkg )
9497 if (! file.exists(' package.json' )) {
9598 cat(tpl , file = ' package.json' )
99+ message(' Created package.json' )
96100 } else {
97101 message(" package.json already exists" )
98102 }
@@ -102,6 +106,7 @@ addWebpackConfig <- function(name) {
102106 tpl <- sprintf(slurp(' templates/widget_webpack.config.js.txt' ), name , name )
103107 if (! file.exists(' webpack.config.js' )) {
104108 cat(tpl , file = ' webpack.config.js' )
109+ message(' Created webpack.config.js' )
105110 } else {
106111 message(" webpack.config.js already exists" )
107112 }
@@ -125,6 +130,16 @@ addWidgetJS <- function(name, edit){
125130 if (edit ) fileEdit(file_ )
126131}
127132
133+ addExampleApp <- function (name ) {
134+ tpl <- sprintf(slurp(' templates/widget_app.R.txt' ), name , name , capName(name ), name )
135+ if (! file.exists(' app.R' )) {
136+ cat(tpl , file = ' app.R' )
137+ message(' Created example app.R' )
138+ } else {
139+ message(" app.R already exists" )
140+ }
141+ }
142+
128143# invoke file.edit in a way that will bind to the RStudio editor
129144# when running inside RStudio
130145fileEdit <- function (file ) {
0 commit comments