|
16 | 16 | #' |
17 | 17 | #' @export |
18 | 18 | scaffoldReactInput <- function(name, npmPkgs = NULL, edit = interactive()) { |
19 | | - if (!file.exists('DESCRIPTION')){ |
20 | | - stop( |
21 | | - "You need to create a package to house your widget first!", |
22 | | - call. = F |
23 | | - ) |
24 | | - } |
25 | | - |
26 | | - package <- read.dcf('DESCRIPTION')[[1,"Package"]] |
| 19 | + package <- getPackage() |
27 | 20 |
|
28 | | - # Add input constructor |
29 | | - renderFile( |
| 21 | + file <- renderFile( |
30 | 22 | sprintf("R/%s.R", name), |
31 | 23 | "templates/input_r.txt", |
32 | 24 | "boilerplate for input constructor", |
33 | 25 | list( |
34 | 26 | name = name, |
35 | | - package = package, |
36 | | - capName = capitalize(name) |
| 27 | + package = package |
| 28 | + ) |
| 29 | + ) |
| 30 | + if (edit) fileEdit(file) |
| 31 | + |
| 32 | + renderFile( |
| 33 | + 'package.json', |
| 34 | + 'templates/package.json.txt', |
| 35 | + 'project metadata', |
| 36 | + list(npmPkgs = toDepJSON(npmPkgs)) |
| 37 | + ) |
| 38 | + |
| 39 | + renderFile( |
| 40 | + 'webpack.config.js', |
| 41 | + 'templates/webpack.config.js.txt', |
| 42 | + 'webpack configuration', |
| 43 | + list( |
| 44 | + name = name, |
| 45 | + outputPath = sprintf("inst/www/%s/%s", package, name) |
| 46 | + ) |
| 47 | + ) |
| 48 | + |
| 49 | + renderFile( |
| 50 | + sprintf('srcjs/%s.jsx', name), |
| 51 | + 'templates/input_js.txt', |
| 52 | + 'JavaScript implementation', |
| 53 | + list( |
| 54 | + name = name, |
| 55 | + package = package |
37 | 56 | ) |
38 | 57 | ) |
39 | | - # addInputConstructor(name, package, edit) |
40 | | - # addInputJSON(toDepJSON(npmPkgs)) |
41 | | - # addWebpackConfig(name) |
42 | | - # addWidgetJS(name, edit) |
43 | | - # addExampleApp(name) |
44 | | - # |
45 | | - # usethis::use_build_ignore(c("node_modules", "srcjs")) |
46 | | - # usethis::use_git_ignore(c("node_modules")) |
47 | | - # lapply(c("htmltools", "htmlwidgets", "reactR"), usethis::use_package) |
48 | | - # |
49 | | - # message("To install dependencies from npm run: yarn install") |
50 | | - # message("To build JavaScript run: yarn run webpack --mode=development") |
| 58 | + |
| 59 | + renderFile( |
| 60 | + 'app.R', |
| 61 | + 'templates/input_app.R.txt', |
| 62 | + 'example app', |
| 63 | + list( |
| 64 | + name = name, |
| 65 | + package = package |
| 66 | + ) |
| 67 | + ) |
| 68 | + |
| 69 | + usethis::use_build_ignore(c("node_modules", "srcjs")) |
| 70 | + usethis::use_git_ignore(c("node_modules")) |
| 71 | + lapply(c("htmltools", "htmlwidgets", "reactR"), usethis::use_package) |
| 72 | + |
| 73 | + message("To install dependencies from npm run: yarn install") |
| 74 | + message("To build JavaScript run: yarn run webpack --mode=development") |
51 | 75 | } |
52 | 76 |
|
0 commit comments