├── .github └── .gitignore ├── FUNDING.yml ├── R ├── zzz.R ├── bare-utils.R ├── workflows.R ├── ambiorix-utils.R ├── leprechaun-files.R ├── golem-utils.R ├── lit.R ├── extension-utils.R ├── npx.R ├── mock.R ├── rmd-utils.R ├── library.R ├── roclets.R ├── windy.R ├── bare.R ├── tailwind.R ├── bundle.R ├── rmd.R ├── ambiorix.R ├── leprechaun.R ├── extension.R ├── input.R ├── output.R ├── widget.R ├── framework7.R ├── widget-utils.R ├── typescript.R └── golem.R ├── inst ├── rmd │ ├── javascript │ │ ├── assets │ │ │ ├── header.html │ │ │ └── app.html │ │ └── srcjs │ │ │ ├── modules │ │ │ └── message.js │ │ │ └── index.js │ ├── vue │ │ ├── assets │ │ │ ├── app.html │ │ │ └── header.html │ │ └── srcjs │ │ │ ├── index.js │ │ │ └── Home.vue │ ├── react │ │ ├── assets │ │ │ ├── app.html │ │ │ └── header.html │ │ └── srcjs │ │ │ └── index.js │ └── index.Rmd ├── leprechaun │ ├── modules │ │ └── message.js │ └── index.js ├── tailwind │ ├── style.css │ ├── postcss.config.js │ └── tailwind.config.js ├── templates │ ├── vue │ │ ├── _babelrc │ │ ├── vue.js │ │ ├── vue.vue │ │ └── vue_cdn.R │ ├── react │ │ ├── _babelrc │ │ ├── react.js │ │ └── react_cdn.R │ ├── framework7 │ │ ├── _babelrc │ │ ├── framework7.js │ │ ├── app_ui.R │ │ ├── components │ │ │ └── app.f7.jsx │ │ └── golem_add_external_resources.R │ ├── peeky-test.js │ ├── mocha-test.js │ ├── index.pug │ └── index.html ├── ambiorix │ └── javascript │ │ ├── modules │ │ └── message.js │ │ └── index.js ├── golem │ └── javascript │ │ ├── modules │ │ └── message.js │ │ └── index.js ├── widget │ └── javascript │ │ ├── module.js │ │ └── widget.js ├── extension │ ├── R │ │ ├── zzz.R │ │ └── extension.R │ └── javascript │ │ └── extension.js ├── hooks │ ├── rprof.R │ ├── minified.sh │ └── check.yml ├── common │ ├── webpack.prod.js │ ├── webpack.dev.js │ └── webpack.common.js ├── bare │ └── index.js ├── jsdoc │ └── conf.json ├── output │ ├── javascript │ │ └── output.js │ └── R │ │ └── output.R ├── lit │ └── config.json └── input │ ├── javascript │ └── input.js │ └── R │ └── input.R ├── LICENSE ├── .gitignore ├── docs ├── favicon.ico ├── _media │ ├── favicon.ico │ ├── packer.png │ ├── peeky.png │ ├── typed.gif │ ├── vue-bs4.gif │ ├── golem-pug.png │ ├── input-toy.png │ ├── shiny-vue.png │ ├── get-started.gif │ ├── golem-react.png │ ├── input-basic.gif │ ├── toy-widget.png │ ├── vue-bs4-html.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ ├── packer_banner.png │ ├── apple-touch-icon.png │ ├── android-chrome-192x192.png │ └── android-chrome-512x512.png ├── references │ ├── checks.md │ ├── npm_update.md │ ├── npm_outdated.md │ ├── dev_roclet.md │ ├── prod_roclet.md │ ├── npm_console.md │ ├── yarn_console.md │ ├── engine_console.md │ ├── engine_check.md │ ├── add_plugin_workbox.md │ ├── yarn_upgrade.md │ ├── yarn_outdated.md │ ├── add_plugin_eslint.md │ ├── include_action_check.md │ ├── put_test.md │ ├── npx.md │ ├── yarn_clean.md │ ├── add_plugin_prettier.md │ ├── put_recommended.md │ ├── npm_fix.md │ ├── get_edit.md │ ├── ease_lit.md │ ├── npm_run.md │ ├── yarn_run.md │ ├── put_rprofile_adapt.md │ ├── mockup.md │ ├── yarn_version.md │ ├── put_precommit_hook.md │ ├── use_loader_svelte.md │ ├── use_loader_pug.md │ ├── use_loader_ts.md │ ├── yarn_global.md │ ├── bundle.md │ ├── use_tailwind.md │ ├── set_npm.md │ ├── set_yarn.md │ ├── apply_framework7.md │ ├── use_loader_file.md │ ├── jsdoc.md │ ├── use_loader_mocha.md │ ├── use_loader_coffee.md │ ├── yarn_install.md │ ├── npm_install.md │ ├── use_loader_framework7.md │ ├── types.md │ ├── add_plugin_clean.md │ ├── use_loader_babel.md │ ├── add_plugin_html.md │ ├── engine.md │ ├── use_loader_vue.md │ ├── apply_vue.md │ ├── use_loader_rule.md │ ├── make_library.md │ ├── scaffold_bare.md │ ├── scaffold_windy.md │ ├── scaffold_input.md │ ├── scaffold_output.md │ ├── scaffold_extension.md │ ├── use_loader_style.md │ ├── apply_react.md │ ├── scaffold_widget.md │ ├── scaffold_leprechaun.md │ ├── scaffold_rmd.md │ ├── tests.md │ ├── scaffold_ambiorix.md │ └── scaffold_golem.md ├── sw.js ├── docify.R ├── guide │ ├── bundle.md │ ├── engines.md │ ├── installation.md │ ├── docs.md │ ├── typescript.md │ ├── prereq.md │ ├── library.md │ └── pwa.md └── examples │ └── typed.md ├── tests ├── testthat.R ├── testthat │ ├── test-bare │ ├── test-bare.R │ ├── test-windy.R │ ├── test-widget.R │ ├── test-ouput.R │ ├── test-npm.R │ ├── test-ts.R │ ├── test-ambiorix.R │ ├── test-extension.R │ ├── test-check.R │ ├── test-rmd.R │ ├── test-leprechaun.R │ ├── test-input.R │ ├── test-yarn.R │ └── test-golem.R └── fns.R ├── CRAN-SUBMISSION ├── .Rbuildignore ├── cran-comments.md ├── man ├── npm_update.Rd ├── npm_outdated.Rd ├── dev_roclet.Rd ├── npx.Rd ├── prod_roclet.Rd ├── npm_console.Rd ├── yarn_console.Rd ├── engine_console.Rd ├── engine_check.Rd ├── yarn_upgrade.Rd ├── add_plugin_workbox.Rd ├── yarn_outdated.Rd ├── ease_lit.Rd ├── npm_run.Rd ├── put_test.Rd ├── yarn_run.Rd ├── get_edit.Rd ├── yarn_clean.Rd ├── put_recommended.Rd ├── add_plugin_eslint.Rd ├── include_action_check.Rd ├── npm_fix.Rd ├── add_plugin_prettier.Rd ├── use_loader_pug.Rd ├── use_loader_svelte.Rd ├── use_loader_ts.Rd ├── checks.Rd ├── put_rprofile_adapt.Rd ├── yarn_version.Rd ├── use_tailwind.Rd ├── put_precommit_hook.Rd ├── set_npm.Rd ├── set_yarn.Rd ├── mockup.Rd ├── use_loader_file.Rd ├── use_loader_mocha.Rd ├── use_loader_coffee.Rd ├── apply_framework7.Rd ├── jsdoc.Rd ├── use_loader_framework7.Rd ├── yarn_global.Rd ├── add_plugin_clean.Rd ├── use_loader_babel.Rd ├── add_plugin_html.Rd ├── use_loader_vue.Rd ├── yarn_install.Rd ├── apply_vue.Rd ├── use_loader_rule.Rd ├── types.Rd ├── make_library.Rd ├── npm_install.Rd ├── scaffold_bare.Rd ├── scaffold_windy.Rd ├── scaffold_input.Rd ├── scaffold_output.Rd ├── scaffold_extension.Rd ├── apply_react.Rd ├── bundle.Rd ├── scaffold_widget.Rd ├── engine.Rd ├── scaffold_leprechaun.Rd ├── scaffold_rmd.Rd ├── scaffold_ambiorix.Rd ├── tests.Rd ├── use_loader_style.Rd └── scaffold_golem.Rd ├── makefile ├── codecov.yml ├── LICENSE.md ├── DESCRIPTION ├── README.md └── NAMESPACE /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: JohnCoene 2 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | storage <- new.env() 2 | -------------------------------------------------------------------------------- /inst/rmd/javascript/assets/header.html: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2020 2 | COPYRIGHT HOLDER: John Coene 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ./docs/node_modules/ 2 | .DS_Store 3 | test.R 4 | .vscode 5 | -------------------------------------------------------------------------------- /inst/rmd/javascript/assets/app.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/favicon.ico -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(packer) 3 | 4 | test_check("packer") 5 | -------------------------------------------------------------------------------- /inst/rmd/vue/assets/app.html: -------------------------------------------------------------------------------- 1 |
2 | -------------------------------------------------------------------------------- /docs/_media/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/favicon.ico -------------------------------------------------------------------------------- /docs/_media/packer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/packer.png -------------------------------------------------------------------------------- /docs/_media/peeky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/peeky.png -------------------------------------------------------------------------------- /docs/_media/typed.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/typed.gif -------------------------------------------------------------------------------- /docs/_media/vue-bs4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/vue-bs4.gif -------------------------------------------------------------------------------- /inst/leprechaun/modules/message.js: -------------------------------------------------------------------------------- 1 | export const message = (msg) => { 2 | alert(msg); 3 | } 4 | -------------------------------------------------------------------------------- /inst/rmd/react/assets/app.html: -------------------------------------------------------------------------------- 1 |
2 | -------------------------------------------------------------------------------- /inst/tailwind/style.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /inst/templates/vue/_babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /docs/_media/golem-pug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/golem-pug.png -------------------------------------------------------------------------------- /docs/_media/input-toy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/input-toy.png -------------------------------------------------------------------------------- /docs/_media/shiny-vue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/shiny-vue.png -------------------------------------------------------------------------------- /docs/_media/get-started.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/get-started.gif -------------------------------------------------------------------------------- /docs/_media/golem-react.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/golem-react.png -------------------------------------------------------------------------------- /docs/_media/input-basic.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/input-basic.gif -------------------------------------------------------------------------------- /docs/_media/toy-widget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/toy-widget.png -------------------------------------------------------------------------------- /docs/_media/vue-bs4-html.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/vue-bs4-html.png -------------------------------------------------------------------------------- /inst/rmd/vue/assets/header.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /docs/_media/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/favicon-16x16.png -------------------------------------------------------------------------------- /docs/_media/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/favicon-32x32.png -------------------------------------------------------------------------------- /docs/_media/packer_banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/packer_banner.png -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.1.3 2 | Date: 2022-05-28 09:13:28 UTC 3 | SHA: 91d8558cbb1842c9a2b248a29dacc7fde11371a2 4 | -------------------------------------------------------------------------------- /docs/_media/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/apple-touch-icon.png -------------------------------------------------------------------------------- /docs/_media/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/android-chrome-192x192.png -------------------------------------------------------------------------------- /docs/_media/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnCoene/packer/HEAD/docs/_media/android-chrome-512x512.png -------------------------------------------------------------------------------- /inst/ambiorix/javascript/modules/message.js: -------------------------------------------------------------------------------- 1 | const message = (msg) => { 2 | alert(msg); 3 | } 4 | 5 | export { message }; 6 | -------------------------------------------------------------------------------- /inst/golem/javascript/modules/message.js: -------------------------------------------------------------------------------- 1 | const message = (msg) => { 2 | alert(msg); 3 | } 4 | 5 | export { message }; 6 | -------------------------------------------------------------------------------- /inst/rmd/javascript/srcjs/modules/message.js: -------------------------------------------------------------------------------- 1 | const message = (msg) => { 2 | alert(msg); 3 | } 4 | 5 | export { message }; 6 | -------------------------------------------------------------------------------- /inst/rmd/react/srcjs/index.js: -------------------------------------------------------------------------------- 1 | createRoot( 2 | document.getElementById('app') 3 | ).render( 4 |
{title}
5 | ); 6 | -------------------------------------------------------------------------------- /inst/templates/react/_babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-react" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /inst/templates/framework7/_babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/preset-env", 4 | "@babel/preset-react" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /inst/tailwind/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | ['tailwindcss'], 4 | ['autoprefixer'], 5 | ], 6 | }; 7 | -------------------------------------------------------------------------------- /inst/widget/javascript/module.js: -------------------------------------------------------------------------------- 1 | const asHeader = (x) => { 2 | return '

' + x.message + '

'; 3 | } 4 | 5 | export { asHeader }; 6 | -------------------------------------------------------------------------------- /inst/ambiorix/javascript/index.js: -------------------------------------------------------------------------------- 1 | import 'ambiorix'; 2 | import { message } from './modules/message.js'; 3 | 4 | message("Hello Ambiorix"); 5 | -------------------------------------------------------------------------------- /inst/templates/peeky-test.js: -------------------------------------------------------------------------------- 1 | describe('Example test suite', () => { 2 | test('must work', () => { 3 | expect(42).toBe(42) 4 | }) 5 | }) 6 | -------------------------------------------------------------------------------- /inst/templates/react/react.js: -------------------------------------------------------------------------------- 1 | const title = 'Shiny powered by React!'; 2 | 3 | createRoot( 4 | document.getElementById('app') 5 | ).render( 6 |
{title}
7 | ); 8 | -------------------------------------------------------------------------------- /inst/templates/vue/vue.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import App from "./Home.vue"; 3 | 4 | new Vue({ 5 | el: "#app", 6 | template: "", 7 | components: { App } 8 | }); 9 | -------------------------------------------------------------------------------- /inst/extension/R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname){ 2 | path <- system.file("packer", package = "#pkgname#") 3 | shiny::addResourcePath('#pkgname#-assets', path) 4 | } 5 | -------------------------------------------------------------------------------- /inst/rmd/vue/srcjs/index.js: -------------------------------------------------------------------------------- 1 | import Vue from "vue"; 2 | import App from "./Home.vue"; 3 | 4 | new Vue({ 5 | el: "#app", 6 | template: "", 7 | components: { App } 8 | }); 9 | -------------------------------------------------------------------------------- /inst/hooks/rprof.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace('packer', quietly = TRUE)){ 2 | packer::engine_adapt() 3 | } else { 4 | warning("This package requires packer: `install.packages('packer')`") 5 | } 6 | -------------------------------------------------------------------------------- /inst/common/webpack.prod.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const common = require('./webpack.common.js'); 3 | 4 | module.exports = merge(common, { 5 | mode: 'production', 6 | }); 7 | -------------------------------------------------------------------------------- /inst/rmd/javascript/srcjs/index.js: -------------------------------------------------------------------------------- 1 | import { message } from './modules/message.js'; 2 | 3 | // In shiny server use: 4 | // session$sendCustomMessage('show-packer', 'hello packer!') 5 | message(msg); 6 | -------------------------------------------------------------------------------- /inst/hooks/minified.sh: -------------------------------------------------------------------------------- 1 | RESULT=$(Rscript -e "packer:::are_minified('<>')") 2 | if [ $RESULT -gt 0 ] 3 | then 4 | echo 'JavaScript files not minified, run packer::bundle_prod()' 5 | fi 6 | exit $RESULT 7 | -------------------------------------------------------------------------------- /inst/rmd/index.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Packer" 3 | output: 4 | html_document: 5 | includes: 6 | in_header: assets/header.html 7 | after_body: assets/app.html 8 | --- 9 | 10 | # Packer 11 | -------------------------------------------------------------------------------- /docs/references/checks.md: -------------------------------------------------------------------------------- 1 | # `checks` 2 | 3 | Checks 4 | 5 | 6 | ## Description 7 | 8 | Run checks on a package using packer. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | checks() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/references/npm_update.md: -------------------------------------------------------------------------------- 1 | # `npm_update` 2 | 3 | Npm Update 4 | 5 | 6 | ## Description 7 | 8 | Update npm dependencies. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | npm_update() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /inst/bare/index.js: -------------------------------------------------------------------------------- 1 | import 'shiny'; 2 | 3 | // In shiny server use: 4 | // session$sendCustomMessage('packer-alert', 'hello packer!') 5 | Shiny.addCustomMessageHandler('packer-alert', (msg) => { 6 | alert(msg) 7 | }); 8 | -------------------------------------------------------------------------------- /inst/extension/javascript/extension.js: -------------------------------------------------------------------------------- 1 | import 'shiny'; 2 | 3 | Shiny.addCustomMessageHandler('#name#-alert', (msg) => { 4 | let response = prompt(msg); 5 | Shiny.setInputValue('#name#Response', response); 6 | }) 7 | -------------------------------------------------------------------------------- /inst/jsdoc/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "opts" : { 3 | "destination": "./jsdoc" 4 | }, 5 | "source": { 6 | "include": "srcjs/", 7 | "exclude": "/node_modules", 8 | "includePattern": ".+\\.js(doc|x)?$" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /docs/references/npm_outdated.md: -------------------------------------------------------------------------------- 1 | # `npm_outdated` 2 | 3 | Npm Outdated 4 | 5 | 6 | ## Description 7 | 8 | Find outdated dependencies 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | npm_outdated() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /inst/rmd/react/assets/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /inst/common/webpack.dev.js: -------------------------------------------------------------------------------- 1 | const { merge } = require('webpack-merge'); 2 | const common = require('./webpack.common.js'); 3 | 4 | module.exports = merge(common, { 5 | mode: 'development', 6 | devtool: 'inline-source-map' 7 | }); 8 | -------------------------------------------------------------------------------- /inst/tailwind/tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | purge: ['./srcjs/*.js'], 3 | darkMode: false, 4 | theme: { 5 | extend: {}, 6 | }, 7 | variants: { 8 | extend: {}, 9 | }, 10 | plugins: [], 11 | }; 12 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^LICENSE\.md$ 2 | ^\.github$ 3 | ^docs$ 4 | ^\.travis\.yml$ 5 | ^appveyor\.yml$ 6 | ^cran-comments\.md$ 7 | ^CRAN-RELEASE$ 8 | FUNDING.yml 9 | ^codecov\.yml$ 10 | ^test\.R$ 11 | ^CRAN-SUBMISSION$ 12 | makefile 13 | ^\.vscode$ 14 | -------------------------------------------------------------------------------- /docs/references/dev_roclet.md: -------------------------------------------------------------------------------- 1 | # `dev_roclet` 2 | 3 | Roclet Dev 4 | 5 | 6 | ## Description 7 | 8 | Roclet to run [bundle_dev](#bundledev) when documenting. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | dev_roclet() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## Test environments 2 | 3 | * local R installation, R 4.1.2 4 | * ubuntu 16.04 (on travis-ci), R 4.1.2 5 | * win-builder (devel) 6 | * rhub, R 4.1.2 7 | 8 | ## R CMD check results 9 | 10 | 0 errors | 0 warnings | 0 note 11 | -------------------------------------------------------------------------------- /docs/references/prod_roclet.md: -------------------------------------------------------------------------------- 1 | # `prod_roclet` 2 | 3 | Roclet Prod 4 | 5 | 6 | ## Description 7 | 8 | Roclet to run [bundle_prod](#bundleprod) when documenting. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | prod_roclet() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/references/npm_console.md: -------------------------------------------------------------------------------- 1 | # `npm_console` 2 | 3 | Npm Output 4 | 5 | 6 | ## Description 7 | 8 | Prints the output of the last npm command run, useful for debugging. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | npm_console() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/references/yarn_console.md: -------------------------------------------------------------------------------- 1 | # `yarn_console` 2 | 3 | Yarn Output 4 | 5 | 6 | ## Description 7 | 8 | Prints the output of the last command run, useful for debugging. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | yarn_console() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/references/engine_console.md: -------------------------------------------------------------------------------- 1 | # `engine_console` 2 | 3 | Npm Output 4 | 5 | 6 | ## Description 7 | 8 | Prints the output of the last npm command run, useful for debugging. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | engine_console() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /inst/rmd/vue/srcjs/Home.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 16 | -------------------------------------------------------------------------------- /man/npm_update.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm_update} 4 | \alias{npm_update} 5 | \title{Npm Update} 6 | \usage{ 7 | npm_update() 8 | } 9 | \description{ 10 | Update npm dependencies. 11 | } 12 | -------------------------------------------------------------------------------- /inst/leprechaun/index.js: -------------------------------------------------------------------------------- 1 | import { message } from './modules/message.js'; 2 | import 'shiny'; 3 | 4 | // In shiny server use: 5 | // session$sendCustomMessage('show-packer', 'hello packer!') 6 | Shiny.addCustomMessageHandler('show-packer', (msg) => { 7 | message(msg.text); 8 | }) -------------------------------------------------------------------------------- /inst/templates/mocha-test.js: -------------------------------------------------------------------------------- 1 | describe('Test', () => { 2 | it('should succeed', (done) => { 3 | setTimeout(done, 1000); 4 | }); 5 | 6 | it('should fail', () => { 7 | if (require('./module')) { 8 | throw new Error('Failed'); 9 | } 10 | }); 11 | }); -------------------------------------------------------------------------------- /docs/references/engine_check.md: -------------------------------------------------------------------------------- 1 | # `engine_check` 2 | 3 | Engine Check 4 | 5 | 6 | ## Description 7 | 8 | Check if the engine is correctly set up and 9 | prints helpful messages if not. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | engine_check() 16 | ``` 17 | 18 | 19 | -------------------------------------------------------------------------------- /inst/golem/javascript/index.js: -------------------------------------------------------------------------------- 1 | import { message } from './modules/message.js'; 2 | import 'shiny'; 3 | 4 | // In shiny server use: 5 | // session$sendCustomMessage('show-packer', 'hello packer!') 6 | Shiny.addCustomMessageHandler('show-packer', (msg) => { 7 | message(msg); 8 | }) 9 | -------------------------------------------------------------------------------- /docs/references/add_plugin_workbox.md: -------------------------------------------------------------------------------- 1 | # `add_plugin_workbox` 2 | 3 | Progressive Web Applications 4 | 5 | 6 | ## Description 7 | 8 | Add the `workbox-webpack-plugin` to the config files. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | add_plugin_workbox() 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /man/npm_outdated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm_outdated} 4 | \alias{npm_outdated} 5 | \title{Npm Outdated} 6 | \usage{ 7 | npm_outdated() 8 | } 9 | \description{ 10 | Find outdated dependencies 11 | } 12 | -------------------------------------------------------------------------------- /docs/references/yarn_upgrade.md: -------------------------------------------------------------------------------- 1 | # `yarn_upgrade` 2 | 3 | Yarn Upgrade 4 | 5 | 6 | ## Description 7 | 8 | Upgrade yarn dependencies. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | yarn_upgrade() 15 | ``` 16 | 17 | 18 | ## Examples 19 | 20 | ```r 21 | yarn_upgrade() 22 | ``` 23 | 24 | 25 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | install: check 2 | Rscript -e "devtools::install()" 3 | 4 | check: document 5 | Rscript -e "devtools::document()" 6 | 7 | document: site 8 | Rscript -e "devtools::check()" 9 | 10 | site: styler 11 | Rscript docs/docify.R 12 | 13 | styler: 14 | Rscript -e "styler::style_pkg()" 15 | -------------------------------------------------------------------------------- /man/dev_roclet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/roclets.R 3 | \name{dev_roclet} 4 | \alias{dev_roclet} 5 | \title{Roclet Dev} 6 | \usage{ 7 | dev_roclet() 8 | } 9 | \description{ 10 | Roclet to run \link{bundle_dev} when documenting. 11 | } 12 | -------------------------------------------------------------------------------- /docs/references/yarn_outdated.md: -------------------------------------------------------------------------------- 1 | # `yarn_outdated` 2 | 3 | Yarn Outdated 4 | 5 | 6 | ## Description 7 | 8 | Find outdated dependencies 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | yarn_outdated() 15 | ``` 16 | 17 | 18 | ## Examples 19 | 20 | ```r 21 | yarn_outdated() 22 | ``` 23 | 24 | 25 | -------------------------------------------------------------------------------- /inst/templates/index.pug: -------------------------------------------------------------------------------- 1 | //- layout.pug 2 | doctype html 3 | html 4 | head 5 | script(src="shared/jquery.js") 6 | script(src="shared/shiny.js") 7 | link(rel="stylesheet" type="text/css" href="shared/shiny.css") 8 | title Hello Packer 9 | body 10 | p Place the content here 11 | -------------------------------------------------------------------------------- /man/npx.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npx.R 3 | \name{npx} 4 | \alias{npx} 5 | \title{NPX} 6 | \usage{ 7 | npx(...) 8 | } 9 | \arguments{ 10 | \item{...}{Arguments to pass to npx} 11 | } 12 | \description{ 13 | Run an \code{npx} command. 14 | } 15 | -------------------------------------------------------------------------------- /man/prod_roclet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/roclets.R 3 | \name{prod_roclet} 4 | \alias{prod_roclet} 5 | \title{Roclet Prod} 6 | \usage{ 7 | prod_roclet() 8 | } 9 | \description{ 10 | Roclet to run \link{bundle_prod} when documenting. 11 | } 12 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /man/npm_console.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm_console} 4 | \alias{npm_console} 5 | \title{Npm Output} 6 | \usage{ 7 | npm_console() 8 | } 9 | \description{ 10 | Prints the output of the last npm command run, useful for debugging. 11 | } 12 | -------------------------------------------------------------------------------- /man/yarn_console.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_console} 4 | \alias{yarn_console} 5 | \title{Yarn Output} 6 | \usage{ 7 | yarn_console() 8 | } 9 | \description{ 10 | Prints the output of the last command run, useful for debugging. 11 | } 12 | -------------------------------------------------------------------------------- /docs/references/add_plugin_eslint.md: -------------------------------------------------------------------------------- 1 | # `add_plugin_eslint` 2 | 3 | ESLint Plugin 4 | 5 | 6 | ## Description 7 | 8 | Add the [eslint-webpack-plugin](https://www.npmjs.com/package/eslint-webpack-plugin) 9 | run ESLint on files. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | add_plugin_eslint() 16 | ``` 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/references/include_action_check.md: -------------------------------------------------------------------------------- 1 | # `include_action_check` 2 | 3 | Github Actions 4 | 5 | 6 | ## Description 7 | 8 | Adds a Github Action to the package that will ensure 9 | JavaScript files have been bundled for production. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | include_action_check() 16 | ``` 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/references/put_test.md: -------------------------------------------------------------------------------- 1 | # `put_test` 2 | 3 | Put a Test 4 | 5 | 6 | ## Description 7 | 8 | Puts a testthat test to ensure the files are 9 | optimised for prod. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | put_test() 16 | ``` 17 | 18 | 19 | ## Note 20 | 21 | This function adds packer to `Suggests` . 22 | 23 | 24 | -------------------------------------------------------------------------------- /man/engine_console.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/engine.R 3 | \name{engine_console} 4 | \alias{engine_console} 5 | \title{Npm Output} 6 | \usage{ 7 | engine_console() 8 | } 9 | \description{ 10 | Prints the output of the last npm command run, useful for debugging. 11 | } 12 | -------------------------------------------------------------------------------- /docs/references/npx.md: -------------------------------------------------------------------------------- 1 | # `npx` 2 | 3 | NPX 4 | 5 | 6 | ## Description 7 | 8 | Run an `npx` command. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | npx(...) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `...` | Arguments to pass to npx 23 | 24 | 25 | -------------------------------------------------------------------------------- /man/engine_check.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/engine.R 3 | \name{engine_check} 4 | \alias{engine_check} 5 | \title{Engine Check} 6 | \usage{ 7 | engine_check() 8 | } 9 | \description{ 10 | Check if the engine is correctly set up and 11 | prints helpful messages if not. 12 | } 13 | -------------------------------------------------------------------------------- /docs/references/yarn_clean.md: -------------------------------------------------------------------------------- 1 | # `yarn_clean` 2 | 3 | Yarn cache clean 4 | 5 | 6 | ## Description 7 | 8 | Clean the cache 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | yarn_clean() 15 | ``` 16 | 17 | 18 | ## Value 19 | 20 | The semver as a string. 21 | 22 | 23 | ## Examples 24 | 25 | ```r 26 | yarn_clean() 27 | ``` 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/references/add_plugin_prettier.md: -------------------------------------------------------------------------------- 1 | # `add_plugin_prettier` 2 | 3 | Prettier Plugin 4 | 5 | 6 | ## Description 7 | 8 | Add the [prettier-webpack-plugin](https://www.npmjs.com/package/prettier-webpack-plugin) to 9 | prettify the pre-bundled files. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | add_plugin_prettier() 16 | ``` 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/references/put_recommended.md: -------------------------------------------------------------------------------- 1 | # `put_recommended` 2 | 3 | Recommended Checks 4 | 5 | 6 | ## Description 7 | 8 | Recommended checks for packer projects, 9 | runs [put_rprofile_adapt](#putrprofileadapt) and 10 | [put_precommit_hook](#putprecommithook) . 11 | 12 | 13 | ## Usage 14 | 15 | ```r 16 | put_recommended() 17 | ``` 18 | 19 | 20 | -------------------------------------------------------------------------------- /man/yarn_upgrade.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_upgrade} 4 | \alias{yarn_upgrade} 5 | \title{Yarn Upgrade} 6 | \usage{ 7 | yarn_upgrade() 8 | } 9 | \description{ 10 | Upgrade yarn dependencies. 11 | } 12 | \examples{ 13 | \dontrun{ 14 | yarn_upgrade() 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /docs/references/npm_fix.md: -------------------------------------------------------------------------------- 1 | # `npm_fix` 2 | 3 | Audit Fix 4 | 5 | 6 | ## Description 7 | 8 | Scan your project for vulnerabilities and automatically install 9 | any compatible updates to vulnerable dependencies. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | npm_fix() 16 | ``` 17 | 18 | 19 | ## Details 20 | 21 | Runs npm audit fix 22 | 23 | 24 | -------------------------------------------------------------------------------- /man/add_plugin_workbox.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugins.R 3 | \name{add_plugin_workbox} 4 | \alias{add_plugin_workbox} 5 | \title{Progressive Web Applications} 6 | \usage{ 7 | add_plugin_workbox() 8 | } 9 | \description{ 10 | Add the \code{workbox-webpack-plugin} to the config files. 11 | } 12 | -------------------------------------------------------------------------------- /man/yarn_outdated.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_outdated} 4 | \alias{yarn_outdated} 5 | \title{Yarn Outdated} 6 | \usage{ 7 | yarn_outdated() 8 | } 9 | \description{ 10 | Find outdated dependencies 11 | } 12 | \examples{ 13 | \dontrun{ 14 | yarn_outdated() 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /inst/templates/vue/vue.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 14 | 15 | 21 | -------------------------------------------------------------------------------- /man/ease_lit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/lit.R 3 | \name{ease_lit} 4 | \alias{ease_lit} 5 | \title{Lit} 6 | \usage{ 7 | ease_lit(ts = FALSE) 8 | } 9 | \arguments{ 10 | \item{ts}{Whether to use TypeScript (recommended).} 11 | } 12 | \description{ 13 | Use \href{https://lit.dev}{Lit} in your project. 14 | } 15 | -------------------------------------------------------------------------------- /inst/templates/framework7/framework7.js: -------------------------------------------------------------------------------- 1 | // Import Framework7 2 | import Framework7 from 'framework7'; 3 | // Import Framework7 Styles 4 | import 'framework7/framework7-bundle.min.css'; 5 | 6 | import App from './components/app.f7.jsx'; 7 | let app = new Framework7({ 8 | el: '#app', 9 | theme: 'ios', 10 | // specify main app component 11 | component: App 12 | }); -------------------------------------------------------------------------------- /man/npm_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm_run} 4 | \alias{npm_run} 5 | \title{Npm Command} 6 | \usage{ 7 | npm_run(...) 8 | } 9 | \arguments{ 10 | \item{...}{Passed to \code{\link[=system2]{system2()}}.} 11 | } 12 | \description{ 13 | Convenience function to run \code{npm} commands. 14 | } 15 | -------------------------------------------------------------------------------- /man/put_test.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checks.R 3 | \name{put_test} 4 | \alias{put_test} 5 | \title{Put a Test} 6 | \usage{ 7 | put_test() 8 | } 9 | \description{ 10 | Puts a testthat test to ensure the files are 11 | optimised for prod. 12 | } 13 | \note{ 14 | This function adds packer to \code{Suggests}. 15 | } 16 | -------------------------------------------------------------------------------- /man/yarn_run.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_run} 4 | \alias{yarn_run} 5 | \title{Yarn Command} 6 | \usage{ 7 | yarn_run(...) 8 | } 9 | \arguments{ 10 | \item{...}{Passed to \code{\link[=system2]{system2()}}.} 11 | } 12 | \description{ 13 | Convenience function to run \code{yarn} commands. 14 | } 15 | -------------------------------------------------------------------------------- /docs/references/get_edit.md: -------------------------------------------------------------------------------- 1 | # `get_edit` 2 | 3 | Get Edit Mode 4 | 5 | 6 | ## Description 7 | 8 | Get edit value to handle `NULL` value. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | get_edit(edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `edit` | Current edit value. 23 | 24 | 25 | -------------------------------------------------------------------------------- /man/get_edit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{get_edit} 4 | \alias{get_edit} 5 | \title{Get Edit Mode} 6 | \usage{ 7 | get_edit(edit = NULL) 8 | } 9 | \arguments{ 10 | \item{edit}{Current edit value.} 11 | } 12 | \description{ 13 | Get edit value to handle \code{NULL} value. 14 | } 15 | \keyword{internal} 16 | -------------------------------------------------------------------------------- /man/yarn_clean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_clean} 4 | \alias{yarn_clean} 5 | \title{Yarn cache clean} 6 | \usage{ 7 | yarn_clean() 8 | } 9 | \value{ 10 | The semver as a string. 11 | } 12 | \description{ 13 | Clean the cache 14 | } 15 | \examples{ 16 | \dontrun{ 17 | yarn_clean() 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /man/put_recommended.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checks.R 3 | \name{put_recommended} 4 | \alias{put_recommended} 5 | \title{Recommended Checks} 6 | \usage{ 7 | put_recommended() 8 | } 9 | \description{ 10 | Recommended checks for packer projects, 11 | runs \link{put_rprofile_adapt} and 12 | \link{put_precommit_hook}. 13 | } 14 | -------------------------------------------------------------------------------- /docs/references/ease_lit.md: -------------------------------------------------------------------------------- 1 | # `ease_lit` 2 | 3 | Lit 4 | 5 | 6 | ## Description 7 | 8 | Use [Lit](https://lit.dev) in your project. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | ease_lit(ts = FALSE) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `ts` | Whether to use TypeScript (recommended). 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/references/npm_run.md: -------------------------------------------------------------------------------- 1 | # `npm_run` 2 | 3 | Npm Command 4 | 5 | 6 | ## Description 7 | 8 | Convenience function to run `npm` commands. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | npm_run(...) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `...` | Passed to [`system2()`](#system2()) . 23 | 24 | 25 | -------------------------------------------------------------------------------- /man/add_plugin_eslint.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugins.R 3 | \name{add_plugin_eslint} 4 | \alias{add_plugin_eslint} 5 | \title{ESLint Plugin} 6 | \usage{ 7 | add_plugin_eslint() 8 | } 9 | \description{ 10 | Add the \href{https://www.npmjs.com/package/eslint-webpack-plugin}{eslint-webpack-plugin} 11 | run ESLint on files. 12 | } 13 | -------------------------------------------------------------------------------- /docs/references/yarn_run.md: -------------------------------------------------------------------------------- 1 | # `yarn_run` 2 | 3 | Yarn Command 4 | 5 | 6 | ## Description 7 | 8 | Convenience function to run `yarn` commands. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | yarn_run(...) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `...` | Passed to [`system2()`](#system2()) . 23 | 24 | 25 | -------------------------------------------------------------------------------- /man/include_action_check.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/workflows.R 3 | \name{include_action_check} 4 | \alias{include_action_check} 5 | \title{Github Actions} 6 | \usage{ 7 | include_action_check() 8 | } 9 | \description{ 10 | Adds a Github Action to the package that will ensure 11 | JavaScript files have been bundled for production. 12 | } 13 | -------------------------------------------------------------------------------- /man/npm_fix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm_fix} 4 | \alias{npm_fix} 5 | \title{Audit Fix} 6 | \usage{ 7 | npm_fix() 8 | } 9 | \description{ 10 | Scan your project for vulnerabilities and automatically install 11 | any compatible updates to vulnerable dependencies. 12 | } 13 | \details{ 14 | Runs \verb{npm audit fix} 15 | } 16 | -------------------------------------------------------------------------------- /R/bare-utils.R: -------------------------------------------------------------------------------- 1 | #' Bare JavaScript Files 2 | #' 3 | #' Creates the necessary `srcjs` directory and children JavaScript files. 4 | #' This is a simple copy of template files: no changes required. 5 | #' 6 | #' @noRd 7 | #' @keywords internal 8 | bare_files <- function() { 9 | base <- pkg_file("bare") 10 | fs::dir_copy(base, "srcjs") 11 | cli::cli_alert_success("Created {.file srcjs} directory") 12 | } 13 | -------------------------------------------------------------------------------- /docs/references/put_rprofile_adapt.md: -------------------------------------------------------------------------------- 1 | # `put_rprofile_adapt` 2 | 3 | Rprofile 4 | 5 | 6 | ## Description 7 | 8 | Add [`engine_adapt()`](#engineadapt()) to `.Rprofile` . 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | put_rprofile_adapt() 15 | ``` 16 | 17 | 18 | ## Details 19 | 20 | This is recommended so anyone contributing to 21 | the project is guaranteed to be on the correct 22 | engine. 23 | 24 | 25 | -------------------------------------------------------------------------------- /man/add_plugin_prettier.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugins.R 3 | \name{add_plugin_prettier} 4 | \alias{add_plugin_prettier} 5 | \title{Prettier Plugin} 6 | \usage{ 7 | add_plugin_prettier() 8 | } 9 | \description{ 10 | Add the \href{https://www.npmjs.com/package/prettier-webpack-plugin}{prettier-webpack-plugin} to 11 | prettify the pre-bundled files. 12 | } 13 | -------------------------------------------------------------------------------- /tests/testthat/test-bare: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Bare", { 6 | 7 | # keep working directory 8 | wd <- getwd() 9 | 10 | # test bare 11 | pkg <- create_tmp_package() 12 | setwd(pkg) 13 | on.exit({ 14 | setwd(wd) 15 | delete_tmp_package(pkg) 16 | }) 17 | expect_output(scaffold_bare(edit = FALSE)) 18 | expect_error(scaffold_bare(edit = FALSE)) 19 | }) 20 | -------------------------------------------------------------------------------- /R/workflows.R: -------------------------------------------------------------------------------- 1 | #' Github Actions 2 | #' 3 | #' Adds a Github Action to the package that will ensure 4 | #' JavaScript files have been bundled for production. 5 | #' 6 | #' @export 7 | include_action_check <- function() { 8 | file <- pkg_file("hooks/check.yml") 9 | fs::dir_create(".github/workflows", recurse = TRUE) 10 | fs::file_copy(file, ".github/workflows/packer-check.yml") 11 | usethis::use_build_ignore(".github/") 12 | } 13 | -------------------------------------------------------------------------------- /docs/references/mockup.md: -------------------------------------------------------------------------------- 1 | # `mockup` 2 | 3 | Mock up 4 | 5 | 6 | ## Description 7 | 8 | Functions to mock up packages for tests 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | tmp_package() 15 | tmp_golem() 16 | tmp_project() 17 | tmp_ambiorix() 18 | tmp_delete(tmp) 19 | ``` 20 | 21 | 22 | ## Arguments 23 | 24 | Argument |Description 25 | ------------- |---------------- 26 | `tmp` | A temp mock up project. 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/references/yarn_version.md: -------------------------------------------------------------------------------- 1 | # `yarn_version` 2 | 3 | Npm version 4 | 5 | 6 | ## Description 7 | 8 | Get the version of npm. 9 | 10 | Get the version of yarn. 11 | 12 | 13 | ## Usage 14 | 15 | ```r 16 | yarn_version() 17 | yarn_version() 18 | ``` 19 | 20 | 21 | ## Value 22 | 23 | The semver as a string. 24 | 25 | The semver as a string. 26 | 27 | 28 | ## Examples 29 | 30 | ```r 31 | yarn_version() 32 | ``` 33 | 34 | 35 | -------------------------------------------------------------------------------- /inst/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Hello Packer! 10 | 11 | 12 |

Hello packer

13 | 14 | -------------------------------------------------------------------------------- /man/use_loader_pug.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_pug} 4 | \alias{use_loader_pug} 5 | \title{Use Pug Loader} 6 | \usage{ 7 | use_loader_pug(test = "\\\\.pug$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the loader for the pug templating engine. 14 | } 15 | -------------------------------------------------------------------------------- /man/use_loader_svelte.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_svelte} 4 | \alias{use_loader_svelte} 5 | \title{Use Svelte Loader} 6 | \usage{ 7 | use_loader_svelte(test = "\\\\.(html|svelte)$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Add the loader svelte 14 | } 15 | -------------------------------------------------------------------------------- /tests/testthat/test-bare.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("bare", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_package() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | expect_output(scaffold_bare(edit = FALSE)) 17 | expect_error(scaffold_bare(edit = FALSE)) 18 | expect_message(bundle_dev()) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-windy.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("windy", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_package() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | expect_output(scaffold_bare(edit = FALSE)) 17 | expect_error(scaffold_bare(edit = FALSE)) 18 | expect_message(bundle_dev()) 19 | }) 20 | -------------------------------------------------------------------------------- /man/use_loader_ts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_ts} 4 | \alias{use_loader_ts} 5 | \title{Use Typescript Loader} 6 | \usage{ 7 | use_loader_ts(test = "\\\\.tsx?$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the loader for the pug templating engine. 14 | } 15 | -------------------------------------------------------------------------------- /man/checks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checks.R 3 | \name{checks} 4 | \alias{checks} 5 | \title{Checks} 6 | \usage{ 7 | checks() 8 | } 9 | \description{ 10 | Run checks on a package using packer. 11 | } 12 | \section{Checks}{ 13 | 14 | \itemize{ 15 | \item Output files are minified 16 | \item \link{put_precommit_hook} is in place 17 | \item \link{put_rprofile_adapt} is in place 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /docs/references/put_precommit_hook.md: -------------------------------------------------------------------------------- 1 | # `put_precommit_hook` 2 | 3 | Put Pre-Commit Hook 4 | 5 | 6 | ## Description 7 | 8 | Add a pre-commit hook that runs at every commit 9 | to ensure that JavaScript files are minified. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | put_precommit_hook() 16 | ``` 17 | 18 | 19 | ## Note 20 | 21 | Will only work if using git. 22 | 23 | 24 | ## Examples 25 | 26 | ```r 27 | put_precommit_hook() 28 | ``` 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/references/use_loader_svelte.md: -------------------------------------------------------------------------------- 1 | # `use_loader_svelte` 2 | 3 | Use Svelte Loader 4 | 5 | 6 | ## Description 7 | 8 | Add the loader svelte 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_svelte(test = "\\.(html|svelte)$") 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/references/use_loader_pug.md: -------------------------------------------------------------------------------- 1 | # `use_loader_pug` 2 | 3 | Use Pug Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the loader for the pug templating engine. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_pug(test = "\\.pug$") 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/references/use_loader_ts.md: -------------------------------------------------------------------------------- 1 | # `use_loader_ts` 2 | 3 | Use Typescript Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the loader for the pug templating engine. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_ts(test = "\\.tsx?$") 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | 24 | 25 | -------------------------------------------------------------------------------- /man/put_rprofile_adapt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checks.R 3 | \name{put_rprofile_adapt} 4 | \alias{put_rprofile_adapt} 5 | \title{Rprofile} 6 | \usage{ 7 | put_rprofile_adapt() 8 | } 9 | \description{ 10 | Add \code{\link[=engine_adapt]{engine_adapt()}} to \code{.Rprofile}. 11 | } 12 | \details{ 13 | This is recommended so anyone contributing to 14 | the project is guaranteed to be on the correct 15 | engine. 16 | } 17 | -------------------------------------------------------------------------------- /man/yarn_version.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R, R/yarn.R 3 | \name{yarn_version} 4 | \alias{yarn_version} 5 | \title{Npm version} 6 | \usage{ 7 | yarn_version() 8 | 9 | yarn_version() 10 | } 11 | \value{ 12 | The semver as a string. 13 | 14 | The semver as a string. 15 | } 16 | \description{ 17 | Get the version of npm. 18 | 19 | Get the version of yarn. 20 | } 21 | \examples{ 22 | \dontrun{ 23 | yarn_version() 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /docs/references/yarn_global.md: -------------------------------------------------------------------------------- 1 | # `yarn_global` 2 | 3 | Yarn Global 4 | 5 | 6 | ## Description 7 | 8 | Installs or manage yarn globally . 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | engine_yarn_install() 15 | engine_yarn_set(version = "latest") 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `version` | Version to set yarn 24 | 25 | 26 | ## Examples 27 | 28 | ```r 29 | engine_yarn_install() 30 | ``` 31 | 32 | 33 | -------------------------------------------------------------------------------- /man/use_tailwind.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tailwind.R 3 | \name{use_tailwind} 4 | \alias{use_tailwind} 5 | \title{Use Tailwind} 6 | \usage{ 7 | use_tailwind(test = "\\\\.css$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Creates PostCSS, and tailwindcss config files as well 14 | as adds the appropriate loaders and installs dependencies. 15 | } 16 | -------------------------------------------------------------------------------- /docs/references/bundle.md: -------------------------------------------------------------------------------- 1 | # `bundle` 2 | 3 | bundle & Watch 4 | 5 | 6 | ## Description 7 | 8 | Bundle and watch the JavaScript. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | bundle(mode = c("production", "development", "none")) 15 | bundle_prod() 16 | bundle_dev() 17 | watch() 18 | ``` 19 | 20 | 21 | ## Arguments 22 | 23 | Argument |Description 24 | ------------- |---------------- 25 | `mode` | The configuration mode tells webpack to use its built-in optimisations accordingly. 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/3.6.1/workbox-sw.js' 3 | ) 4 | 5 | const ALLOWED_HOSTS = [ 6 | // The domain to load markdown files 7 | location.host, 8 | // The domain to load docute 9 | 'unpkg.com' 10 | ] 11 | 12 | const matchCb = ({ url, event }) => { 13 | return event.request.method === 'GET' && ALLOWED_HOSTS.includes(url.host) 14 | } 15 | 16 | workbox.routing.registerRoute( 17 | matchCb, 18 | workbox.strategies.networkFirst() 19 | ) 20 | -------------------------------------------------------------------------------- /inst/output/javascript/output.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | import 'shiny'; 3 | 4 | var #name#Binding = new Shiny.OutputBinding(); 5 | 6 | $.extend(#name#Binding, { 7 | find: (scope) => { 8 | return $(scope).find(".#name#"); 9 | }, 10 | getId: (el) => { 11 | return el.id; 12 | }, 13 | renderValue: (el, data) => { 14 | $(el).html(data.html); 15 | $(el).css('color', data.color); 16 | } 17 | }); 18 | 19 | Shiny.outputBindings.register(#name#Binding, "#pkgname#.#name#Binding"); 20 | -------------------------------------------------------------------------------- /man/put_precommit_hook.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/checks.R 3 | \name{put_precommit_hook} 4 | \alias{put_precommit_hook} 5 | \title{Put Pre-Commit Hook} 6 | \usage{ 7 | put_precommit_hook() 8 | } 9 | \description{ 10 | Add a pre-commit hook that runs at every commit 11 | to ensure that JavaScript files are minified. 12 | } 13 | \note{ 14 | Will only work if using git. 15 | } 16 | \examples{ 17 | \dontrun{ 18 | put_precommit_hook() 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /man/set_npm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{set_npm} 4 | \alias{set_npm} 5 | \title{Set npm path} 6 | \usage{ 7 | set_npm(path = NULL) 8 | } 9 | \arguments{ 10 | \item{path}{Path to npm installation to use.} 11 | } 12 | \description{ 13 | By default packer looks for the npm installation using 14 | the \code{which} (or \code{where}) command. 15 | This function lets you override that behaviour and 16 | force a specific npm installation. 17 | } 18 | -------------------------------------------------------------------------------- /man/set_yarn.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{set_yarn} 4 | \alias{set_yarn} 5 | \title{Set yarn path} 6 | \usage{ 7 | set_yarn(path = NULL) 8 | } 9 | \arguments{ 10 | \item{path}{Path to yarn installation to use.} 11 | } 12 | \description{ 13 | By default packer looks for the yarn installation using 14 | the \code{which} (or \code{where}) command. 15 | This function lets you override that behaviour and 16 | force a specific yarn installation. 17 | } 18 | -------------------------------------------------------------------------------- /tests/testthat/test-widget.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Widget", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # create package and 10 | pkg <- create_tmp_package() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | 17 | expect_error(scaffold_widget()) 18 | expect_output(scaffold_widget("writeH1", edit = FALSE)) 19 | expect_output(scaffold_widget("writeH2", edit = FALSE)) 20 | expect_message(bundle()) 21 | }) 22 | -------------------------------------------------------------------------------- /docs/references/use_tailwind.md: -------------------------------------------------------------------------------- 1 | # `use_tailwind` 2 | 3 | Use Tailwind 4 | 5 | 6 | ## Description 7 | 8 | Creates PostCSS, and tailwindcss config files as well 9 | as adds the appropriate loaders and installs dependencies. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | use_tailwind(test = "\\.css$") 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `test` | Test regular expression test which files should be transformed by the loader. 24 | 25 | 26 | -------------------------------------------------------------------------------- /docs/references/set_npm.md: -------------------------------------------------------------------------------- 1 | # `set_npm` 2 | 3 | Set npm path 4 | 5 | 6 | ## Description 7 | 8 | By default packer looks for the npm installation using 9 | the `which` (or `where` ) command. 10 | This function lets you override that behaviour and 11 | force a specific npm installation. 12 | 13 | 14 | ## Usage 15 | 16 | ```r 17 | set_npm(path = NULL) 18 | ``` 19 | 20 | 21 | ## Arguments 22 | 23 | Argument |Description 24 | ------------- |---------------- 25 | `path` | Path to npm installation to use. 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/references/set_yarn.md: -------------------------------------------------------------------------------- 1 | # `set_yarn` 2 | 3 | Set yarn path 4 | 5 | 6 | ## Description 7 | 8 | By default packer looks for the yarn installation using 9 | the `which` (or `where` ) command. 10 | This function lets you override that behaviour and 11 | force a specific yarn installation. 12 | 13 | 14 | ## Usage 15 | 16 | ```r 17 | set_yarn(path = NULL) 18 | ``` 19 | 20 | 21 | ## Arguments 22 | 23 | Argument |Description 24 | ------------- |---------------- 25 | `path` | Path to yarn installation to use. 26 | 27 | 28 | -------------------------------------------------------------------------------- /inst/templates/framework7/app_ui.R: -------------------------------------------------------------------------------- 1 | #' The application User-Interface 2 | #' 3 | #' @param request Internal parameter for `{shiny}`. 4 | #' DO NOT REMOVE. 5 | #' @param title Page title. 6 | #' @import shiny 7 | #' @noRd 8 | app_ui <- function(request, title = NULL) { 9 | tagList( 10 | # Leave this function for adding external resources 11 | golem_add_external_resources(title), 12 | # Your application UI logic 13 | tags$body( 14 | div(id = "app"), 15 | tags$script(src = "www/index.js") 16 | ) 17 | ) 18 | } 19 | -------------------------------------------------------------------------------- /man/mockup.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mock.R 3 | \name{mockup} 4 | \alias{mockup} 5 | \alias{tmp_package} 6 | \alias{tmp_golem} 7 | \alias{tmp_project} 8 | \alias{tmp_ambiorix} 9 | \alias{tmp_delete} 10 | \title{Mock up} 11 | \usage{ 12 | tmp_package() 13 | 14 | tmp_golem() 15 | 16 | tmp_project() 17 | 18 | tmp_ambiorix() 19 | 20 | tmp_delete(tmp) 21 | } 22 | \arguments{ 23 | \item{tmp}{A temp mock up project.} 24 | } 25 | \description{ 26 | Functions to mock up packages for tests 27 | } 28 | -------------------------------------------------------------------------------- /docs/references/apply_framework7.md: -------------------------------------------------------------------------------- 1 | # `apply_framework7` 2 | 3 | Apply Framework7 4 | 5 | 6 | ## Description 7 | 8 | Apply Framework7 to a project, adds the relevant (babel) loader, installs dependencies, 9 | and creates, or updates, or replaces the `srcjs/index.js` file. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | apply_framework7() 16 | ``` 17 | 18 | 19 | ## Details 20 | 21 | After running this function and bundling the JavaScript remember to place 22 | div(id = "app"), tags$script(src = "www/index.js") at the bottom of your shiny UI. 23 | 24 | 25 | -------------------------------------------------------------------------------- /R/ambiorix-utils.R: -------------------------------------------------------------------------------- 1 | #' Golem JavaScript Files 2 | #' 3 | #' Creates the necessary `srcjs` directory and children JavaScript files. 4 | #' This is a simple copy of template files: no changes required. 5 | #' 6 | #' @inheritParams scaffol_golem 7 | #' 8 | #' @noRd 9 | #' @keywords internal 10 | ambiorix_files <- function(vue = FALSE) { 11 | base <- pkg_file("ambiorix/javascript") 12 | 13 | if (vue) { 14 | fs::dir_create("srcjs") 15 | } else { 16 | fs::dir_copy(base, "srcjs") 17 | } 18 | 19 | cli::cli_alert_success("Created {.file srcjs} directory") 20 | } 21 | -------------------------------------------------------------------------------- /docs/references/use_loader_file.md: -------------------------------------------------------------------------------- 1 | # `use_loader_file` 2 | 3 | Use File Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the [list("file-loader")](https://webpack.js.org/loaders/file-loader/) 9 | to resolve files: `png` , `jpg` , `jpeg` , and `gif` . 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | use_loader_file(test = "\\.(png|jpe?g|gif)$/i") 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `test` | Test regular expression test which files should be transformed by the loader. 24 | 25 | 26 | -------------------------------------------------------------------------------- /man/use_loader_file.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_file} 4 | \alias{use_loader_file} 5 | \title{Use File Loader} 6 | \usage{ 7 | use_loader_file(test = "\\\\.(png|jpe?g|gif)$/i") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the \href{https://webpack.js.org/loaders/file-loader/}{\code{file-loader}} 14 | to resolve files: \code{png}, \code{jpg}, \code{jpeg}, and \code{gif}. 15 | } 16 | -------------------------------------------------------------------------------- /man/use_loader_mocha.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_mocha} 4 | \alias{use_loader_mocha} 5 | \title{Use Mocha Loader} 6 | \usage{ 7 | use_loader_mocha(test = "\\\\.test\\\\.js$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the \href{https://webpack.js.org/loaders/mocha-loader/}{\code{mocha-loader}} for tests. 14 | } 15 | \details{ 16 | Excludes \code{node_modules} by default. 17 | } 18 | -------------------------------------------------------------------------------- /docs/references/jsdoc.md: -------------------------------------------------------------------------------- 1 | # `jsdoc` 2 | 3 | Add Plugin jsdoc 4 | 5 | 6 | ## Description 7 | 8 | Add the [jsdoc](https://github.com/jsdoc/jsdoc) 9 | plugin to generate documentation from JavaScript code 10 | with tags similar to roxygen2. 11 | 12 | 13 | ## Usage 14 | 15 | ```r 16 | add_plugin_jsdoc(edit = interactive()) 17 | add_jsdoc_tutorial(name, edit = interactive()) 18 | ``` 19 | 20 | 21 | ## Arguments 22 | 23 | Argument |Description 24 | ------------- |---------------- 25 | `edit` | Whether to open relevent file. 26 | `name` | Name of tutorial 27 | 28 | 29 | -------------------------------------------------------------------------------- /docs/references/use_loader_mocha.md: -------------------------------------------------------------------------------- 1 | # `use_loader_mocha` 2 | 3 | Use Mocha Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the [list("mocha-loader")](https://webpack.js.org/loaders/mocha-loader/) for tests. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_mocha(test = "\\.test\\.js$") 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | 24 | 25 | ## Details 26 | 27 | Excludes `node_modules` by default. 28 | 29 | 30 | -------------------------------------------------------------------------------- /man/use_loader_coffee.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_coffee} 4 | \alias{use_loader_coffee} 5 | \title{Use Coffee Loader} 6 | \usage{ 7 | use_loader_coffee(test = "\\\\.coffee$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the \href{https://webpack.js.org/loaders/coffee-loader/}{\code{coffee-loader}} to use 14 | cofeescript. 15 | } 16 | \details{ 17 | Excludes \code{node_modules} by default. 18 | } 19 | -------------------------------------------------------------------------------- /tests/testthat/test-ouput.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Output", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_package() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | expect_error(scaffold_output()) 17 | expect_output(scaffold_output("out", edit = FALSE)) 18 | expect_error(scaffold_output("out", edit = FALSE)) 19 | expect_message(bundle()) 20 | expect_output(scaffold_output("out_again", edit = FALSE)) 21 | expect_message(bundle()) 22 | }) 23 | -------------------------------------------------------------------------------- /inst/templates/vue/vue_cdn.R: -------------------------------------------------------------------------------- 1 | #' Dependencies for Vue 2 | #' 3 | #' Includes Vue dependencies in a shiny application. 4 | #' 5 | #' @param version Version of Vue to use, if `NULL` uses the latest 6 | #' 7 | #' @keywords internal 8 | vueCDN <- function(version = NULL){ 9 | 10 | version_string <- ".js" 11 | if(!is.null(version)) 12 | version_string <- sprintf("@%d", version) 13 | 14 | vue <- sprintf("https://cdn.jsdelivr.net/npm/vue%s", version_string) 15 | shiny::singleton( 16 | shiny::tags$head( 17 | shiny::tags$script(src = vue, crossorigin = NA) 18 | ) 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /R/leprechaun-files.R: -------------------------------------------------------------------------------- 1 | #' Leprechaun JavaScript Files 2 | #' 3 | #' Creates the necessary `srcjs` directory and children JavaScript files. 4 | #' This is a simple copy of template files: no changes required. 5 | #' 6 | #' @inheritParams scaffold_leprechaun 7 | #' 8 | #' @noRd 9 | #' @keywords internal 10 | leprechaun_files <- function(react = FALSE, vue = FALSE) { 11 | base <- pkg_file("leprechaun") 12 | 13 | if (any(react, vue)) { 14 | fs::dir_create("srcjs") 15 | } else { 16 | fs::dir_copy(base, "srcjs") 17 | } 18 | 19 | cli::cli_alert_success("Created {.file srcjs} directory") 20 | } 21 | -------------------------------------------------------------------------------- /docs/references/use_loader_coffee.md: -------------------------------------------------------------------------------- 1 | # `use_loader_coffee` 2 | 3 | Use Coffee Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the [list("coffee-loader")](https://webpack.js.org/loaders/coffee-loader/) to use 9 | cofeescript. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | use_loader_coffee(test = "\\.coffee$") 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `test` | Test regular expression test which files should be transformed by the loader. 24 | 25 | 26 | ## Details 27 | 28 | Excludes `node_modules` by default. 29 | 30 | 31 | -------------------------------------------------------------------------------- /tests/testthat/test-npm.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("NPM", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_golem() 11 | setwd(pkg) 12 | expect_output(scaffold_golem(edit = FALSE)) 13 | engine_adapt() 14 | # no error 15 | expect_message(npm_install("browserify")) 16 | expect_message(npm_install()) 17 | npm_outdated() 18 | npm_fix() 19 | expect_error(npm_uninstall()) 20 | expect_message(npm_update()) 21 | expect_message(npm_uninstall("browserify")) 22 | setwd(wd) 23 | delete_tmp_package(pkg) 24 | }) 25 | -------------------------------------------------------------------------------- /R/golem-utils.R: -------------------------------------------------------------------------------- 1 | #' Golem JavaScript Files 2 | #' 3 | #' Creates the necessary `srcjs` directory and children JavaScript files. 4 | #' This is a simple copy of template files: no changes required. 5 | #' 6 | #' @inheritParams scaffol_golem 7 | #' 8 | #' @noRd 9 | #' @keywords internal 10 | golem_files <- function(react = FALSE, vue = FALSE, framework7 = FALSE) { 11 | base <- pkg_file("golem/javascript") 12 | 13 | if (any(react, vue, framework7)) { 14 | fs::dir_create("srcjs") 15 | } else { 16 | fs::dir_copy(base, "srcjs") 17 | } 18 | 19 | cli::cli_alert_success("Created {.file srcjs} directory") 20 | } 21 | -------------------------------------------------------------------------------- /man/apply_framework7.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/framework7.R 3 | \name{apply_framework7} 4 | \alias{apply_framework7} 5 | \title{Apply Framework7} 6 | \usage{ 7 | apply_framework7() 8 | } 9 | \description{ 10 | Apply Framework7 to a project, adds the relevant (babel) loader, installs dependencies, 11 | and creates, or updates, or replaces the \code{srcjs/index.js} file. 12 | } 13 | \details{ 14 | After running this function and bundling the JavaScript remember to place 15 | \verb{div(id = "app"), tags$script(src = "www/index.js")} at the bottom of your shiny UI. 16 | } 17 | -------------------------------------------------------------------------------- /tests/testthat/test-ts.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("TypeScript", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_golem() 11 | setwd(pkg) 12 | expect_output(scaffold_golem(edit = FALSE)) 13 | expect_message(use_loader_ts()) 14 | expect_message(ts_shiny_types()) 15 | expect_error(ts_get_types("error", versions = c(1, 2))) 16 | expect_message(ts_get_type("jquery")) 17 | expect_message(ts_get_types("@types/jquery"), versions = "3.5.5") 18 | expect_message(ease_lit(TRUE)) 19 | setwd(wd) 20 | delete_tmp_package(pkg) 21 | }) 22 | -------------------------------------------------------------------------------- /man/jsdoc.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugins.R 3 | \name{jsdoc} 4 | \alias{jsdoc} 5 | \alias{add_plugin_jsdoc} 6 | \alias{add_jsdoc_tutorial} 7 | \title{Add Plugin jsdoc} 8 | \usage{ 9 | add_plugin_jsdoc(edit = interactive()) 10 | 11 | add_jsdoc_tutorial(name, edit = interactive()) 12 | } 13 | \arguments{ 14 | \item{edit}{Whether to open relevent file.} 15 | 16 | \item{name}{Name of tutorial} 17 | } 18 | \description{ 19 | Add the \href{https://github.com/jsdoc/jsdoc}{jsdoc} 20 | plugin to generate documentation from JavaScript code 21 | with tags similar to roxygen2. 22 | } 23 | -------------------------------------------------------------------------------- /docs/references/yarn_install.md: -------------------------------------------------------------------------------- 1 | # `yarn_install` 2 | 3 | Install and Uninstall yarn Packages 4 | 5 | 6 | ## Description 7 | 8 | Install and uninstall yarn packages. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | yarn_add(..., scope = c("dev", "prod")) 15 | yarn_install() 16 | yarn_remove(..., scope = c("dev", "prod")) 17 | ``` 18 | 19 | 20 | ## Arguments 21 | 22 | Argument |Description 23 | ------------- |---------------- 24 | `...` | Packages to install or uninstall. 25 | `scope` | Scope of installation or uninstallation, see scopes. 26 | 27 | 28 | ## Examples 29 | 30 | ```r 31 | yarn_add("browserify") 32 | ``` 33 | 34 | 35 | -------------------------------------------------------------------------------- /inst/widget/javascript/widget.js: -------------------------------------------------------------------------------- 1 | import 'widgets'; 2 | import { asHeader } from '../modules/header.js'; 3 | 4 | HTMLWidgets.widget({ 5 | 6 | name: '#name#', 7 | 8 | type: 'output', 9 | 10 | factory: function(el, width, height) { 11 | 12 | // TODO: define shared variables for this instance 13 | 14 | return { 15 | 16 | renderValue: function(x) { 17 | 18 | // TODO: code to render the widget, e.g. 19 | el.innerHTML = asHeader(x); 20 | 21 | }, 22 | 23 | resize: function(width, height) { 24 | 25 | // TODO: code to re-render the widget with a new size 26 | 27 | } 28 | 29 | }; 30 | } 31 | }); 32 | -------------------------------------------------------------------------------- /docs/references/npm_install.md: -------------------------------------------------------------------------------- 1 | # `npm_install` 2 | 3 | Install and Uninstall Npm Packages 4 | 5 | 6 | ## Description 7 | 8 | Install and uninstall npm packages. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | npm_install(..., scope = c("dev", "prod", "global")) 15 | npm_uninstall(..., scope = c("dev", "prod", "global")) 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `...` | Packages to install or uninstall. If no packages are specified then this function install packages in `package.json` (useful e.g.: after clone). 24 | `scope` | Scope of installation or uninstallation, see scopes. 25 | 26 | 27 | -------------------------------------------------------------------------------- /man/use_loader_framework7.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_framework7} 4 | \alias{use_loader_framework7} 5 | \title{Use Framework7 Loader} 6 | \usage{ 7 | use_loader_framework7(test = "\\\\.(f7).(html|js|jsx)$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the \href{https://www.npmjs.com/package/framework7-loader}{Framework7 loader}. 14 | } 15 | \details{ 16 | Excludes \code{node_modules} by default. If used outside \code{scaffold_golem} 17 | context, installs the babel-loader in the dev scope. 18 | } 19 | -------------------------------------------------------------------------------- /docs/references/use_loader_framework7.md: -------------------------------------------------------------------------------- 1 | # `use_loader_framework7` 2 | 3 | Use Framework7 Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the [Framework7 loader](https://www.npmjs.com/package/framework7-loader) . 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_framework7(test = "\\.(f7).(html|js|jsx)$") 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | 24 | 25 | ## Details 26 | 27 | Excludes `node_modules` by default. If used outside `scaffold_golem` 28 | context, installs the babel-loader in the dev scope. 29 | 30 | 31 | -------------------------------------------------------------------------------- /R/lit.R: -------------------------------------------------------------------------------- 1 | #' Lit 2 | #' 3 | #' Use [Lit](https://lit.dev) in your project. 4 | #' 5 | #' @param ts Whether to use TypeScript (recommended). 6 | #' 7 | #' @export 8 | ease_lit <- function(ts = FALSE) { 9 | engine_install("lit", scope = "prod") 10 | 11 | if (!ts) { 12 | return(invisible()) 13 | } 14 | 15 | # if the ts config file is not found 16 | # it likely means the loader is not in place 17 | if (!fs::file_exists("tsconfig.json")) { 18 | use_loader_ts() 19 | } 20 | 21 | engine_install("typescript", scope = "dev") 22 | 23 | # we use a different config file 24 | fs::file_copy( 25 | pkg_file("lit/config.json"), 26 | "tsconfig.json", 27 | overwrite = TRUE 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /docs/references/types.md: -------------------------------------------------------------------------------- 1 | # `types` 2 | 3 | Install Types 4 | 5 | 6 | ## Description 7 | 8 | Install TypeScript types from npm. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | ts_get_types(..., versions = NULL) 15 | ts_get_type(type, version = NULL) 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `...` | Types to install. 24 | `versions, version` | Corresponding versions of types passed to `...` , if `NULL` the latest version is installed. 25 | `type` | Name of types @types/* to install. 26 | 27 | 28 | ## Examples 29 | 30 | ```r 31 | ts_get_type("jquery") 32 | ts_get_types("@types/jquery") 33 | ``` 34 | 35 | 36 | -------------------------------------------------------------------------------- /man/yarn_global.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_global} 4 | \alias{yarn_global} 5 | \alias{engine_yarn_install} 6 | \alias{engine_yarn_set} 7 | \title{Yarn Global} 8 | \usage{ 9 | engine_yarn_install() 10 | 11 | engine_yarn_set(version = "latest") 12 | } 13 | \arguments{ 14 | \item{version}{Version to set yarn} 15 | } 16 | \description{ 17 | Installs or manage yarn \emph{globally}. 18 | } 19 | \section{Functions}{ 20 | 21 | \itemize{ 22 | \item \code{engine_yarn_install}: Installs yarn globally. 23 | \item \code{engine_yarn_set}: Set yarn function. 24 | } 25 | } 26 | 27 | \examples{ 28 | \dontrun{ 29 | engine_yarn_install() 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /R/extension-utils.R: -------------------------------------------------------------------------------- 1 | #' Extension R Files 2 | #' 3 | #' @param name Name of widget as passed from [scaffold_extension()]. 4 | #' 5 | #' @details Creates `R/zzz.R` file if it does not already exist. 6 | #' 7 | #' @noRd 8 | #' @keywords internal 9 | ext_zzz_file <- function(name) { 10 | pkgname <- get_pkg_name() 11 | 12 | if (fs::file_exists("R/zzz.R")) { 13 | cli::cli_alert_info("{.file R/zzz.R} already exists: assumes path to shiny resource already exists") 14 | return() 15 | } 16 | 17 | # create file 18 | zzz_in <- pkg_file("extension/R/zzz.R") 19 | zzz <- readLines(zzz_in) 20 | zzz <- gsub("#pkgname#", pkgname, zzz) 21 | writeLines(zzz, "R/zzz.R") 22 | cli::cli_alert_success("Added path to shiny resource") 23 | } 24 | -------------------------------------------------------------------------------- /R/npx.R: -------------------------------------------------------------------------------- 1 | #' NPX 2 | #' 3 | #' Run an `npx` command. 4 | #' 5 | #' @param ... Arguments to pass to npx 6 | #' 7 | #' @export 8 | npx <- function(...) { 9 | npx <- npx_find() 10 | system2(npx, args = paste0(..., collapse = " "), stdout = TRUE) 11 | } 12 | 13 | #' NPX Find 14 | #' 15 | #' Find the NPX executable. 16 | #' 17 | #' @noRd 18 | #' @keywords internal 19 | npx_find <- function() { 20 | # which on UNIX and where on Windows 21 | cmd <- which_or_where() 22 | path <- tryCatch( 23 | system2(cmd, "npx", stdout = TRUE), 24 | error = function(e) e 25 | ) 26 | 27 | if (inherits(path, "error")) { 28 | stop("Could not find path to `npx`", call. = FALSE) 29 | } 30 | 31 | # where may return multiple paths 32 | path[1] 33 | } 34 | -------------------------------------------------------------------------------- /man/add_plugin_clean.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugins.R 3 | \name{add_plugin_clean} 4 | \alias{add_plugin_clean} 5 | \title{Clean Plugin} 6 | \usage{ 7 | add_plugin_clean(dry = FALSE, verbose = FALSE, clean = TRUE, protect = TRUE) 8 | } 9 | \arguments{ 10 | \item{dry}{Whether to simulate the removal of files.} 11 | 12 | \item{verbose}{Write Logs to the console.} 13 | 14 | \item{clean}{Whether to automatically remove all unused webpack assets on rebuild.} 15 | 16 | \item{protect}{Whether to not allow removal of current webpack assets.} 17 | } 18 | \description{ 19 | Add the \href{https://www.npmjs.com/package/clean-webpack-plugin}{clean-webpack-plugin} to 20 | clean the bundled files. 21 | } 22 | -------------------------------------------------------------------------------- /tests/testthat/test-ambiorix.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Ambiorix Bare", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_ambiorix() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | expect_output(scaffold_ambiorix(edit = FALSE)) 17 | expect_message(bundle()) 18 | }) 19 | 20 | test_that("Ambiorix Vue", { 21 | # keep working directory 22 | wd <- getwd() 23 | 24 | # test bare 25 | pkg <- create_tmp_ambiorix() 26 | setwd(pkg) 27 | on.exit({ 28 | setwd(wd) 29 | delete_tmp_package(pkg) 30 | }) 31 | expect_output(scaffold_ambiorix(vue = TRUE, edit = FALSE)) 32 | expect_message(bundle()) 33 | }) 34 | -------------------------------------------------------------------------------- /docs/references/add_plugin_clean.md: -------------------------------------------------------------------------------- 1 | # `add_plugin_clean` 2 | 3 | Clean Plugin 4 | 5 | 6 | ## Description 7 | 8 | Add the [clean-webpack-plugin](https://www.npmjs.com/package/clean-webpack-plugin) to 9 | clean the bundled files. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | add_plugin_clean(dry = FALSE, verbose = FALSE, clean = TRUE, protect = TRUE) 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `dry` | Whether to simulate the removal of files. 24 | `verbose` | Write Logs to the console. 25 | `clean` | Whether to automatically remove all unused webpack assets on rebuild. 26 | `protect` | Whether to not allow removal of current webpack assets. 27 | 28 | 29 | -------------------------------------------------------------------------------- /inst/templates/react/react_cdn.R: -------------------------------------------------------------------------------- 1 | #' Dependencies for React 2 | #' 3 | #' Includes React dependencies in a shiny application. 4 | #' 5 | #' @param version Version of React to use, if `NULL` uses the latest 6 | #' 7 | #' @keywords internal 8 | reactCDN <- function(version = 17){ 9 | unpkg <- "https://unpkg.com" 10 | 11 | version_string <- sprintf("@%d", version) 12 | 13 | react <- sprintf("%s/react%s/umd/react.production.min.js", unpkg, version_string) 14 | react_dom <- sprintf("%s/react-dom%s/umd/react-dom.production.min.js", unpkg, version_string) 15 | shiny::singleton( 16 | shiny::tags$head( 17 | shiny::tags$script(src = react, crossorigin = NA), 18 | shiny::tags$script(src = react_dom, crossorigin = NA) 19 | ) 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /tests/testthat/test-extension.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Extension", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # create package and 10 | pkg <- create_tmp_package() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | 17 | expect_error(scaffold_extension()) 18 | expect_output(scaffold_extension("ext", edit = FALSE)) 19 | expect_error(scaffold_extension("ext", edit = FALSE)) 20 | file.create("R/ext2.R") 21 | expect_output(scaffold_extension("ext2", edit = FALSE)) 22 | expect_message(bundle()) 23 | expect_message(use_loader_babel(use_eslint = TRUE)) 24 | expect_message(bundle()) 25 | 26 | # make library 27 | expect_message(make_library("lib")) 28 | }) 29 | -------------------------------------------------------------------------------- /man/use_loader_babel.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_babel} 4 | \alias{use_loader_babel} 5 | \title{Use babel Loader} 6 | \usage{ 7 | use_loader_babel(test = "\\\\.(js|jsx)$", use_eslint = FALSE) 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | 12 | \item{use_eslint}{Whether to also add the ESlint loader.} 13 | } 14 | \description{ 15 | Adds the loader for babel compiler to the loader configuration file. 16 | } 17 | \details{ 18 | The \code{use_elsint} argument is useful here as loaders have 19 | to be defined in the correct order or files might be checked after 20 | being processed by babel. 21 | 22 | Excludes \code{node_modules} by default. 23 | } 24 | -------------------------------------------------------------------------------- /docs/references/use_loader_babel.md: -------------------------------------------------------------------------------- 1 | # `use_loader_babel` 2 | 3 | Use babel Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the loader for babel compiler to the loader configuration file. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_babel(test = "\\.(js|jsx)$", use_eslint = FALSE) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | `use_eslint` | Whether to also add the ESlint loader. 24 | 25 | 26 | ## Details 27 | 28 | The `use_elsint` argument is useful here as loaders have 29 | to be defined in the correct order or files might be checked after 30 | being processed by babel. 31 | 32 | Excludes `node_modules` by default. 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/references/add_plugin_html.md: -------------------------------------------------------------------------------- 1 | # `add_plugin_html` 2 | 3 | HTML Plugin 4 | 5 | 6 | ## Description 7 | 8 | Add the [html-webpack-plugin](https://webpack.js.org/plugins/html-webpack-plugin/) to 9 | the configuration to generate HTML with webpack, used in packer to generate the UI of 10 | a golem app with webpack. 11 | 12 | 13 | ## Usage 14 | 15 | ```r 16 | add_plugin_html(use_pug = FALSE, output_path = "../index.html") 17 | ``` 18 | 19 | 20 | ## Arguments 21 | 22 | Argument |Description 23 | ------------- |---------------- 24 | `use_pug` | Set to `TRUE` to use the [pug engine](https://pugjs.org/) . 25 | `output_path` | Path to the generated html file, defaults to `../index.html` as is ideal for golem. Note that this path is relative to your output directory specified in your `webpack.common.js` file. 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/testthat/test-check.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Checks", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | expect_error(scaffold_leprechaun(edit = FALSE)) 10 | 11 | # test bare 12 | pkg <- create_tmp_package() 13 | setwd(pkg) 14 | expect_output(scaffold_input("test", edit = FALSE)) 15 | bundle_dev() 16 | on.exit({ 17 | setwd(wd) 18 | delete_tmp_package(pkg) 19 | }) 20 | 21 | expect_message(checks()) 22 | expect_error(are_minified()) 23 | expect_message(bundle_dev()) 24 | are_minified("inst/packer") 25 | expect_message(put_precommit_hook()) 26 | 27 | # git 28 | usethis::use_git() 29 | expect_message(put_precommit_hook()) 30 | expect_message(put_precommit_hook()) 31 | 32 | # rprofile 33 | file.create(".Rprofile") 34 | put_rprofile_adapt() 35 | }) 36 | -------------------------------------------------------------------------------- /man/add_plugin_html.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/plugins.R 3 | \name{add_plugin_html} 4 | \alias{add_plugin_html} 5 | \title{HTML Plugin} 6 | \usage{ 7 | add_plugin_html(use_pug = FALSE, output_path = "../index.html") 8 | } 9 | \arguments{ 10 | \item{use_pug}{Set to \code{TRUE} to use the \href{https://pugjs.org/}{pug engine}.} 11 | 12 | \item{output_path}{Path to the generated html file, defaults to \code{../index.html} as 13 | is ideal for golem. Note that this path is relative to your output directory specified 14 | in your \code{webpack.common.js} file.} 15 | } 16 | \description{ 17 | Add the \href{https://webpack.js.org/plugins/html-webpack-plugin/}{html-webpack-plugin} to 18 | the configuration to generate HTML with webpack, used in packer to generate the UI of 19 | a golem app with webpack. 20 | } 21 | -------------------------------------------------------------------------------- /man/use_loader_vue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_vue} 4 | \alias{use_loader_vue} 5 | \title{Use Vue Loader} 6 | \usage{ 7 | use_loader_vue(test = "\\\\.vue$") 8 | } 9 | \arguments{ 10 | \item{test}{Test regular expression test which files should be transformed by the loader.} 11 | } 12 | \description{ 13 | Adds the Vue loader to the loader configuration file. 14 | } 15 | \details{ 16 | Every time a new version of Vue is released, a corresponding version of \code{vue-template-compiler} 17 | is released together. The compiler's version must be in sync with the base Vue package so that \code{vue-loader} 18 | produces code that is compatible with the runtime. This means every time you upgrade Vue in your project, 19 | you should upgrade \code{vue-template-compiler} to match it as well. 20 | } 21 | -------------------------------------------------------------------------------- /docs/references/engine.md: -------------------------------------------------------------------------------- 1 | # `engine` 2 | 3 | Set Engine 4 | 5 | 6 | ## Description 7 | 8 | Defines the engine to use with packer. 9 | One can pick between npm and yarn. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | engine_set(engine = c("npm", "yarn")) 16 | engine_get() 17 | engine_adapt() 18 | engine_which() 19 | ``` 20 | 21 | 22 | ## Arguments 23 | 24 | Argument |Description 25 | ------------- |---------------- 26 | `engine` | The engine to use, npm or yarn. 27 | 28 | 29 | ## Details 30 | 31 | Generally one would want to define 32 | the engine prior to scaffolding. 33 | For convenience you can instead set the environment 34 | variable `PACKER_ENGINE` to your engine of choice. 35 | Packer reads this variable, all subsequent use 36 | of packer will use the defined engine. 37 | You can use the function `usethis::edit_r_environ` 38 | to do so. 39 | 40 | 41 | -------------------------------------------------------------------------------- /docs/references/use_loader_vue.md: -------------------------------------------------------------------------------- 1 | # `use_loader_vue` 2 | 3 | Use Vue Loader 4 | 5 | 6 | ## Description 7 | 8 | Adds the Vue loader to the loader configuration file. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_vue(test = "\\.vue$") 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `test` | Test regular expression test which files should be transformed by the loader. 23 | 24 | 25 | ## Details 26 | 27 | Every time a new version of Vue is released, a corresponding version of `vue-template-compiler` 28 | is released together. The compiler's version must be in sync with the base Vue package so that `vue-loader` 29 | produces code that is compatible with the runtime. This means every time you upgrade Vue in your project, 30 | you should upgrade `vue-template-compiler` to match it as well. 31 | 32 | 33 | -------------------------------------------------------------------------------- /man/yarn_install.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/yarn.R 3 | \name{yarn_install} 4 | \alias{yarn_install} 5 | \alias{yarn_add} 6 | \alias{yarn_remove} 7 | \title{Install and Uninstall yarn Packages} 8 | \usage{ 9 | yarn_add(..., scope = c("dev", "prod")) 10 | 11 | yarn_install() 12 | 13 | yarn_remove(..., scope = c("dev", "prod")) 14 | } 15 | \arguments{ 16 | \item{...}{Packages to install or uninstall.} 17 | 18 | \item{scope}{Scope of installation or uninstallation, see scopes.} 19 | } 20 | \description{ 21 | Install and uninstall yarn packages. 22 | } 23 | \section{Scopes}{ 24 | 25 | \itemize{ 26 | \item \code{prod} - Add/remove packages for project with no flag 27 | \item \code{dev} - Installs/Uninstalls dev packages for project with \code{--dev} 28 | } 29 | } 30 | 31 | \examples{ 32 | \dontrun{ 33 | yarn_add("browserify") 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /man/apply_vue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/vue.R 3 | \name{apply_vue} 4 | \alias{apply_vue} 5 | \title{Apply Vue} 6 | \usage{ 7 | apply_vue(use_cdn = TRUE) 8 | } 9 | \arguments{ 10 | \item{use_cdn}{Whether to use the CDN for \code{vue} (recommended). 11 | This means later importing the dependencies in the shiny UI using \code{vueCDN()}, 12 | this function will be created in a \code{R/vue_cdn.R}. 13 | The correct instructions are printed to the console by the application.} 14 | } 15 | \description{ 16 | Apply Vue to a project, adds the relevant (babel) loader, installs dependencies, 17 | and creates, or updates, or replaces the \code{srcjs/index.js} file. 18 | } 19 | \details{ 20 | After running this function and bundling the JavaScript remember to place 21 | \verb{div(id = "app"), tags$script(src = "www/index.js")} at the bottom of your shiny UI. 22 | } 23 | -------------------------------------------------------------------------------- /docs/references/apply_vue.md: -------------------------------------------------------------------------------- 1 | # `apply_vue` 2 | 3 | Apply Vue 4 | 5 | 6 | ## Description 7 | 8 | Apply Vue to a project, adds the relevant (babel) loader, installs dependencies, 9 | and creates, or updates, or replaces the `srcjs/index.js` file. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | apply_vue(use_cdn = TRUE) 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `use_cdn` | Whether to use the CDN for `vue` (recommended). This means later importing the dependencies in the shiny UI using `vueCDN()` , this function will be created in a `R/vue_cdn.R` . The correct instructions are printed to the console by the application. 24 | 25 | 26 | ## Details 27 | 28 | After running this function and bundling the JavaScript remember to place 29 | div(id = "app"), tags$script(src = "www/index.js") at the bottom of your shiny UI. 30 | 31 | 32 | -------------------------------------------------------------------------------- /tests/testthat/test-rmd.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Rmd", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_project() 11 | setwd(pkg) 12 | expect_output(scaffold_rmd(edit = FALSE)) 13 | expect_message(use_loader_file()) 14 | expect_message(bundle()) 15 | setwd(wd) 16 | delete_tmp_package(pkg) 17 | 18 | # test react 19 | pkg <- create_tmp_project() 20 | setwd(pkg) 21 | expect_output(scaffold_rmd(react = TRUE, edit = FALSE)) 22 | expect_message(use_loader_coffee()) 23 | expect_message(bundle()) 24 | setwd(wd) 25 | delete_tmp_package(pkg) 26 | 27 | # test vue 28 | pkg <- create_tmp_project() 29 | setwd(pkg) 30 | expect_output(scaffold_rmd(vue = TRUE, edit = FALSE)) 31 | expect_message(use_loader_sass()) 32 | expect_message(bundle()) 33 | setwd(wd) 34 | delete_tmp_package(pkg) 35 | }) 36 | -------------------------------------------------------------------------------- /inst/lit/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2019", 4 | "module": "es2020", 5 | "lib": ["es2020", "DOM", "DOM.Iterable"], 6 | "declaration": true, 7 | "declarationMap": true, 8 | "sourceMap": true, 9 | "inlineSources": true, 10 | "outDir": "./", 11 | "rootDir": "./src", 12 | "strict": true, 13 | "noUnusedLocals": true, 14 | "noUnusedParameters": true, 15 | "noImplicitReturns": true, 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitAny": true, 18 | "noImplicitThis": true, 19 | "moduleResolution": "node", 20 | "allowSyntheticDefaultImports": true, 21 | "experimentalDecorators": true, 22 | "forceConsistentCasingInFileNames": true, 23 | "plugins": [ 24 | { 25 | "name": "ts-lit-plugin", 26 | "strict": true 27 | } 28 | ] 29 | }, 30 | "include": ["srcjs/**/*.ts"], 31 | "exclude": [] 32 | } 33 | -------------------------------------------------------------------------------- /inst/templates/framework7/components/app.f7.jsx: -------------------------------------------------------------------------------- 1 | export default (props, { $f7 }) => { 2 | const title = 'Hello World'; 3 | 4 | return () => ( 5 |
6 |
7 |
8 | 14 |
15 |
16 | Link 1 17 | Link 2 18 |
19 |
20 |
21 |
22 | Page Content 23 |
24 |
25 |
26 |
27 |
28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /docs/references/use_loader_rule.md: -------------------------------------------------------------------------------- 1 | # `use_loader_rule` 2 | 3 | Add a Loader rule 4 | 5 | 6 | ## Description 7 | 8 | Adds a loader rule that is not yet implemented in packer. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | use_loader_rule( 15 | packages, 16 | test, 17 | ..., 18 | use = as.list(packages), 19 | .name_use = "use" 20 | ) 21 | ``` 22 | 23 | 24 | ## Arguments 25 | 26 | Argument |Description 27 | ------------- |---------------- 28 | `packages` | NPM packages (loaders) to install. 29 | `test` | Test regular expression test which files should be transformed by the loader. 30 | `...` | Any other options to pass to the rule. 31 | `use` | Name of the loaders to use for `test` . 32 | `.name_use` | Depending on the webpack config one might want to change the `use` to `loader` or `loaders` . 33 | 34 | 35 | ## Details 36 | 37 | Reads the `srcjs/config/loaders.json` and appends the rule. 38 | 39 | 40 | -------------------------------------------------------------------------------- /man/use_loader_rule.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_rule} 4 | \alias{use_loader_rule} 5 | \title{Add a Loader rule} 6 | \usage{ 7 | use_loader_rule( 8 | packages, 9 | test, 10 | ..., 11 | use = as.list(packages), 12 | .name_use = "use" 13 | ) 14 | } 15 | \arguments{ 16 | \item{packages}{NPM packages (loaders) to install.} 17 | 18 | \item{test}{Test regular expression test which files should be transformed by the loader.} 19 | 20 | \item{...}{Any other options to pass to the rule.} 21 | 22 | \item{use}{Name of the loaders to use for \code{test}.} 23 | 24 | \item{.name_use}{Depending on the webpack config 25 | one might want to change the \code{use} to \code{loader} or \code{loaders}.} 26 | } 27 | \description{ 28 | Adds a loader rule that is not yet implemented in packer. 29 | } 30 | \details{ 31 | Reads the \code{srcjs/config/loaders.json} and appends the rule. 32 | } 33 | -------------------------------------------------------------------------------- /tests/testthat/test-leprechaun.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Leprechaun", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | expect_error(scaffold_leprechaun(edit = FALSE)) 10 | 11 | # test bare 12 | pkg <- create_tmp_package() 13 | setwd(pkg) 14 | expect_error(scaffold_leprechaun(edit = FALSE)) 15 | file.create(".leprechaun") 16 | expect_error(scaffold_leprechaun(vue = TRUE, react = TRUE, edit = FALSE)) 17 | expect_output(scaffold_leprechaun(edit = FALSE)) 18 | expect_error(scaffold_leprechaun(edit = FALSE)) 19 | expect_message(use_loader_svelte()) 20 | setwd(wd) 21 | delete_tmp_package(pkg) 22 | }) 23 | 24 | test_that("Leprechaun Vue", { 25 | # keep working directory 26 | wd <- getwd() 27 | 28 | pkg <- create_tmp_package() 29 | setwd(pkg) 30 | file.create(".leprechaun") 31 | expect_output(scaffold_leprechaun(vue = TRUE, edit = FALSE)) 32 | setwd(wd) 33 | delete_tmp_package(pkg) 34 | }) 35 | -------------------------------------------------------------------------------- /man/types.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/typescript.R 3 | \name{types} 4 | \alias{types} 5 | \alias{ts_get_types} 6 | \alias{ts_get_type} 7 | \title{Install Types} 8 | \usage{ 9 | ts_get_types(..., versions = NULL) 10 | 11 | ts_get_type(type, version = NULL) 12 | } 13 | \arguments{ 14 | \item{...}{Types to install.} 15 | 16 | \item{versions, version}{Corresponding versions of types passed 17 | to \code{...}, if \code{NULL} the latest version is installed.} 18 | 19 | \item{type}{Name of types \verb{@types/*} to install.} 20 | } 21 | \description{ 22 | Install TypeScript types from npm. 23 | } 24 | \section{Functions}{ 25 | 26 | \itemize{ 27 | \item \code{ts_get_types}: Flexible to retrieve multiple types. 28 | \item \code{ts_get_type}: Convenience to easily retrieve a single type. 29 | } 30 | } 31 | 32 | \examples{ 33 | \dontrun{ 34 | ts_get_type("jquery") 35 | } 36 | \dontrun{ 37 | ts_get_types("@types/jquery") 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /man/make_library.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/library.R 3 | \name{make_library} 4 | \alias{make_library} 5 | \title{Make Library} 6 | \usage{ 7 | make_library(name = "[name]", type = "umd") 8 | } 9 | \arguments{ 10 | \item{name}{Name of the library, default recommended, 11 | see details.} 12 | 13 | \item{type}{Type of the library.} 14 | } 15 | \description{ 16 | Adds library settings to webpack config. 17 | This allow exporting JavaScript objects. 18 | } 19 | \details{ 20 | The functions will be exported 21 | at the specified \code{name}, e.g.: if 22 | the name is \code{myLib} then functions can be 23 | called with \code{myLib.function();}. 24 | The default (\verb{[name]}) means the name of the exported 25 | library will be the same as the name of the scaffold. 26 | This is advised because otherwise, if one has multiple 27 | scaffold, an absolute will overwrite itself and only 28 | the last scaffold added will be a valid library. 29 | } 30 | -------------------------------------------------------------------------------- /docs/references/make_library.md: -------------------------------------------------------------------------------- 1 | # `make_library` 2 | 3 | Make Library 4 | 5 | 6 | ## Description 7 | 8 | Adds library settings to webpack config. 9 | This allow exporting JavaScript objects. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | make_library(name = "[name]", type = "umd") 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `name` | Name of the library, default recommended, see details. 24 | `type` | Type of the library. 25 | 26 | 27 | ## Details 28 | 29 | The functions will be exported 30 | at the specified `name` , e.g.: if 31 | the name is `myLib` then functions can be 32 | called with `myLib.function();` . 33 | The default ( [name] ) means the name of the exported 34 | library will be the same as the name of the scaffold. 35 | This is advised because otherwise, if one has multiple 36 | scaffold, an absolute will overwrite itself and only 37 | the last scaffold added will be a valid library. 38 | 39 | 40 | -------------------------------------------------------------------------------- /man/npm_install.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/npm.R 3 | \name{npm_install} 4 | \alias{npm_install} 5 | \alias{npm_uninstall} 6 | \title{Install and Uninstall Npm Packages} 7 | \usage{ 8 | npm_install(..., scope = c("dev", "prod", "global")) 9 | 10 | npm_uninstall(..., scope = c("dev", "prod", "global")) 11 | } 12 | \arguments{ 13 | \item{...}{Packages to install or uninstall. If no packages 14 | are specified then this function install packages in 15 | \code{package.json} (useful e.g.: after clone).} 16 | 17 | \item{scope}{Scope of installation or uninstallation, see scopes.} 18 | } 19 | \description{ 20 | Install and uninstall npm packages. 21 | } 22 | \section{Scopes}{ 23 | 24 | \itemize{ 25 | \item \code{prod} - Installs/Uninstalls packages for project with \code{--save} 26 | \item \code{dev} - Installs/Uninstalls dev packages for project with \code{--save-dev} 27 | \item \code{global} - Installs/Uninstalls packages globally with \code{-g} 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /tests/testthat/test-input.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Input", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | expect_error(scaffold_input()) 10 | 11 | # test bare 12 | pkg <- create_tmp_package() 13 | setwd(pkg) 14 | expect_error(scaffold_input()) 15 | expect_output(scaffold_input("increment", edit = FALSE)) 16 | expect_error(scaffold_input("increment", edit = FALSE)) 17 | expect_message(bundle_prod()) 18 | expect_message(npm_install()) 19 | expect_output(scaffold_input("increment_again", edit = FALSE)) 20 | expect_message(bundle_dev()) 21 | expect_message(use_loader_babel()) 22 | setwd(wd) 23 | delete_tmp_package(pkg) 24 | }) 25 | 26 | test_that("Input React", { 27 | # keep working directory 28 | wd <- getwd() 29 | 30 | # test bare 31 | pkg <- create_tmp_package() 32 | setwd(pkg) 33 | expect_output(scaffold_input("incremental", edit = FALSE)) 34 | expect_message(apply_react()) 35 | setwd(wd) 36 | delete_tmp_package(pkg) 37 | }) 38 | -------------------------------------------------------------------------------- /man/scaffold_bare.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bare.R 3 | \name{scaffold_bare} 4 | \alias{scaffold_bare} 5 | \title{Bare} 6 | \usage{ 7 | scaffold_bare(edit = NULL) 8 | } 9 | \arguments{ 10 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 11 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 12 | Otherwise takes a boolean.} 13 | } 14 | \value{ 15 | \code{TRUE} (invisibly) if successfully run. 16 | } 17 | \description{ 18 | Creates a bare scaffold for no specific use case, as 19 | opposed to other scaffolds. This scaffold does not 20 | generate R code. 21 | } 22 | \examples{ 23 | if (interactive()) { 24 | # current directory 25 | wd <- getwd() 26 | 27 | # create a mock up ambiorix project 28 | tmp <- tmp_package() 29 | 30 | # move to package 31 | setwd(tmp) 32 | 33 | # scaffold bare 34 | scaffold_bare() 35 | 36 | # clean up 37 | setwd(wd) 38 | tmp_delete(tmp) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /R/mock.R: -------------------------------------------------------------------------------- 1 | #' Mock up 2 | #' 3 | #' Functions to mock up packages for tests 4 | #' 5 | #' @param tmp A temp mock up project. 6 | #' 7 | #' @name mockup 8 | #' 9 | #' @export 10 | tmp_package <- function() { 11 | tmp <- tempdir() 12 | usethis::create_package(tmp) 13 | return(tmp) 14 | } 15 | 16 | #' @rdname mockup 17 | #' @export 18 | tmp_golem <- function() { 19 | tmp <- tempdir() 20 | golem::create_golem(tmp) 21 | return(tmp) 22 | } 23 | 24 | #' @rdname mockup 25 | #' @export 26 | tmp_project <- function() { 27 | tmp <- tempdir() 28 | usethis::create_project(tmp) 29 | return(tmp) 30 | } 31 | 32 | #' @rdname mockup 33 | #' @export 34 | tmp_ambiorix <- function() { 35 | tmp <- tempdir() 36 | usethis::create_project(tmp) 37 | dir.create(sprintf("%s/templates", tmp)) 38 | dir.create(sprintf("%s/assets", tmp)) 39 | file.create(sprintf("%s/app.R", tmp)) 40 | return(tmp) 41 | } 42 | 43 | #' @rdname mockup 44 | #' @export 45 | tmp_delete <- function(tmp) { 46 | unlink(tmp, recursive = TRUE, force = TRUE) 47 | } 48 | -------------------------------------------------------------------------------- /docs/references/scaffold_bare.md: -------------------------------------------------------------------------------- 1 | # `scaffold_bare` 2 | 3 | Bare 4 | 5 | 6 | ## Description 7 | 8 | Creates a bare scaffold for no specific use case, as 9 | opposed to other scaffolds. This scaffold does not 10 | generate R code. 11 | 12 | 13 | ## Usage 14 | 15 | ```r 16 | scaffold_bare(edit = NULL) 17 | ``` 18 | 19 | 20 | ## Arguments 21 | 22 | Argument |Description 23 | ------------- |---------------- 24 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 25 | 26 | 27 | ## Value 28 | 29 | `TRUE` (invisibly) if successfully run. 30 | 31 | 32 | ## Examples 33 | 34 | ```r 35 | if (interactive()) { 36 | # current directory 37 | wd <- getwd() 38 | 39 | # create a mock up ambiorix project 40 | tmp <- tmp_package() 41 | 42 | # move to package 43 | setwd(tmp) 44 | 45 | # scaffold bare 46 | scaffold_bare() 47 | 48 | # clean up 49 | setwd(wd) 50 | tmp_delete(tmp) 51 | } 52 | ``` 53 | 54 | 55 | -------------------------------------------------------------------------------- /inst/templates/framework7/golem_add_external_resources.R: -------------------------------------------------------------------------------- 1 | #' Add external Resources to the Application 2 | #' 3 | #' This function is internally used to add external 4 | #' resources inside the Shiny application. 5 | #' 6 | #' @import shiny 7 | #' @importFrom golem add_resource_path activate_js favicon bundle_resources 8 | #' @noRd 9 | golem_add_external_resources <- function(title){ 10 | 11 | add_resource_path( 12 | 'www', app_sys('app/www') 13 | ) 14 | 15 | # Optimized for mobile rendering and PWA 16 | tags$head( 17 | favicon(), 18 | tags$meta(charset = "utf-8"), 19 | tags$meta( 20 | name = "viewport", 21 | content = "width=device-width, initial-scale=1, 22 | maximum-scale=1, minimum-scale=1, user-scalable=no, 23 | viewport-fit=cover" 24 | ), 25 | tags$meta( 26 | name = "apple-mobile-web-app-capable", 27 | content = "yes" 28 | ), 29 | tags$meta( 30 | name = "theme-color", 31 | content = "#2196f3" 32 | ), 33 | tags$title(title) 34 | ) 35 | } 36 | -------------------------------------------------------------------------------- /inst/input/javascript/input.js: -------------------------------------------------------------------------------- 1 | import $ from 'jquery'; 2 | import 'shiny'; 3 | 4 | $(document).on("click", "button.#name#Binding", (evt) => { 5 | // evt.target is the button that was clicked 6 | var el = $(evt.target); 7 | 8 | // Set the button's text to its current value plus 1 9 | el.text(parseInt(el.text()) + 1); 10 | 11 | // Raise an event to signal that the value changed 12 | el.trigger("change"); 13 | }); 14 | 15 | var #name#Binding = new Shiny.InputBinding(); 16 | 17 | $.extend(#name#Binding, { 18 | find: (scope) => { 19 | return $(scope).find(".#name#Binding"); 20 | }, 21 | getValue: (el) => { 22 | return parseInt($(el).text()); 23 | }, 24 | setValue: (el, value) => { 25 | $(el).text(value); 26 | }, 27 | subscribe: (el, callback) => { 28 | $(el).on("change.#name#Binding", function(e) { 29 | callback(); 30 | }); 31 | }, 32 | unsubscribe: (el) => { 33 | $(el).off(".#name#Binding"); 34 | } 35 | }); 36 | 37 | Shiny.inputBindings.register(#name#Binding, "#pkgname#.#name#Binding"); 38 | -------------------------------------------------------------------------------- /man/scaffold_windy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/windy.R 3 | \name{scaffold_windy} 4 | \alias{scaffold_windy} 5 | \title{Windy} 6 | \usage{ 7 | scaffold_windy(edit = NULL) 8 | } 9 | \arguments{ 10 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 11 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 12 | Otherwise takes a boolean.} 13 | } 14 | \value{ 15 | \code{TRUE} (invisibly) if successfully run. 16 | } 17 | \description{ 18 | Creates a scaffold for \href{https://github.com/devOpifex/windy}{windy}, 19 | it's a modified version of \code{\link[=scaffold_bare]{scaffold_bare()}}. 20 | } 21 | \examples{ 22 | if (interactive()) { 23 | # current directory 24 | wd <- getwd() 25 | 26 | # create a mock up ambiorix project 27 | tmp <- tmp_package() 28 | 29 | # move to package 30 | setwd(tmp) 31 | 32 | # scaffold bare 33 | scaffold_windy() 34 | 35 | # clean up 36 | setwd(wd) 37 | tmp_delete(tmp) 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /docs/references/scaffold_windy.md: -------------------------------------------------------------------------------- 1 | # `scaffold_windy` 2 | 3 | Windy 4 | 5 | 6 | ## Description 7 | 8 | Creates a scaffold for [windy](https://github.com/devOpifex/windy) , 9 | it's a modified version of [`scaffold_bare()`](#scaffoldbare()) . 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | scaffold_windy(edit = NULL) 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 24 | 25 | 26 | ## Value 27 | 28 | `TRUE` (invisibly) if successfully run. 29 | 30 | 31 | ## Examples 32 | 33 | ```r 34 | if (interactive()) { 35 | # current directory 36 | wd <- getwd() 37 | 38 | # create a mock up ambiorix project 39 | tmp <- tmp_package() 40 | 41 | # move to package 42 | setwd(tmp) 43 | 44 | # scaffold bare 45 | scaffold_windy() 46 | 47 | # clean up 48 | setwd(wd) 49 | tmp_delete(tmp) 50 | } 51 | ``` 52 | 53 | 54 | -------------------------------------------------------------------------------- /man/scaffold_input.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/input.R 3 | \name{scaffold_input} 4 | \alias{scaffold_input} 5 | \title{Scaffold a Custom Input} 6 | \usage{ 7 | scaffold_input(name, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{name}{Name of input, will define internal name binding and CSS class.} 11 | 12 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 13 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 14 | Otherwise takes a boolean.} 15 | } 16 | \value{ 17 | \code{TRUE} (invisibly) if successfully run. 18 | } 19 | \description{ 20 | Sets basic structure for a shiny input. 21 | } 22 | \examples{ 23 | if (interactive()) { 24 | # current directory 25 | wd <- getwd() 26 | 27 | # create a mock up ambiorix project 28 | tmp <- tmp_package() 29 | 30 | # move to package 31 | setwd(tmp) 32 | 33 | # scaffold ambiorix 34 | scaffold_input() 35 | 36 | # clean up 37 | setwd(wd) 38 | tmp_delete(tmp) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /man/scaffold_output.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/output.R 3 | \name{scaffold_output} 4 | \alias{scaffold_output} 5 | \title{Scaffold Shiny Output} 6 | \usage{ 7 | scaffold_output(name, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{name}{Name of output, will define internal name binding and CSS class.} 11 | 12 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 13 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 14 | Otherwise takes a boolean.} 15 | } 16 | \value{ 17 | \code{TRUE} (invisibly) if successfully run. 18 | } 19 | \description{ 20 | Sets basic structure for a shiny input. 21 | } 22 | \examples{ 23 | if (interactive()) { 24 | # current directory 25 | wd <- getwd() 26 | 27 | # create a mock up ambiorix project 28 | tmp <- tmp_package() 29 | 30 | # move to package 31 | setwd(tmp) 32 | 33 | # scaffold ambiorix 34 | scaffold_output() 35 | 36 | # clean up 37 | setwd(wd) 38 | tmp_delete(tmp) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /inst/extension/R/extension.R: -------------------------------------------------------------------------------- 1 | #' Dependencies 2 | #' 3 | #' Include dependencies, place anywhere in the shiny UI. 4 | #' 5 | #' @importFrom shiny singleton tags 6 | #' 7 | #' @export 8 | use#Name# <- function(){ 9 | singleton( 10 | tags$head( 11 | tags$script(src = "#pkgname#-assets/#name#.js") 12 | ) 13 | ) 14 | } 15 | 16 | #' Show an alert 17 | #' 18 | #' Show a vanilla JavaScript alert. 19 | #' 20 | #' @param msg Message to display. 21 | #' @param session A valid shiny `session`. 22 | #' 23 | #' @examples 24 | #' library(shiny) 25 | #' 26 | #' ui <- fluidPage( 27 | #' use_name(), 28 | #' verbatimTextOutput("response") 29 | #' ) 30 | #' 31 | #' server <- function(input, output){ 32 | #' #name#("Please enter something:") 33 | #' output$response <- renderPrint({ 34 | #' input$#name#Response 35 | #' }) 36 | #' } 37 | #' 38 | #' if(interactive()) 39 | #' shinyApp(ui, server) 40 | #' 41 | #' @export 42 | #name# <- function(msg, session = shiny::getDefaultReactiveDomain()){ 43 | session$sendCustomMessage("#name#-alert", msg) 44 | } 45 | -------------------------------------------------------------------------------- /docs/references/scaffold_input.md: -------------------------------------------------------------------------------- 1 | # `scaffold_input` 2 | 3 | Scaffold a Custom Input 4 | 5 | 6 | ## Description 7 | 8 | Sets basic structure for a shiny input. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_input(name, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `name` | Name of input, will define internal name binding and CSS class. 23 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 24 | 25 | 26 | ## Value 27 | 28 | `TRUE` (invisibly) if successfully run. 29 | 30 | 31 | ## Examples 32 | 33 | ```r 34 | if (interactive()) { 35 | # current directory 36 | wd <- getwd() 37 | 38 | # create a mock up ambiorix project 39 | tmp <- tmp_package() 40 | 41 | # move to package 42 | setwd(tmp) 43 | 44 | # scaffold ambiorix 45 | scaffold_input() 46 | 47 | # clean up 48 | setwd(wd) 49 | tmp_delete(tmp) 50 | } 51 | ``` 52 | 53 | 54 | -------------------------------------------------------------------------------- /docs/references/scaffold_output.md: -------------------------------------------------------------------------------- 1 | # `scaffold_output` 2 | 3 | Scaffold Shiny Output 4 | 5 | 6 | ## Description 7 | 8 | Sets basic structure for a shiny input. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_output(name, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `name` | Name of output, will define internal name binding and CSS class. 23 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 24 | 25 | 26 | ## Value 27 | 28 | `TRUE` (invisibly) if successfully run. 29 | 30 | 31 | ## Examples 32 | 33 | ```r 34 | if (interactive()) { 35 | # current directory 36 | wd <- getwd() 37 | 38 | # create a mock up ambiorix project 39 | tmp <- tmp_package() 40 | 41 | # move to package 42 | setwd(tmp) 43 | 44 | # scaffold ambiorix 45 | scaffold_output() 46 | 47 | # clean up 48 | setwd(wd) 49 | tmp_delete(tmp) 50 | } 51 | ``` 52 | 53 | 54 | -------------------------------------------------------------------------------- /docs/references/scaffold_extension.md: -------------------------------------------------------------------------------- 1 | # `scaffold_extension` 2 | 3 | Shiny Extension 4 | 5 | 6 | ## Description 7 | 8 | Creates the basic structure for a shiny extension. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_extension(name, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `name` | Name of extension used to define file names and functions. 23 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 24 | 25 | 26 | ## Value 27 | 28 | `TRUE` (invisibly) if successfully run. 29 | 30 | 31 | ## Examples 32 | 33 | ```r 34 | if (interactive()) { 35 | # current directory 36 | wd <- getwd() 37 | 38 | # create a mock up ambiorix project 39 | tmp <- tmp_package() 40 | 41 | # move to package 42 | setwd(tmp) 43 | 44 | # scaffold ambiorix 45 | scaffold_extension() 46 | 47 | # clean up 48 | setwd(wd) 49 | tmp_delete(tmp) 50 | } 51 | ``` 52 | 53 | 54 | -------------------------------------------------------------------------------- /man/scaffold_extension.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/extension.R 3 | \name{scaffold_extension} 4 | \alias{scaffold_extension} 5 | \title{Shiny Extension} 6 | \usage{ 7 | scaffold_extension(name, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{name}{Name of extension used to define file names and functions.} 11 | 12 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 13 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 14 | Otherwise takes a boolean.} 15 | } 16 | \value{ 17 | \code{TRUE} (invisibly) if successfully run. 18 | } 19 | \description{ 20 | Creates the basic structure for a shiny extension. 21 | } 22 | \examples{ 23 | if (interactive()) { 24 | # current directory 25 | wd <- getwd() 26 | 27 | # create a mock up ambiorix project 28 | tmp <- tmp_package() 29 | 30 | # move to package 31 | setwd(tmp) 32 | 33 | # scaffold ambiorix 34 | scaffold_extension() 35 | 36 | # clean up 37 | setwd(wd) 38 | tmp_delete(tmp) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /docs/references/use_loader_style.md: -------------------------------------------------------------------------------- 1 | # `use_loader_style` 2 | 3 | Use Styles Loader 4 | 5 | 6 | ## Description 7 | 8 | Installs loaders and adds relevant configuration rules 9 | to `srcjs/config/loaders.json` , the function 10 | `use_loader_style` is recommended . 11 | 12 | 13 | ## Usage 14 | 15 | ```r 16 | use_loader_css(test = "\\.css$", import = TRUE, modules = TRUE) 17 | use_loader_sass(test = "\\.s[ac]ss$") 18 | use_loader_style(test = "\\.css$", import = TRUE, modules = TRUE) 19 | ``` 20 | 21 | 22 | ## Arguments 23 | 24 | Argument |Description 25 | ------------- |---------------- 26 | `test` | Test regular expression test which files should be transformed by the loader. 27 | `import` | Whether to enable `import` statements for `.css` files. If `FALSE` use `require` . 28 | `modules` | Enables CSS modules and their config, a complex but powerful feature detailed [here](https://webpack.js.org/loaders/css-loader/#modules) 29 | 30 | 31 | ## Details 32 | 33 | This will let you import styles much like any other modules, e.g.: import './styles.css' . 34 | 35 | 36 | -------------------------------------------------------------------------------- /inst/input/R/input.R: -------------------------------------------------------------------------------- 1 | #' #name# 2 | #' 3 | #' Incremental button. 4 | #' 5 | #' @param inputId Id of input. 6 | #' @param value Initial value. 7 | #' 8 | #' @examples 9 | #' library(shiny) 10 | #' 11 | #' ui <- fluidPage( 12 | #' #name#Input("theId", 0) 13 | #' ) 14 | #' 15 | #' server <- function(input, output){ 16 | #' 17 | #' observeEvent(input$theId, { 18 | #' print(input$theId) 19 | #' }) 20 | #' 21 | #' } 22 | #' 23 | #' if(interactive()) 24 | #' shinyApp(ui, server) 25 | #' 26 | #' @importFrom shiny tags tagList 27 | #' 28 | #' @export 29 | #name#Input <- function(inputId, value = 0){ 30 | 31 | stopifnot(!missing(inputId)) 32 | stopifnot(is.numeric(value)) 33 | 34 | dep <- htmltools::htmlDependency( 35 | name = "#name#Binding", 36 | version = "1.0.0", 37 | src = c(file = system.file("packer", package = "#pkgname#")), 38 | script = "#name#.js" 39 | ) 40 | 41 | tagList( 42 | dep, 43 | tags$button( 44 | id = inputId, 45 | class = "#name#Binding btn btn-default", 46 | type = "button", 47 | value 48 | ) 49 | ) 50 | } 51 | -------------------------------------------------------------------------------- /docs/references/apply_react.md: -------------------------------------------------------------------------------- 1 | # `apply_react` 2 | 3 | Apply React 4 | 5 | 6 | ## Description 7 | 8 | Apply React to a project, adds the relevant (babel) loader, installs dependencies, 9 | and creates, updates, or replaces the `srcjs/index.js` file. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | apply_react(use_cdn = TRUE) 16 | ``` 17 | 18 | 19 | ## Arguments 20 | 21 | Argument |Description 22 | ------------- |---------------- 23 | `use_cdn` | Whether to use the CDN for `react` and `react-dom` (recommended). This means later importing the dependencies in the shiny UI using `reactCDN()` , this function will be created in a `R/react_cdn.R` . The correct instructions to do so are printed to the console by the function. 24 | 25 | 26 | ## Details 27 | 28 | After running this function and bundling the JavaScript remember to place 29 | the code printed by the function in shiny UI. By default [`apply_react()`](#applyreact()) does not 30 | bundle `react` and `react-dom` and thus requires using `reactCDN()` to import the 31 | dependencies in the shiny application: this function is created in a `R/react_cdn.R` . 32 | 33 | 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2020 John Coene 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /man/apply_react.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/react.R 3 | \name{apply_react} 4 | \alias{apply_react} 5 | \title{Apply React} 6 | \usage{ 7 | apply_react(use_cdn = TRUE) 8 | } 9 | \arguments{ 10 | \item{use_cdn}{Whether to use the CDN for \code{react} and \code{react-dom} (recommended). 11 | This means later importing the dependencies in the shiny UI using \code{reactCDN()}, 12 | this function will be created in a \code{R/react_cdn.R}. 13 | The correct instructions to do so are printed to the console by the function.} 14 | } 15 | \description{ 16 | Apply React to a project, adds the relevant (babel) loader, installs dependencies, 17 | and creates, updates, or replaces the \code{srcjs/index.js} file. 18 | } 19 | \details{ 20 | After running this function and bundling the JavaScript remember to place 21 | the code printed by the function in shiny UI. By default \code{\link[=apply_react]{apply_react()}} does not 22 | bundle \code{react} and \code{react-dom} and thus requires using \code{reactCDN()} to import the 23 | dependencies in the shiny application: this function is created in a \code{R/react_cdn.R}. 24 | } 25 | -------------------------------------------------------------------------------- /tests/testthat/test-yarn.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Install yarn", { 6 | expect_message(engine_yarn_install()) 7 | }) 8 | 9 | test_that("Yarn", { 10 | # wrong engine 11 | engine_set("npm") 12 | expect_error(yarn_add("sth")) 13 | engine_set("yarn") 14 | expect_null(engine_which()) 15 | expect_error(yarn_remove()) 16 | 17 | # keep working directory 18 | wd <- getwd() 19 | 20 | # test bare 21 | pkg <- create_tmp_golem() 22 | setwd(pkg) 23 | on.exit({ 24 | set_yarn("") 25 | engine_set("npm") 26 | setwd(wd) 27 | delete_tmp_package(pkg) 28 | }) 29 | expect_output(scaffold_golem(edit = FALSE)) 30 | expect_message(engine_yarn_set()) 31 | expect_is(engine_which(), "character") 32 | yarn_version() 33 | expect_message(yarn_add("browserify")) 34 | yarn_run("production") 35 | yarn_install() 36 | yarn_upgrade() 37 | yarn_remove("browserify") 38 | expect_message(yarn_console()) 39 | expect_message(bundle_prod()) 40 | expect_message(use_loader_style()) 41 | expect_message(add_plugin_eslint()) 42 | expect_invisible(engine_get()) 43 | yarn_outdated() 44 | yarn_clean() 45 | }) 46 | -------------------------------------------------------------------------------- /man/bundle.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/bundle.R 3 | \name{bundle} 4 | \alias{bundle} 5 | \alias{bundle_prod} 6 | \alias{bundle_dev} 7 | \alias{watch} 8 | \title{bundle & Watch} 9 | \usage{ 10 | bundle(mode = c("production", "development", "none")) 11 | 12 | bundle_prod() 13 | 14 | bundle_dev() 15 | 16 | watch() 17 | } 18 | \arguments{ 19 | \item{mode}{The configuration mode tells webpack to use 20 | its built-in optimisations accordingly.} 21 | } 22 | \description{ 23 | Bundle and watch the JavaScript. 24 | } 25 | \section{Functions}{ 26 | 27 | \itemize{ 28 | \item \code{\link[=bundle]{bundle()}} - bundle the project. 29 | \item \code{\link[=bundle_prod]{bundle_prod()}} - bundle the project optimising production, equivalent to \code{bundle("production")} and \verb{npm run production}. 30 | \item \code{\link[=bundle_dev]{bundle_dev()}} - bundle the project including debugging developer tools, equivalent to \code{bundle("development")} and \verb{npm run development}. 31 | \item \code{\link[=watch]{watch()}} - watches for changes in the \code{srcjs} and rebuilds if necessary, equivalent to \verb{npm run watch}. 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /R/rmd-utils.R: -------------------------------------------------------------------------------- 1 | #' Golem JavaScript Files 2 | #' 3 | #' Creates the necessary `srcjs` directory and children JavaScript files. 4 | #' This is a simple copy of template files: no changes required. 5 | #' 6 | #' @inheritParams scaffol_golem 7 | #' 8 | #' @noRd 9 | #' @keywords internal 10 | rmd_files <- function(react = FALSE, vue = FALSE) { 11 | # define template to copy 12 | template_dir <- "javascript" 13 | if (react) template_dir <- "react" 14 | if (vue) template_dir <- "vue" 15 | 16 | # get full path to srcjs 17 | srcjs_path <- sprintf("rmd/%s/srcjs", template_dir) 18 | srcjs_base <- pkg_file(srcjs_path) 19 | 20 | # get full path to assets 21 | assets_path <- sprintf("rmd/%s/assets/", template_dir) 22 | assets_base <- pkg_file(assets_path) 23 | 24 | # Rmd file 25 | index_path <- pkg_file("rmd/index.Rmd") 26 | 27 | # copy templates 28 | fs::dir_copy(srcjs_base, "srcjs/rmd") 29 | fs::dir_copy(assets_base, "assets") 30 | fs::file_copy(index_path, "index.Rmd") 31 | 32 | cli::cli_alert_success("Created {.file assets} directory") 33 | cli::cli_alert_success("Created {.file index.Rmd}") 34 | cli::cli_alert_success("Created {.file srcjs} directory") 35 | } 36 | -------------------------------------------------------------------------------- /R/library.R: -------------------------------------------------------------------------------- 1 | #' Make Library 2 | #' 3 | #' Adds library settings to webpack config. 4 | #' This allow exporting JavaScript objects. 5 | #' 6 | #' @param name Name of the library, default recommended, 7 | #' see details. 8 | #' @param type Type of the library. 9 | #' 10 | #' @details The functions will be exported 11 | #' at the specified `name`, e.g.: if 12 | #' the name is `myLib` then functions can be 13 | #' called with `myLib.function();`. 14 | #' The default (`[name]`) means the name of the exported 15 | #' library will be the same as the name of the scaffold. 16 | #' This is advised because otherwise, if one has multiple 17 | #' scaffold, an absolute will overwrite itself and only 18 | #' the last scaffold added will be a valid library. 19 | #' 20 | #' @export 21 | make_library <- function(name = "[name]", type = "umd") { 22 | common <- readLines("webpack.common.js") 23 | common[grepl("\\[name\\]\\.js", common)] <- sprintf( 24 | " filename: '[name].js',\n library: {name: '%s', type: '%s'},", 25 | name, type 26 | ) 27 | 28 | writeLines(common, "webpack.common.js") 29 | 30 | cli::cli_alert_info("Use `{name}.foo()` to call exported functions.") 31 | invisible() 32 | } 33 | -------------------------------------------------------------------------------- /tests/fns.R: -------------------------------------------------------------------------------- 1 | create_tmp_package <- function() { 2 | tmp <- tempdir() 3 | # make sure it's empty 4 | files <- list.files(tmp) 5 | sapply(files, empty, dir = tmp) 6 | suppressMessages(usethis::create_package(tmp)) 7 | return(tmp) 8 | } 9 | 10 | empty <- function(file, dir = tmp) { 11 | path <- file.path(dir, file) 12 | unlink(file, recursive = TRUE, force = TRUE) 13 | } 14 | 15 | delete_tmp_package <- function(tmp) { 16 | unlink(tmp, recursive = TRUE, force = TRUE) 17 | } 18 | 19 | create_tmp_golem <- function() { 20 | tmp <- tempdir() 21 | suppressMessages( 22 | golem::create_golem( 23 | tmp, 24 | open = FALSE, 25 | check_name = FALSE 26 | ) 27 | ) 28 | return(tmp) 29 | } 30 | 31 | create_tmp_project <- function() { 32 | tmp <- tempdir() 33 | suppressMessages(usethis::create_project(tmp)) 34 | return(tmp) 35 | } 36 | 37 | create_tmp_ambiorix <- function() { 38 | tmp <- tempdir() 39 | # make sure it's empty 40 | files <- list.files(tmp) 41 | sapply(files, empty, dir = tmp) 42 | suppressMessages(usethis::create_package(tmp)) 43 | writeLines( 44 | "build()$start()", 45 | file.path(tmp, "app.R") 46 | ) 47 | return(tmp) 48 | } 49 | -------------------------------------------------------------------------------- /docs/docify.R: -------------------------------------------------------------------------------- 1 | library(purrr) 2 | 3 | news <- readLines("NEWS.md") 4 | news <- c("# Changelog", "", news) 5 | writeLines(news, con = "docs/NEWS.md") 6 | 7 | fs::dir_delete("./docs/references") 8 | fs::dir_create("./docs/references") 9 | 10 | # ------------------------------------------- REFERENCE 11 | # functions 12 | get_id <- function(x){ 13 | gsub("\\.md", "", x) 14 | } 15 | 16 | get_name <- function(x){ 17 | x <- gsub("\\_", " ", x) 18 | gsub("\\.md", "", x) 19 | } 20 | 21 | # directory of .Rd 22 | dir <- "./man" 23 | 24 | # read .Rd 25 | files <- list.files(dir) 26 | files <- files[grepl("\\.Rd", files)] 27 | 28 | docs <- purrr::map(files, function(x){ 29 | input <- paste0(dir, "/", x) 30 | nm <- gsub("\\.Rd", ".md", x) 31 | output <- paste0("./docs/references/", nm) 32 | Rd2md::Rd2markdown(input, output) 33 | 34 | list(name = nm, output = output) 35 | }) 36 | 37 | json <- purrr::map(files, function(x){ 38 | link <- gsub("\\.Rd", "", x) 39 | title <- tools::toTitleCase(link) 40 | title <- gsub("_", " ", title) 41 | list(title = title, link = sprintf("/references/%s", link)) 42 | }) 43 | 44 | json <- jsonlite::toJSON(json, pretty = FALSE, auto_unbox = TRUE) 45 | 46 | cat(json, "\n") 47 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: packer 2 | Title: An Opinionated Framework for Using 'JavaScript' 3 | Date: 2022-05-28 4 | Version: 0.1.3.9000 5 | Authors@R: 6 | person(given = "John", 7 | family = "Coene", 8 | role = c("aut", "cre"), 9 | email = "jcoenep@gmail.com", 10 | comment = c(ORCID = "0000-0002-6637-4107")) 11 | Description: 12 | Enforces good practice and provides convenience functions to make work with 'JavaScript' 13 | not just easier but also scalable. It is a robust wrapper to 'NPM', 'yarn', and 'webpack' that 14 | enables to compartmentalize 'JavaScript' code, leverage 'NPM' and 'yarn' packages, include 15 | 'TypeScript', 'React', or 'Vue' in web applications, and much more. 16 | License: MIT + file LICENSE 17 | Encoding: UTF-8 18 | LazyData: true 19 | Roxygen: list(markdown = TRUE) 20 | RoxygenNote: 7.2.3 21 | Imports: 22 | fs, 23 | cli, 24 | usethis, 25 | jsonlite, 26 | roxygen2, 27 | rprojroot, 28 | rstudioapi, 29 | assertthat, 30 | htmlwidgets 31 | URL: https://github.com/JohnCoene/packer, https://packer.john-coene.com 32 | BugReports: https://github.com/JohnCoene/packer/issues 33 | Suggests: 34 | testthat, 35 | covr, 36 | golem 37 | -------------------------------------------------------------------------------- /man/scaffold_widget.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/widget.R 3 | \name{scaffold_widget} 4 | \alias{scaffold_widget} 5 | \title{Scaffold Widget} 6 | \usage{ 7 | scaffold_widget(name, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{name}{Name of widget, also passed to \code{\link[htmlwidgets:scaffoldWidget]{htmlwidgets::scaffoldWidget()}}.} 11 | 12 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 13 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 14 | Otherwise takes a boolean.} 15 | } 16 | \value{ 17 | \code{TRUE} (invisibly) if successfully run. 18 | } 19 | \description{ 20 | Creates basic structure for a widget. 21 | } 22 | \details{ 23 | Internally runs \code{\link[htmlwidgets:scaffoldWidget]{htmlwidgets::scaffoldWidget()}} do not run it prior to this function. 24 | } 25 | \examples{ 26 | if (interactive()) { 27 | # current directory 28 | wd <- getwd() 29 | 30 | # create a mock up ambiorix project 31 | tmp <- tmp_package() 32 | 33 | # move to package 34 | setwd(tmp) 35 | 36 | # scaffold ambiorix 37 | scaffold_widget() 38 | 39 | # clean up 40 | setwd(wd) 41 | tmp_delete(tmp) 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /docs/references/scaffold_widget.md: -------------------------------------------------------------------------------- 1 | # `scaffold_widget` 2 | 3 | Scaffold Widget 4 | 5 | 6 | ## Description 7 | 8 | Creates basic structure for a widget. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_widget(name, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `name` | Name of widget, also passed to [`htmlwidgets::scaffoldWidget()`](#htmlwidgets::scaffoldwidget()) . 23 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 24 | 25 | 26 | ## Details 27 | 28 | Internally runs [`htmlwidgets::scaffoldWidget()`](#htmlwidgets::scaffoldwidget()) do not run it prior to this function. 29 | 30 | 31 | ## Value 32 | 33 | `TRUE` (invisibly) if successfully run. 34 | 35 | 36 | ## Examples 37 | 38 | ```r 39 | if (interactive()) { 40 | # current directory 41 | wd <- getwd() 42 | 43 | # create a mock up ambiorix project 44 | tmp <- tmp_package() 45 | 46 | # move to package 47 | setwd(tmp) 48 | 49 | # scaffold ambiorix 50 | scaffold_widget() 51 | 52 | # clean up 53 | setwd(wd) 54 | tmp_delete(tmp) 55 | } 56 | ``` 57 | 58 | 59 | -------------------------------------------------------------------------------- /docs/references/scaffold_leprechaun.md: -------------------------------------------------------------------------------- 1 | # `scaffold_leprechaun` 2 | 3 | Leprechaun 4 | 5 | 6 | ## Description 7 | 8 | Creates the basic structure for leprechaun app with JavaScript. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_leprechaun(react = FALSE, vue = FALSE, use_cdn = TRUE, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `react` | Whether to include React, internally runs [`apply_react()`](#applyreact()) and adapts the `srcjs/index.js` template for React. 23 | `vue` | Whether to include Vue, internally runs [`apply_vue()`](#applyvue()) and adapts the `srcjs/index.js` template for Vue. 24 | `use_cdn` | Whether to use the CDN for react or vue dependencies, this is passed to [`apply_react()`](#applyreact()) or [`apply_vue()`](#applyvue()) if `react` or `vue` arguments are set to `TRUE` and ignored otherwise. 25 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 26 | 27 | 28 | ## Details 29 | 30 | Only one of `react` or `vue` can be set to `TRUE` . 31 | 32 | 33 | ## Value 34 | 35 | `TRUE` (invisibly) if successfully run. 36 | 37 | 38 | -------------------------------------------------------------------------------- /man/engine.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/engine.R 3 | \name{engine} 4 | \alias{engine} 5 | \alias{engine_set} 6 | \alias{engine_get} 7 | \alias{engine_adapt} 8 | \alias{engine_which} 9 | \title{Set Engine} 10 | \usage{ 11 | engine_set(engine = c("npm", "yarn")) 12 | 13 | engine_get() 14 | 15 | engine_adapt() 16 | 17 | engine_which() 18 | } 19 | \arguments{ 20 | \item{engine}{The engine to use, npm or yarn.} 21 | } 22 | \description{ 23 | Defines the engine to use with packer. 24 | One can pick between npm and yarn. 25 | } 26 | \details{ 27 | Generally one would want to define 28 | the engine prior to scaffolding. 29 | For convenience you can instead set the environment 30 | variable \code{PACKER_ENGINE} to your engine of choice. 31 | Packer reads this variable, all subsequent use 32 | of packer will use the defined engine. 33 | You can use the function \code{usethis::edit_r_environ} 34 | to do so. 35 | } 36 | \section{Functions}{ 37 | 38 | \itemize{ 39 | \item \code{engine_set}: Define the engine to use for the project. 40 | \item \code{engine_get}: Retrieve the default engine. 41 | \item \code{engine_which}: Retrieve which engine the project is set 42 | to use-. 43 | \item \code{engine_adapt}: Change the engine to match that of the 44 | poject. 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /inst/hooks/check.yml: -------------------------------------------------------------------------------- 1 | name: packer 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - main 8 | 9 | jobs: 10 | check: 11 | 12 | env: 13 | R_REMOTES_NO_ERRORS_FROM_WARNINGS: true 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@master 21 | 22 | - name: Install R dependencies 23 | run: | 24 | install.packages("remotes") 25 | saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) 26 | writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") 27 | shell: Rscript {0} 28 | 29 | - name: Install system dependencies 30 | if: runner.os == 'Linux' 31 | run: | 32 | while read -r cmd 33 | do 34 | eval sudo $cmd 35 | done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') 36 | 37 | - name: Install Dependencies 38 | run: Rscript -e "remotes::install_deps(dependencies = TRUE)" 39 | 40 | - name: Install NPM Dependencies 41 | run: Rscript -e "packer:::engine_install()" 42 | 43 | - name: Check minification 44 | run: Rscript -e "packer:::are_minified('inst')" 45 | -------------------------------------------------------------------------------- /docs/references/scaffold_rmd.md: -------------------------------------------------------------------------------- 1 | # `scaffold_rmd` 2 | 3 | Golem 4 | 5 | 6 | ## Description 7 | 8 | Creates the basic structure for golem app with JavaScript. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_rmd(react = FALSE, vue = FALSE, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `react` | Whether to include React, internally runs [`apply_react()`](#applyreact()) and adapts the `srcjs/index.js` template for React. 23 | `vue` | Whether to include Vue, internally runs [`apply_vue()`](#applyvue()) and adapts the `srcjs/index.js` template for Vue. 24 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 25 | 26 | 27 | ## Details 28 | 29 | Only one of `react` or `vue` can be set to `TRUE` . 30 | 31 | 32 | ## Value 33 | 34 | `TRUE` (invisibly) if successfully run. 35 | 36 | 37 | ## Examples 38 | 39 | ```r 40 | if (interactive()) { 41 | # current directory 42 | wd <- getwd() 43 | 44 | # create a mock up ambiorix project 45 | tmp <- tmp_project() 46 | 47 | # move to package 48 | setwd(tmp) 49 | 50 | # scaffold ambiorix 51 | scaffold_rmd() 52 | 53 | # clean up 54 | setwd(wd) 55 | tmp_delete(tmp) 56 | } 57 | ``` 58 | 59 | 60 | -------------------------------------------------------------------------------- /man/scaffold_leprechaun.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/leprechaun.R 3 | \name{scaffold_leprechaun} 4 | \alias{scaffold_leprechaun} 5 | \title{Leprechaun} 6 | \usage{ 7 | scaffold_leprechaun(react = FALSE, vue = FALSE, use_cdn = TRUE, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{react}{Whether to include React, internally runs \code{\link[=apply_react]{apply_react()}} 11 | and adapts the \code{srcjs/index.js} template for React.} 12 | 13 | \item{vue}{Whether to include Vue, internally runs \code{\link[=apply_vue]{apply_vue()}} and 14 | adapts the \code{srcjs/index.js} template for Vue.} 15 | 16 | \item{use_cdn}{Whether to use the CDN for react or vue dependencies, 17 | this is passed to \code{\link[=apply_react]{apply_react()}} or \code{\link[=apply_vue]{apply_vue()}} if \code{react} or 18 | \code{vue} arguments are set to \code{TRUE} and ignored otherwise.} 19 | 20 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 21 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 22 | Otherwise takes a boolean.} 23 | } 24 | \value{ 25 | \code{TRUE} (invisibly) if successfully run. 26 | } 27 | \description{ 28 | Creates the basic structure for leprechaun app with JavaScript. 29 | } 30 | \details{ 31 | Only one of \code{react} or \code{vue} can be set to \code{TRUE}. 32 | } 33 | -------------------------------------------------------------------------------- /R/roclets.R: -------------------------------------------------------------------------------- 1 | #' Roclet Prod 2 | #' 3 | #' Roclet to run [bundle_prod] when documenting. 4 | #' 5 | #' @import roxygen2 6 | #' 7 | #' @export 8 | prod_roclet <- function() { 9 | roclet("prod") 10 | } 11 | 12 | #' @export 13 | roclet_process.roclet_prod <- function(x, 14 | blocks, 15 | env, 16 | base_path) { 17 | invisible() 18 | } 19 | 20 | #' @export 21 | roclet_output.roclet_prod <- function(x, 22 | results, 23 | base_path, 24 | ...) { 25 | bundle("production") 26 | } 27 | 28 | #' Roclet Dev 29 | #' 30 | #' Roclet to run [bundle_dev] when documenting. 31 | #' 32 | #' @import roxygen2 33 | #' 34 | #' @export 35 | dev_roclet <- function() { 36 | roclet("dev") 37 | } 38 | 39 | #' @export 40 | roclet_process.roclet_dev <- function(x, 41 | blocks, 42 | env, 43 | base_path) { 44 | invisible() 45 | } 46 | 47 | #' @export 48 | roclet_output.roclet_dev <- function(x, 49 | results, 50 | base_path, 51 | ...) { 52 | bundle("development") 53 | } 54 | -------------------------------------------------------------------------------- /man/scaffold_rmd.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rmd.R 3 | \name{scaffold_rmd} 4 | \alias{scaffold_rmd} 5 | \title{Golem} 6 | \usage{ 7 | scaffold_rmd(react = FALSE, vue = FALSE, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{react}{Whether to include React, internally runs \code{\link[=apply_react]{apply_react()}} 11 | and adapts the \code{srcjs/index.js} template for React.} 12 | 13 | \item{vue}{Whether to include Vue, internally runs \code{\link[=apply_vue]{apply_vue()}} and 14 | adapts the \code{srcjs/index.js} template for Vue.} 15 | 16 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 17 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 18 | Otherwise takes a boolean.} 19 | } 20 | \value{ 21 | \code{TRUE} (invisibly) if successfully run. 22 | } 23 | \description{ 24 | Creates the basic structure for golem app with JavaScript. 25 | } 26 | \details{ 27 | Only one of \code{react} or \code{vue} can be set to \code{TRUE}. 28 | } 29 | \examples{ 30 | if (interactive()) { 31 | # current directory 32 | wd <- getwd() 33 | 34 | # create a mock up ambiorix project 35 | tmp <- tmp_project() 36 | 37 | # move to package 38 | setwd(tmp) 39 | 40 | # scaffold ambiorix 41 | scaffold_rmd() 42 | 43 | # clean up 44 | setwd(wd) 45 | tmp_delete(tmp) 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /docs/guide/bundle.md: -------------------------------------------------------------------------------- 1 | # Bundle 2 | 3 | Once you have made changes to any file in the `srcjs` directory you need to bundle the JavaScript to produce the output in the `inst` directory of the package. 4 | 5 | 6 | Remember to bundle your JavaScript files to see the changes reflected in the package. 7 | 8 | 9 | ## Development 10 | 11 | Webpack optimises the bundle(s) differently depending on the mode: development or production. Since webpack bundles multiple files into one it can be difficult to trace back a bug and the file it originated from. To do so webpack uses a sourcemap, either as separate files or inline. 12 | 13 | ```r 14 | packer::bundle_dev() 15 | ``` 16 | 17 | Using the above the files are bundled using a sourcemap, it's less efficient but will let you debug. 18 | 19 | ## Production 20 | 21 | Webpack optimises the bundle differently for production, the output will be more efficient but more difficult to debug. 22 | 23 | ```r 24 | packer::bundle_prod() 25 | ``` 26 | 27 | The production bundle removes comments, minifies the file, and 28 | more. 29 | 30 | 31 | `packer::bundle()` bundles for prod by default. 32 | 33 | 34 | ## Watch 35 | 36 | You can also run `watch` to automatically rebundle the files when the `src` files change. 37 | 38 | 39 | This is very CPU intensive, bundling for development is generally the better option. 40 | 41 | -------------------------------------------------------------------------------- /inst/output/R/output.R: -------------------------------------------------------------------------------- 1 | #' #Name# 2 | #' 3 | #' The poor man's `shiny::renderUI` 4 | #' 5 | #' @param html HTML to display ([htmltools::tags]). 6 | #' @param color Color of output. 7 | #' 8 | #' @examples 9 | #' library(shiny) 10 | #' 11 | #' ui <- fluidPage( 12 | #' #name#Output("id") 13 | #' ) 14 | #' 15 | #' server <- function(input, output){ 16 | #' output$id <- render#Name#({ 17 | #' #name#(h2("Hello")) 18 | #' }) 19 | #' } 20 | #' 21 | #' if(interactive()) 22 | #' shinyApp(ui, server) 23 | #' 24 | #' @export 25 | #name# <- function(html = shiny::h2("Custom output"), color = "red"){ 26 | list(html = as.character(html), color = color) 27 | } 28 | 29 | #' @export 30 | render#Name# <- function(expr, env = parent.frame(), quoted = FALSE) { 31 | # Convert the expression + environment into a function 32 | func <- shiny::exprToFunction(expr, env, quoted) 33 | 34 | function(){ 35 | func() 36 | } 37 | } 38 | 39 | #' @export 40 | #name#Output <- function(id){ 41 | 42 | # element 43 | el <- shiny::tags$div(id = id, class = "#name#") 44 | 45 | # dependency 46 | path <- system.file("packer", package = "#pkgname#") 47 | 48 | deps <- list( 49 | htmltools::htmlDependency( 50 | name = "#name#", 51 | version = "1.0.0", 52 | src = c(file = path), 53 | script = "#name#.js" 54 | ) 55 | ) 56 | 57 | # wrap together 58 | htmltools::attachDependencies(el, deps) 59 | } 60 | -------------------------------------------------------------------------------- /docs/guide/engines.md: -------------------------------------------------------------------------------- 1 | # Engines 2 | 3 | There are two available "engines" as packer calls them: 4 | 5 | - [npm](https://www.npmjs.com/) (default) 6 | - [yarn](https://yarnpkg.com/) 7 | 8 | Some developers prefer yarn, others npm, the differences 9 | are minor. They both manage the packages (dependencies) 10 | these will be installed, uninstalled, etc. differently 11 | but ultimately they do the same thing. 12 | 13 | NPM (Node Package Manager) comes out-of-the-box (hence it is 14 | the default), while yarn is an open-source project initiated 15 | by Facebook. 16 | 17 | If you want to use yarn, first install it globally with: 18 | 19 | ```r 20 | packer::engine_yarn_install() 21 | ``` 22 | 23 | Then __before scaffolding__ your project set the engine to 24 | yarn with. 25 | 26 | ```r 27 | packer::engine_set("yarn") 28 | ``` 29 | 30 | This is error prone however, as everytime one reopen a project 31 | one has to remember to run this function. 32 | 33 | 34 | Set the environment variable PACKER_ENGINE to 35 | yarn 36 | 37 | 38 | To set the environment variable you may use 39 | `usethis::edit_r_environ()`. 40 | 41 | There are some difference to some of the functions, namely 42 | where one uses `npm_install` and `npm_uninstall`, one use 43 | `yarn_add` and `yarn_remove`. To install the dependencies 44 | already present in `package.json` use `npm_install` and 45 | `yarn_install`. 46 | -------------------------------------------------------------------------------- /docs/references/tests.md: -------------------------------------------------------------------------------- 1 | # `tests` 2 | 3 | Add Tests 4 | 5 | 6 | ## Description 7 | 8 | Adds tests to a project, currently supports mocha and peeky, 9 | see details for more. 10 | 11 | 12 | ## Usage 13 | 14 | ```r 15 | include_tests_mocha(esm = TRUE) 16 | include_tests_peeky() 17 | add_test_file(name) 18 | run_tests(open = FALSE) 19 | ``` 20 | 21 | 22 | ## Arguments 23 | 24 | Argument |Description 25 | ------------- |---------------- 26 | `esm` | Whether to install `esm` and require it for tests (recommended). 27 | `name` | Name of the test file to add, without extension. 28 | `open` | Only valid for "peeky," this will open a development UI if `TRUE` . 29 | 30 | 31 | ## Details 32 | 33 | `include_tests_mocha` uses [mocha](https://mochajs.org/) and 34 | [mocha-webpack](https://webpack.js.org/loaders/mocha-loader/) and 35 | creates a directory called `testjs` where tests should be placed. 36 | The function [`run_tests()`](#runtests()) will then uses mocha on all the files in 37 | the `testjs` directory. All tests should end with `.test.js` . 38 | `include_tests_peeky` uses [peeky](https://github.com/Akryum/peeky) 39 | it's very similar to mocha but also comes with a development UI 40 | that can be accessed when running tests by setting `open` to 41 | `TRUE` . 42 | 43 | Requiring `esm` ( `esm = TRUE` ) is recommended as it will allow using the latest 44 | ESM, e.g.: `import` in tests. 45 | 46 | 47 | -------------------------------------------------------------------------------- /docs/references/scaffold_ambiorix.md: -------------------------------------------------------------------------------- 1 | # `scaffold_ambiorix` 2 | 3 | Ambiorix 4 | 5 | 6 | ## Description 7 | 8 | Creates the basic structure for an ambiorix application. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_ambiorix(vue = FALSE, use_cdn = TRUE, edit = NULL) 15 | ``` 16 | 17 | 18 | ## Arguments 19 | 20 | Argument |Description 21 | ------------- |---------------- 22 | `vue` | Whether to include Vue, internally runs [`apply_vue()`](#applyvue()) and adapts the `srcjs/index.js` template for Vue. 23 | `use_cdn` | Whether to use the CDN for react or vue dependencies, this is passed to [`apply_react()`](#applyreact()) or [`apply_vue()`](#applyvue()) if `react` or `vue` arguments are set to `TRUE` and ignored otherwise. 24 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 25 | 26 | 27 | ## Details 28 | 29 | Only one of `react` or `vue` can be set to `TRUE` . 30 | 31 | 32 | ## Value 33 | 34 | `TRUE` (invisibly) if successfully run. 35 | 36 | 37 | ## Examples 38 | 39 | ```r 40 | if (interactive()) { 41 | # current directory 42 | wd <- getwd() 43 | 44 | # create a mock up ambiorix project 45 | tmp <- tmp_ambiorix() 46 | 47 | # move to package 48 | setwd(tmp) 49 | 50 | # scaffold ambiorix 51 | scaffold_ambiorix() 52 | 53 | # clean up 54 | setwd(wd) 55 | tmp_delete(tmp) 56 | } 57 | ``` 58 | 59 | 60 | -------------------------------------------------------------------------------- /R/windy.R: -------------------------------------------------------------------------------- 1 | #' Windy 2 | #' 3 | #' Creates a scaffold for [windy](https://github.com/devOpifex/windy), 4 | #' it's a modified version of [scaffold_bare()]. 5 | #' 6 | #' @inheritParams scaffold_widget 7 | #' 8 | #' @return `TRUE` (invisibly) if successfully run. 9 | #' 10 | #' @examples 11 | #' if (interactive()) { 12 | #' # current directory 13 | #' wd <- getwd() 14 | #' 15 | #' # create a mock up ambiorix project 16 | #' tmp <- tmp_package() 17 | #' 18 | #' # move to package 19 | #' setwd(tmp) 20 | #' 21 | #' # scaffold bare 22 | #' scaffold_windy() 23 | #' 24 | #' # clean up 25 | #' setwd(wd) 26 | #' tmp_delete(tmp) 27 | #' } 28 | #' 29 | #' @export 30 | scaffold_windy <- function(edit = NULL) { 31 | edit <- get_edit(edit) 32 | 33 | # checks 34 | assert_that(has_engine()) 35 | assert_that(is_package()) 36 | 37 | open_msg("bare") 38 | 39 | # init npm 40 | engine_init() 41 | 42 | # install dependencies 43 | core_deps_install() 44 | 45 | # edit package.json 46 | engine_add_scripts() 47 | 48 | # set up dir 49 | bare_files() 50 | 51 | # create config file 52 | configure( 53 | name = "index", 54 | entry_dir = "", 55 | output_dir = "./inst/app/assets", 56 | externals = list(shiny = "Shiny", jquery = "jQuery") 57 | ) 58 | 59 | # ignore files and directories 60 | ignore_files() 61 | 62 | # edit 63 | edit_files(edit, "srcjs/index.js") 64 | 65 | # wrap up 66 | end_msg() 67 | 68 | invisible(TRUE) 69 | } 70 | -------------------------------------------------------------------------------- /man/scaffold_ambiorix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ambiorix.R 3 | \name{scaffold_ambiorix} 4 | \alias{scaffold_ambiorix} 5 | \title{Ambiorix} 6 | \usage{ 7 | scaffold_ambiorix(vue = FALSE, use_cdn = TRUE, edit = NULL) 8 | } 9 | \arguments{ 10 | \item{vue}{Whether to include Vue, internally runs \code{\link[=apply_vue]{apply_vue()}} and 11 | adapts the \code{srcjs/index.js} template for Vue.} 12 | 13 | \item{use_cdn}{Whether to use the CDN for react or vue dependencies, 14 | this is passed to \code{\link[=apply_react]{apply_react()}} or \code{\link[=apply_vue]{apply_vue()}} if \code{react} or 15 | \code{vue} arguments are set to \code{TRUE} and ignored otherwise.} 16 | 17 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 18 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 19 | Otherwise takes a boolean.} 20 | } 21 | \value{ 22 | \code{TRUE} (invisibly) if successfully run. 23 | } 24 | \description{ 25 | Creates the basic structure for an ambiorix application. 26 | } 27 | \details{ 28 | Only one of \code{react} or \code{vue} can be set to \code{TRUE}. 29 | } 30 | \examples{ 31 | if (interactive()) { 32 | # current directory 33 | wd <- getwd() 34 | 35 | # create a mock up ambiorix project 36 | tmp <- tmp_ambiorix() 37 | 38 | # move to package 39 | setwd(tmp) 40 | 41 | # scaffold ambiorix 42 | scaffold_ambiorix() 43 | 44 | # clean up 45 | setwd(wd) 46 | tmp_delete(tmp) 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /R/bare.R: -------------------------------------------------------------------------------- 1 | #' Bare 2 | #' 3 | #' Creates a bare scaffold for no specific use case, as 4 | #' opposed to other scaffolds. This scaffold does not 5 | #' generate R code. 6 | #' 7 | #' @inheritParams scaffold_widget 8 | #' 9 | #' @return `TRUE` (invisibly) if successfully run. 10 | #' 11 | #' @examples 12 | #' if (interactive()) { 13 | #' # current directory 14 | #' wd <- getwd() 15 | #' 16 | #' # create a mock up ambiorix project 17 | #' tmp <- tmp_package() 18 | #' 19 | #' # move to package 20 | #' setwd(tmp) 21 | #' 22 | #' # scaffold bare 23 | #' scaffold_bare() 24 | #' 25 | #' # clean up 26 | #' setwd(wd) 27 | #' tmp_delete(tmp) 28 | #' } 29 | #' 30 | #' @export 31 | scaffold_bare <- function(edit = NULL) { 32 | edit <- get_edit(edit) 33 | 34 | # checks 35 | assert_that(has_engine()) 36 | assert_that(is_package()) 37 | assert_that(!has_scaffold(), msg = "Only a single bare scaffold is allowed") 38 | 39 | open_msg("bare") 40 | 41 | # init npm 42 | engine_init() 43 | 44 | # install dependencies 45 | core_deps_install() 46 | 47 | # edit package.json 48 | engine_add_scripts() 49 | 50 | # set up dir 51 | bare_files() 52 | 53 | # create config file 54 | configure( 55 | name = "index", 56 | entry_dir = "", 57 | output_dir = "./inst", 58 | externals = list(shiny = "Shiny", jquery = "jQuery") 59 | ) 60 | 61 | # ignore files and directories 62 | ignore_files() 63 | 64 | # edit 65 | edit_files(edit, "srcjs/index.js") 66 | 67 | # wrap up 68 | end_msg() 69 | 70 | invisible(TRUE) 71 | } 72 | -------------------------------------------------------------------------------- /man/tests.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/test.R 3 | \name{tests} 4 | \alias{tests} 5 | \alias{include_tests_mocha} 6 | \alias{include_tests_peeky} 7 | \alias{add_test_file} 8 | \alias{run_tests} 9 | \title{Add Tests} 10 | \usage{ 11 | include_tests_mocha(esm = TRUE) 12 | 13 | include_tests_peeky() 14 | 15 | add_test_file(name) 16 | 17 | run_tests(open = FALSE) 18 | } 19 | \arguments{ 20 | \item{esm}{Whether to install \code{esm} and require it for tests (recommended).} 21 | 22 | \item{name}{Name of the test file to add, without extension.} 23 | 24 | \item{open}{Only valid for "peeky," this will open a development 25 | UI if \code{TRUE}.} 26 | } 27 | \description{ 28 | Adds tests to a project, currently supports mocha and peeky, 29 | see details for more. 30 | } 31 | \details{ 32 | \code{include_tests_mocha} uses \href{https://mochajs.org/}{mocha} and 33 | \href{https://webpack.js.org/loaders/mocha-loader/}{mocha-webpack} and 34 | creates a directory called \code{testjs} where tests should be placed. 35 | The function \code{\link[=run_tests]{run_tests()}} will then uses mocha on all the files in 36 | the \code{testjs} directory. All tests should end with \code{.test.js}. 37 | \code{include_tests_peeky} uses \href{https://github.com/Akryum/peeky}{peeky} 38 | it's very similar to mocha but also comes with a development UI 39 | that can be accessed when running tests by setting \code{open} to 40 | \code{TRUE}. 41 | 42 | Requiring \code{esm} (\code{esm = TRUE}) is recommended as it will allow using the latest 43 | ESM, e.g.: \code{import} in tests. 44 | } 45 | -------------------------------------------------------------------------------- /R/tailwind.R: -------------------------------------------------------------------------------- 1 | #' Use Tailwind 2 | #' 3 | #' Creates PostCSS, and tailwindcss config files as well 4 | #' as adds the appropriate loaders and installs dependencies. 5 | #' 6 | #' @param test Test regular expression test which files should be transformed by the loader. 7 | #' 8 | #' @export 9 | use_tailwind <- function(test = "\\.css$") { 10 | assert_that(has_scaffold()) 11 | 12 | # installs and adds loaders 13 | use_loader_rule( 14 | c( 15 | "style-loader", 16 | "css-loader", 17 | "postcss-loader" 18 | ), 19 | test = test 20 | ) 21 | 22 | # install npm dependencies 23 | npm_install( 24 | c( 25 | "postcss", 26 | "tailwindcss" 27 | ) 28 | ) 29 | 30 | # add config files 31 | cli::cli_alert_success( 32 | "Creating {.file postcss.config.js}" 33 | ) 34 | fs::file_copy( 35 | pkg_file("tailwind/postcss.config.js"), 36 | "postcss.config.js" 37 | ) 38 | 39 | cli::cli_alert_success( 40 | "Creating {.file tailwind.config.js}" 41 | ) 42 | fs::file_copy( 43 | pkg_file("tailwind/tailwind.config.js"), 44 | "tailwind.config.js" 45 | ) 46 | 47 | # initial style.css 48 | css <- "style.css" 49 | if (file.exists("srcjs/style.css")) { 50 | css <- "style2.css" 51 | } 52 | 53 | cli::cli_alert_success( 54 | "Creating {.file srcjs/{css}}" 55 | ) 56 | 57 | fs::file_copy( 58 | pkg_file("tailwind/style.css"), 59 | sprintf( 60 | "srcjs/%s", 61 | css 62 | ) 63 | ) 64 | 65 | cli::cli_alert_info( 66 | "Add {.code import './{css}'} to your {.file index.js}" 67 | ) 68 | 69 | invisible() 70 | } 71 | -------------------------------------------------------------------------------- /docs/guide/installation.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Under the hood, many of the functionalities of packer are powered by [npm](https://www.npmjs.com/), Node's Package Manager which comes bundled with node.js. 4 | 5 | ## Node 6 | 7 | ### Mac OS 8 | 9 | The easiest way is via homebrew. 10 | 11 | ``` 12 | brew update 13 | brew install node 14 | ``` 15 | 16 | Otherwise there is also an [installer](https://nodejs.org/en/download/). 17 | 18 | ### Ubuntu 19 | 20 | ``` 21 | sudo apt install nodejs 22 | ``` 23 | 24 | ### Windows 25 | 26 | Download and install the official [executable](https://nodejs.org/en/download/) or use [chocolatey](https://chocolatey.org/). 27 | 28 | ``` 29 | cinst nodejs 30 | # or for full install with npm 31 | cinst nodejs.install 32 | ``` 33 | 34 | Or use [scoop](https://scoop.sh/). 35 | 36 | ``` 37 | scoop install nodejs 38 | ``` 39 | 40 | ### Other 41 | 42 | If you are on another OS or Linux distro check the official, very concise [guide](https://nodejs.org/en/download/package-manager/) to install from various package managers. 43 | 44 | ## R Package 45 | 46 | Once you have the dependency you can install the stable version of packer from CRAN. 47 | 48 | ```r 49 | install.packages("packer") 50 | ``` 51 | 52 | Or get the development version from Github 53 | 54 | ```r 55 | # install.packages("remotes") 56 | remotes::install_github("JohnCoene/packer") 57 | ``` 58 | 59 | ## Yarn 60 | 61 | By default packer will use npm, you can use yarn instead. 62 | There is far more on this in the [engine](/#/guide/engines) 63 | documentation. 64 | 65 | If you want to use yarn you will need to have it installed. 66 | You can do so with `engine_yarn_install`. 67 | -------------------------------------------------------------------------------- /man/use_loader_style.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/loaders.R 3 | \name{use_loader_style} 4 | \alias{use_loader_style} 5 | \alias{use_loader_css} 6 | \alias{use_loader_sass} 7 | \title{Use Styles Loader} 8 | \usage{ 9 | use_loader_css(test = "\\\\.css$", import = TRUE, modules = TRUE) 10 | 11 | use_loader_sass(test = "\\\\.s[ac]ss$/i") 12 | 13 | use_loader_style(test = "\\\\.css$", import = TRUE, modules = TRUE) 14 | } 15 | \arguments{ 16 | \item{test}{Test regular expression test which files should be transformed by the loader.} 17 | 18 | \item{import}{Whether to enable \code{import} statements for 19 | \code{.css} files. If \code{FALSE} use \code{require}.} 20 | 21 | \item{modules}{Enables CSS modules and their config, 22 | a complex but powerful feature detailed 23 | \href{https://webpack.js.org/loaders/css-loader/#modules}{here}} 24 | } 25 | \description{ 26 | Installs loaders and adds relevant configuration rules 27 | to \code{srcjs/config/loaders.json}, the function 28 | \code{use_loader_style} is \emph{recommended}. 29 | } 30 | \details{ 31 | This will let you import styles much like any other modules, e.g.: \verb{import './styles.css'}. 32 | } 33 | \section{Packages}{ 34 | 35 | \itemize{ 36 | \item \code{\link[=use_loader_css]{use_loader_css()}} - installs and imports \code{css-loader} packages as dev. 37 | \item \code{\link[=use_loader_style]{use_loader_style()}} - installs and imports \code{style-loader} and \code{css-loader} packages as dev. This loader enabled CSS modules. 38 | \item \code{\link[=use_loader_sass]{use_loader_sass()}} - installs and imports \code{style-loader}, \code{css-loader}, and \code{sass-loader} as dev. 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /R/bundle.R: -------------------------------------------------------------------------------- 1 | #' bundle & Watch 2 | #' 3 | #' Bundle and watch the JavaScript. 4 | #' 5 | #' @param mode The configuration mode tells webpack to use 6 | #' its built-in optimisations accordingly. 7 | #' 8 | #' @section Functions: 9 | #' 10 | #' * [bundle()] - bundle the project. 11 | #' * [bundle_prod()] - bundle the project optimising production, equivalent to `bundle("production")` and `npm run production`. 12 | #' * [bundle_dev()] - bundle the project including debugging developer tools, equivalent to `bundle("development")` and `npm run development`. 13 | #' * [watch()] - watches for changes in the `srcjs` and rebuilds if necessary, equivalent to `npm run watch`. 14 | #' 15 | #' @name bundle 16 | #' @export 17 | bundle <- function(mode = c("production", "development", "none")) { 18 | bundle_(mode) 19 | } 20 | 21 | #' @rdname bundle 22 | #' @export 23 | bundle_prod <- function() { 24 | bundle_("production") 25 | } 26 | 27 | #' @rdname bundle 28 | #' @export 29 | bundle_dev <- function() { 30 | bundle_("development") 31 | } 32 | 33 | #' @rdname bundle 34 | #' @export 35 | watch <- function() { 36 | assert_that(has_scaffold()) 37 | cli::cli_alert_warning("Watching for changes") 38 | system2("npm", c("run", "watch")) 39 | } 40 | 41 | bundle_ <- function(mode = c("production", "development", "none")) { 42 | assert_that(has_scaffold()) 43 | 44 | cli::cli_process_start("Bundling files", "Bundled", "Failed to bundle files") 45 | 46 | mode <- match.arg(mode) 47 | args <- c("run", mode) 48 | 49 | results <- engine_run(args) 50 | 51 | if (length(results$warnings) > 0) { 52 | cli::cli_process_failed() 53 | } else { 54 | cli::cli_process_done() 55 | } 56 | 57 | invisible(results) 58 | } 59 | -------------------------------------------------------------------------------- /docs/guide/docs.md: -------------------------------------------------------------------------------- 1 | # Docs 2 | 3 | Webpack itself doesn't enable documenting but certainly 4 | facilitates it. Documenting JavaScript code should be 5 | familiar to R programmers as it very much resembles roxygen2. 6 | 7 | An example of the documentation produced for the 8 | [waiter](https://waiter.john-coene.com/jsdoc/) package. 9 | 10 | ## Code 11 | 12 | Within the JavaScript code we add special comments and tags, 13 | just as we do with roxygen2, many of the tags themselves also 14 | bear the same name. 15 | 16 | All tags can be found on the [official website](https://jsdoc.app/). 17 | 18 | From an existing packer project (scaffolded), add the the jsdoc 19 | pluding with `packer::add_plugin_jsdoc`. 20 | 21 | This installs the plugin and creates a configuration 22 | file `jsdoc.conf.json`. The default should work fine but you can 23 | always take a look at the 24 | [official documentation](https://jsdoc.app/about-configuring-jsdoc.html) 25 | if you want to customise things further. 26 | 27 | Once this done, one can add documentation to the JavaScript code. 28 | 29 | ```js 30 | /** 31 | * Adds one to a number 32 | * @param {number} x - A number. 33 | */ 34 | const AddOne = (x) => { 35 | return x + 1; 36 | } 37 | ``` 38 | 39 | Next time the code is bundled (`packer::bundle`) documentation 40 | will be generated in the `jsdoc/` directory (this can also be 41 | changed in the config). 42 | 43 | The documentation produced is essentially equivalent to a 44 | [pkgdown](https://github.com/r-lib/pkgdown/) website for 45 | JavaScript code. 46 | 47 | ## Tutorials 48 | 49 | You can also add tutorials, jsdoc's version of 'vignettes' with 50 | `add_jsdoc_tutorial('websocket')`. 51 | 52 | This creates a `.markdown` file, that can be used like any other 53 | markdown. 54 | -------------------------------------------------------------------------------- /docs/guide/typescript.md: -------------------------------------------------------------------------------- 1 | # TypeScript 2 | 3 | TypeScript has grown in popularity when working with JavaScript. 4 | It's a superset of the language, TypeScript is a JavaScript with 5 | types, types make code slightly more verbose but clearer and 6 | more strict. TypeScript code gets ultimately transpiled to 7 | JavaScript. 8 | 9 | We'll demonstrate with a golem application: create the app 10 | and the scaffold. 11 | 12 | ```r 13 | golem::create_golem('something') 14 | packer::scaffold_golem() 15 | ``` 16 | 17 | Once this done one can add the TypeScript loader with 18 | 19 | ```r 20 | packer::use_loader_ts() 21 | ``` 22 | 23 | ``` 24 | ✔ typescript, ts-loader installed with scope "dev" 25 | ✔ Added loader rule for "typescript" and "ts-loader" 26 | ✔ Writing tsconfig.json 27 | ``` 28 | 29 | Note that this also creates `tsconfig.json` (if not already 30 | present). 31 | 32 | There are a few things that need changing, TypeScript uses 33 | file with `.ts` extension. So we should rename the files 34 | in the `srcjs` directory. 35 | 36 | - `srcjs/index.js` -> `srcjs/index.ts` 37 | - `srcjs/modules/message.js` -> `srcjs/modules/message.ts` 38 | 39 | We'll simplify the example. In `index.ts` we'll just have 40 | the simple code below, note that we removed the `.js` 41 | extension from the import statement. 42 | 43 | ```ts {highlight: [2]} 44 | // index.ts 45 | import { message } from './modules/message'; 46 | 47 | message("Hello TypeScript"); 48 | ``` 49 | 50 | Then we modify the `message` to specify the type of the 51 | `msg` argument. 52 | 53 | ```ts {highlight: [2]} 54 | // modules/message.ts 55 | export const message = (msg: string) => { 56 | alert(msg); 57 | } 58 | ``` 59 | 60 | That is it, one can bundle, load the package and run the app. 61 | 62 | ```r 63 | packer::bundle() 64 | devtools::load_all() 65 | run_app() 66 | ``` 67 | 68 | There is, of course, a lot more to this, head to the 69 | [TypeScript website](https://www.typescriptlang.org/) 70 | to learn more. 71 | -------------------------------------------------------------------------------- /docs/references/scaffold_golem.md: -------------------------------------------------------------------------------- 1 | # `scaffold_golem` 2 | 3 | Golem 4 | 5 | 6 | ## Description 7 | 8 | Creates the basic structure for golem app with JavaScript. 9 | 10 | 11 | ## Usage 12 | 13 | ```r 14 | scaffold_golem( 15 | react = FALSE, 16 | vue = FALSE, 17 | framework7 = FALSE, 18 | use_cdn = TRUE, 19 | edit = NULL 20 | ) 21 | ``` 22 | 23 | 24 | ## Arguments 25 | 26 | Argument |Description 27 | ------------- |---------------- 28 | `react` | Whether to include React, internally runs [`apply_react()`](#applyreact()) and adapts the `srcjs/index.js` template for React. 29 | `vue` | Whether to include Vue, internally runs [`apply_vue()`](#applyvue()) and adapts the `srcjs/index.js` template for Vue. 30 | `framework7` | Whether to include Framework7, internally runs [`apply_framework7()`](#applyframework7()) and adapts the `srcjs/index.js` template for Framework7. 31 | `use_cdn` | Whether to use the CDN for react, vue or Framework7 dependencies, this is passed to [`apply_react()`](#applyreact()) , [`apply_vue()`](#applyvue()) or [`apply_framework7()`](#applyframework7()) if `react` , `vue` or `framework7` arguments are set to `TRUE` and ignored otherwise. 32 | `edit` | Automatically open pertinent files. Defaults to `NULL` , which looks for the environment variable `PACKER_EDIT` and opens the files specified there. Otherwise takes a boolean. 33 | 34 | 35 | ## Details 36 | 37 | Only one of `react` , `vue` or `framework7` can be set to `TRUE` . `use_cdn` is 38 | not supported for Framework7. 39 | 40 | 41 | ## Value 42 | 43 | `TRUE` (invisibly) if successfully run. 44 | 45 | 46 | ## Examples 47 | 48 | ```r 49 | if (interactive()) { 50 | # current directory 51 | wd <- getwd() 52 | 53 | # create a mock up golem project 54 | tmp <- tmp_golem() 55 | 56 | # move to package 57 | setwd(tmp) 58 | 59 | # scaffold golem 60 | scaffold_golem() 61 | 62 | # clean up 63 | setwd(wd) 64 | tmp_delete(tmp) 65 | } 66 | ``` 67 | 68 | 69 | -------------------------------------------------------------------------------- /R/rmd.R: -------------------------------------------------------------------------------- 1 | #' Golem 2 | #' 3 | #' Creates the basic structure for golem app with JavaScript. 4 | #' 5 | #' @inheritParams scaffold_widget 6 | #' @param react Whether to include React, internally runs [apply_react()] 7 | #' and adapts the `srcjs/index.js` template for React. 8 | #' @param vue Whether to include Vue, internally runs [apply_vue()] and 9 | #' adapts the `srcjs/index.js` template for Vue. 10 | #' 11 | #' @details Only one of `react` or `vue` can be set to `TRUE`. 12 | #' 13 | #' @return `TRUE` (invisibly) if successfully run. 14 | #' 15 | #' @examples 16 | #' if (interactive()) { 17 | #' # current directory 18 | #' wd <- getwd() 19 | #' 20 | #' # create a mock up ambiorix project 21 | #' tmp <- tmp_project() 22 | #' 23 | #' # move to package 24 | #' setwd(tmp) 25 | #' 26 | #' # scaffold ambiorix 27 | #' scaffold_rmd() 28 | #' 29 | #' # clean up 30 | #' setwd(wd) 31 | #' tmp_delete(tmp) 32 | #' } 33 | #' 34 | #' @export 35 | scaffold_rmd <- function(react = FALSE, vue = FALSE, edit = NULL) { 36 | # checks 37 | assert_that(has_engine()) 38 | assert_that(is_project()) 39 | assert_that(!has_scaffold(), msg = "Only a single rmd scaffold is allowed") 40 | assert_that(!all(react, vue), msg = "Setup with either react or vue, not both") 41 | 42 | open_msg("rmd") 43 | 44 | # init npm 45 | engine_init() 46 | 47 | # install dependencies 48 | core_deps_install() 49 | 50 | # edit package.json 51 | engine_add_scripts() 52 | 53 | # set up dir for golem 54 | # only create dir if vue or react 55 | rmd_files(react, vue) 56 | 57 | # create config file 58 | configure( 59 | name = "index", 60 | entry_dir = "", 61 | output_dir = "./assets", 62 | externals = list() 63 | ) 64 | 65 | # ignore files and directories 66 | ignore_files() 67 | 68 | if (react) apply_react(use_cdn = TRUE) 69 | if (vue) apply_vue(use_cdn = TRUE) 70 | 71 | # edit 72 | edit_files(edit, "index.Rmd") 73 | 74 | # wrap up 75 | end_msg() 76 | 77 | invisible(TRUE) 78 | } 79 | -------------------------------------------------------------------------------- /docs/examples/typed.md: -------------------------------------------------------------------------------- 1 | # Widget with Npm 2 | 3 | In this example we use packer to scaffold an htmlwidget and use the npm package [typed.js](https://github.com/mattboldt/typed.js). 4 | 5 | ```r 6 | usethis::create_package("type") 7 | packer::scaffold_widget("type") 8 | ``` 9 | 10 | We can then install the typed.js in prod as this is needed from the browser. 11 | 12 | ```r 13 | packer::npm_install("typed.js", scope = "prod") 14 | ``` 15 | 16 | Then we can edit the `srcjs/widgets/type.js` file to use typed.js. 17 | 18 | ```js {highlight:[3, 14,21]} 19 | // typed.js 20 | import 'widgets'; 21 | import Typed from 'typed.js'; 22 | 23 | HTMLWidgets.widget({ 24 | 25 | name: 'type', 26 | 27 | type: 'output', 28 | 29 | factory: function(el, width, height) { 30 | 31 | // TODO: define shared variables for this instance 32 | var typed; 33 | 34 | return { 35 | 36 | renderValue: function(x) { 37 | 38 | // TODO: code to render the widget, e.g. 39 | typed = new Typed('#' + el.id, x); 40 | 41 | }, 42 | 43 | resize: function(width, height) { 44 | 45 | // TODO: code to re-render the widget with a new size 46 | 47 | } 48 | 49 | }; 50 | } 51 | }); 52 | ``` 53 | 54 | Then adapt the `type.R` file to receive the `strings` and, optionally, other parameters to pass to typed.js. 55 | 56 | ```r {highlight:[2,5]} 57 | # type.R 58 | type <- function(strings, ..., width = NULL, height = NULL, elementId = NULL) { 59 | 60 | # forward options using x 61 | x = list(strings = strings, ...) 62 | 63 | # create widget 64 | htmlwidgets::createWidget( 65 | name = 'type', 66 | x, 67 | width = width, 68 | height = height, 69 | package = 'type', 70 | elementId = elementId 71 | ) 72 | } 73 | ``` 74 | 75 | Then the files can be bundled. 76 | 77 | ```r 78 | packer::bundle() 79 | ``` 80 | 81 | And finally the package can be used. 82 | 83 | ```r 84 | type(c("hello", "packer!"), loop = TRUE, typeSpeed = 20) 85 | ``` 86 | 87 | ![](_media/typed.gif) 88 | -------------------------------------------------------------------------------- /inst/common/webpack.common.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const fs = require('fs'); 3 | 4 | // defaults 5 | var outputPath = [], 6 | entryPoints = [], 7 | externals = [], 8 | misc = [], 9 | loaders = []; 10 | 11 | var outputPathFile = './srcjs/config/output_path.json', 12 | entryPointsFile = './srcjs/config/entry_points.json', 13 | externalsFile = './srcjs/config/externals.json', 14 | miscFile = './srcjs/config/misc.json', 15 | loadersFile = './srcjs/config/loaders.json'; 16 | 17 | // Read config files 18 | if(fs.existsSync(outputPathFile)){ 19 | outputPath = fs.readFileSync(outputPathFile, 'utf8'); 20 | } 21 | 22 | if(fs.existsSync(entryPointsFile)){ 23 | entryPoints = fs.readFileSync(entryPointsFile, 'utf8'); 24 | } 25 | 26 | if(fs.existsSync(externalsFile)){ 27 | externals = fs.readFileSync(externalsFile, 'utf8'); 28 | } 29 | 30 | if(fs.existsSync(miscFile)){ 31 | misc = fs.readFileSync(miscFile, 'utf8'); 32 | } 33 | 34 | if(fs.existsSync(loadersFile)){ 35 | loaders = fs.readFileSync(loadersFile, 'utf8'); 36 | } 37 | 38 | if(fs.existsSync(loadersFile)){ 39 | loaders = fs.readFileSync(loadersFile, 'utf8'); 40 | } 41 | 42 | // parse 43 | loaders = JSON.parse(loaders); 44 | misc = JSON.parse(misc); 45 | externals = JSON.parse(externals); 46 | entryPoints = JSON.parse(entryPoints); 47 | 48 | // parse regex 49 | loaders.forEach((loader) => { 50 | loader.test = RegExp(loader.test); 51 | return(loader); 52 | }) 53 | 54 | // placeholder for plugins 55 | var plugins = [ 56 | ]; 57 | 58 | // define options 59 | var options = { 60 | entry: entryPoints, 61 | output: { 62 | filename: '[name].js', 63 | path: path.resolve(__dirname, JSON.parse(outputPath)), 64 | }, 65 | externals: externals, 66 | module: { 67 | rules: loaders 68 | }, 69 | resolve: { 70 | extensions: ['.tsx', '.ts', '.js'], 71 | }, 72 | plugins: plugins 73 | }; 74 | 75 | // add misc 76 | if(misc.resolve) 77 | options.resolve = misc.resolve; 78 | 79 | // export 80 | module.exports = options; 81 | -------------------------------------------------------------------------------- /docs/guide/prereq.md: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | 3 | This page includes what is necessary to understand in order to work with packer but is not a full-blown tutorial on how to get up to speed. 4 | 5 | ## R packages 6 | 7 | R packages make sharing code, datasets, and anything else R-related extremely easy, they also come with a relatively strict structure, the ability to run unit tests, and much more. These have thus become a core feature of the R ecosystem and therefore are also used as the backbone of every packer project. 8 | 9 | ```r 10 | # create a package named usesJS 11 | usethis::create_package("usesJS") 12 | ``` 13 | 14 | 15 | Only the scaffold_rmd is not rooted in a package and instead from a project. 16 | 17 | 18 | ## Npm 19 | 20 | Npm is Node's Package Manager and is, in a sense, Node's equivalent of CRAN, albeit much less strict. It contains a plethora of JavaScript packages waiting to be used with R packages, shiny apps, and plenty of other things. Npm is at its core very simple and packer provides convenience functions to interact with it from R. 21 | 22 | ```r 23 | # install the sass package for development purposes. 24 | packer::npm_install("sass", scope = "dev") 25 | ``` 26 | 27 | ## Webpack 28 | 29 | Webpack is the core of packer, it's what enables modularising JavaScript code, very much like modularising a shiny application: making code more manageable and reusable throughout the application. It is configured from the `webpack.common.js`, `webpack.dev.js`, and `webpack.prod.js` files, different files for different optimisations: `dev` won't be optimal but return clearer error messages, `prod` is optimised for deployment but gives less precise error messages (no sourcemap). 30 | 31 | You can interact with webpack from R with packer using `packer::bundle` to bundle all the files or `packer::watch` to watch for changes in the JavaScript files and re bundles them when things change, ideal while developing the package. 32 | 33 | ```r 34 | # bundle JavaScript files for prod (default) 35 | packer::bundle() 36 | ``` 37 | -------------------------------------------------------------------------------- /R/ambiorix.R: -------------------------------------------------------------------------------- 1 | #' Ambiorix 2 | #' 3 | #' Creates the basic structure for an ambiorix application. 4 | #' 5 | #' @inheritParams scaffold_widget 6 | #' @param vue Whether to include Vue, internally runs [apply_vue()] and 7 | #' adapts the `srcjs/index.js` template for Vue. 8 | #' @param use_cdn Whether to use the CDN for react or vue dependencies, 9 | #' this is passed to [apply_react()] or [apply_vue()] if `react` or 10 | #' `vue` arguments are set to `TRUE` and ignored otherwise. 11 | #' 12 | #' @details Only one of `react` or `vue` can be set to `TRUE`. 13 | #' 14 | #' @return `TRUE` (invisibly) if successfully run. 15 | #' 16 | #' @examples 17 | #' if (interactive()) { 18 | #' # current directory 19 | #' wd <- getwd() 20 | #' 21 | #' # create a mock up ambiorix project 22 | #' tmp <- tmp_ambiorix() 23 | #' 24 | #' # move to package 25 | #' setwd(tmp) 26 | #' 27 | #' # scaffold ambiorix 28 | #' scaffold_ambiorix() 29 | #' 30 | #' # clean up 31 | #' setwd(wd) 32 | #' tmp_delete(tmp) 33 | #' } 34 | #' 35 | #' @export 36 | scaffold_ambiorix <- function(vue = FALSE, use_cdn = TRUE, edit = NULL) { 37 | edit <- get_edit(edit) 38 | 39 | # checks 40 | assert_that(has_engine()) 41 | assert_that(is_ambiorix()) 42 | 43 | open_msg("ambiorix") 44 | 45 | # init npm 46 | engine_init() 47 | 48 | # install dependencies 49 | core_deps_install() 50 | 51 | # edit package.json 52 | engine_add_scripts() 53 | 54 | # set up dir for golem 55 | # only create dir if vue or react 56 | ambiorix_files(vue) 57 | 58 | output_dir <- "./assets" 59 | if (is_package()) { 60 | output_dir <- "./inst/assets" 61 | } 62 | 63 | # create config file 64 | configure( 65 | name = "index", 66 | entry_dir = "", 67 | output_dir = output_dir, 68 | externals = list(ambiorix = "Ambiorix") 69 | ) 70 | 71 | # ignore files and directories 72 | ignore_files() 73 | 74 | if (vue) apply_vue(use_cdn) 75 | 76 | # edit 77 | edit_files(edit, "srcjs/index.js") 78 | 79 | # wrap up 80 | end_msg() 81 | 82 | invisible(TRUE) 83 | } 84 | -------------------------------------------------------------------------------- /R/leprechaun.R: -------------------------------------------------------------------------------- 1 | #' Leprechaun 2 | #' 3 | #' Creates the basic structure for leprechaun app with JavaScript. 4 | #' 5 | #' @inheritParams scaffold_widget 6 | #' @param react Whether to include React, internally runs [apply_react()] 7 | #' and adapts the `srcjs/index.js` template for React. 8 | #' @param vue Whether to include Vue, internally runs [apply_vue()] and 9 | #' adapts the `srcjs/index.js` template for Vue. 10 | #' @param use_cdn Whether to use the CDN for react or vue dependencies, 11 | #' this is passed to [apply_react()] or [apply_vue()] if `react` or 12 | #' `vue` arguments are set to `TRUE` and ignored otherwise. 13 | #' 14 | #' @importFrom cli cli_alert_info 15 | #' 16 | #' @details Only one of `react` or `vue` can be set to `TRUE`. 17 | #' 18 | #' @return `TRUE` (invisibly) if successfully run. 19 | #' 20 | #' @export 21 | scaffold_leprechaun <- function(react = FALSE, vue = FALSE, use_cdn = TRUE, edit = NULL) { 22 | edit <- get_edit(edit) 23 | 24 | # checks 25 | assert_that(has_engine()) 26 | assert_that(is_leprechaun()) 27 | assert_that(!has_scaffold(), msg = "Only a single leprechaun scaffold is allowed") 28 | assert_that(!all(react, vue), msg = "Setup with either react or vue, not both") 29 | 30 | open_msg("leprechaun") 31 | 32 | # init npm 33 | engine_init() 34 | 35 | # install dependencies 36 | core_deps_install() 37 | 38 | # edit package.json 39 | engine_add_scripts() 40 | 41 | # set up dir for leprechaun 42 | # only create dir if vue or react 43 | leprechaun_files(react, vue) 44 | 45 | # create config file 46 | configure( 47 | name = "index", 48 | entry_dir = "", 49 | output_dir = "./inst/assets", 50 | externals = list(shiny = "Shiny", jquery = "jQuery") 51 | ) 52 | 53 | # ignore files and directories 54 | ignore_files() 55 | 56 | if (react) apply_react(use_cdn) 57 | if (vue) apply_vue(use_cdn) 58 | 59 | # edit 60 | edit_files(edit, "srcjs/index.js") 61 | 62 | # wrap up 63 | end_msg() 64 | cli_alert_info("Run {.code leprechaun::use_packer()}") 65 | 66 | invisible(TRUE) 67 | } 68 | -------------------------------------------------------------------------------- /man/scaffold_golem.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/golem.R 3 | \name{scaffold_golem} 4 | \alias{scaffold_golem} 5 | \title{Golem} 6 | \usage{ 7 | scaffold_golem( 8 | react = FALSE, 9 | vue = FALSE, 10 | framework7 = FALSE, 11 | use_cdn = TRUE, 12 | edit = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{react}{Whether to include React, internally runs \code{\link[=apply_react]{apply_react()}} 17 | and adapts the \code{srcjs/index.js} template for React.} 18 | 19 | \item{vue}{Whether to include Vue, internally runs \code{\link[=apply_vue]{apply_vue()}} and 20 | adapts the \code{srcjs/index.js} template for Vue.} 21 | 22 | \item{framework7}{Whether to include Framework7, internally runs \code{\link[=apply_framework7]{apply_framework7()}} 23 | and adapts the \code{srcjs/index.js} template for Framework7.} 24 | 25 | \item{use_cdn}{Whether to use the CDN for react, vue or Framework7 dependencies, 26 | this is passed to \code{\link[=apply_react]{apply_react()}}, \code{\link[=apply_vue]{apply_vue()}} or \code{\link[=apply_framework7]{apply_framework7()}} if \code{react}, 27 | \code{vue} or \code{framework7} arguments are set to \code{TRUE} and ignored otherwise.} 28 | 29 | \item{edit}{Automatically open pertinent files. Defaults to \code{NULL}, which looks 30 | for the environment variable \code{PACKER_EDIT} and opens the files specified there. 31 | Otherwise takes a boolean.} 32 | } 33 | \value{ 34 | \code{TRUE} (invisibly) if successfully run. 35 | } 36 | \description{ 37 | Creates the basic structure for golem app with JavaScript. 38 | } 39 | \details{ 40 | Only one of \code{react}, \code{vue} or \code{framework7} can be set to \code{TRUE}. \code{use_cdn} is 41 | not supported for Framework7. 42 | } 43 | \examples{ 44 | if (interactive()) { 45 | # current directory 46 | wd <- getwd() 47 | 48 | # create a mock up golem project 49 | tmp <- tmp_golem() 50 | 51 | # move to package 52 | setwd(tmp) 53 | 54 | # scaffold golem 55 | scaffold_golem() 56 | 57 | # clean up 58 | setwd(wd) 59 | tmp_delete(tmp) 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /docs/guide/library.md: -------------------------------------------------------------------------------- 1 | # Library and Minification 2 | 3 | By default webpack will minify and optimise the code a great deal. 4 | 5 | Take the following piece of JavaScript code for instance. 6 | 7 | ```js 8 | // global variable 9 | let number = 41; 10 | 11 | // my hello function 12 | function hello(myVariable){ 13 | let total = number + myVariable; 14 | console.log(total); 15 | } 16 | ``` 17 | 18 | By default webpack will minify it; removing 19 | whitespaces, comments, even _renaming variables._ 20 | This is great because it minimises file size a great deal. 21 | 22 | ```js 23 | let n=41;function h(e){let l=n+e;console.log(l)} 24 | ``` 25 | 26 | However, what if we want to export this JavaScript code 27 | so others can use it directly. 28 | Other users won't be able to call the `hello` function, 29 | it has been simplified to something unknown. 30 | 31 | In order to preserve this we have to tell webpack we are 32 | building a library. 33 | 34 | Packer lets you do this with a single function. 35 | 36 | ```r 37 | packer::make_library() 38 | ``` 39 | 40 | This will preserve the function names and make them available 41 | at the library name provided, e.g.: 42 | `packer::make_library("myLib")` 43 | 44 | ```js 45 | myLib.hello(); 46 | ``` 47 | 48 | By default the library name added by `packer::make_library` is 49 | dynamically assigned: it is the same as the name of the name 50 | of the scaffold. e.g.: `scaffold_input("switch")` then running 51 | `make_library()` will produce a library named `switch`. 52 | 53 | This is great if you have multiple "scaffolds" within a single package. An absolute name will make it such that every library 54 | generated by a scaffold (bundles are built sequentially) is 55 | overwritten by the next. You would technically be creating 56 | multiple libraries all with the same name. Think of R, 57 | package names must be unique, same here. 58 | 59 | This is useful if you have an R function that generates JavaScript 60 | code. 61 | 62 | ```r 63 | fooForShinyUI <- function(var){ 64 | shiny::tags$script( 65 | sprintf("myLib.hello(%s)", var) 66 | ) 67 | } 68 | ``` 69 | -------------------------------------------------------------------------------- /R/extension.R: -------------------------------------------------------------------------------- 1 | #' Shiny Extension 2 | #' 3 | #' Creates the basic structure for a shiny extension. 4 | #' 5 | #' @param name Name of extension used to define file names and functions. 6 | #' @inheritParams scaffold_widget 7 | #' 8 | #' @return `TRUE` (invisibly) if successfully run. 9 | #' 10 | #' @examples 11 | #' if (interactive()) { 12 | #' # current directory 13 | #' wd <- getwd() 14 | #' 15 | #' # create a mock up ambiorix project 16 | #' tmp <- tmp_package() 17 | #' 18 | #' # move to package 19 | #' setwd(tmp) 20 | #' 21 | #' # scaffold ambiorix 22 | #' scaffold_extension() 23 | #' 24 | #' # clean up 25 | #' setwd(wd) 26 | #' tmp_delete(tmp) 27 | #' } 28 | #' 29 | #' @export 30 | scaffold_extension <- function(name, edit = NULL) { 31 | edit <- get_edit(edit) 32 | 33 | # checks 34 | assert_that(has_engine()) 35 | assert_that(is_package()) 36 | assert_that(not_missing(name)) 37 | assert_that(is_name_valid(name)) 38 | 39 | path <- sprintf("srcjs/exts/%s.js", name) 40 | assert_that(!fs::file_exists(path), msg = "Extension already exists") 41 | 42 | open_msg("shiny extension", name) 43 | 44 | # init npm 45 | engine_init() 46 | 47 | # create base npm webpack files 48 | create_directory("srcjs/exts") 49 | 50 | # creating inst packge for assets 51 | create_directory("inst/packer", recurse = TRUE) 52 | 53 | # install dependencies 54 | core_deps_install() 55 | 56 | # edit package.json 57 | engine_add_scripts() 58 | 59 | # create config file 60 | configure( 61 | name = name, 62 | entry_dir = "exts/", 63 | output_dir = "./inst/packer", 64 | externals = list(shiny = "Shiny", jquery = "jQuery") 65 | ) 66 | 67 | # create srcjs and files 68 | template_js_module(name, "exts") 69 | creup_index(name, "exts") 70 | 71 | #  creating R files 72 | ext_zzz_file(name) 73 | template_r_function(name, "extension/R/extension.R") 74 | 75 | # ignore files and directories 76 | ignore_files() 77 | 78 | # use shiny 79 | use_pkgs("shiny") 80 | 81 | # edit 82 | edit_files(edit, sprintf("srcjs/exts/%s.js", name), sprintf("R/%s.R", name)) 83 | 84 | # wrap up 85 | end_msg() 86 | 87 | invisible(TRUE) 88 | } 89 | -------------------------------------------------------------------------------- /R/input.R: -------------------------------------------------------------------------------- 1 | #' Scaffold a Custom Input 2 | #' 3 | #' Sets basic structure for a shiny input. 4 | #' 5 | #' @param name Name of input, will define internal name binding and CSS class. 6 | #' @inheritParams scaffold_widget 7 | #' 8 | #' @return `TRUE` (invisibly) if successfully run. 9 | #' 10 | #' @examples 11 | #' if (interactive()) { 12 | #' # current directory 13 | #' wd <- getwd() 14 | #' 15 | #' # create a mock up ambiorix project 16 | #' tmp <- tmp_package() 17 | #' 18 | #' # move to package 19 | #' setwd(tmp) 20 | #' 21 | #' # scaffold ambiorix 22 | #' scaffold_input() 23 | #' 24 | #' # clean up 25 | #' setwd(wd) 26 | #' tmp_delete(tmp) 27 | #' } 28 | #' 29 | #' @export 30 | scaffold_input <- function(name, edit = NULL) { 31 | edit <- get_edit(edit) 32 | 33 | # checks 34 | assert_that(not_missing(name)) 35 | assert_that(has_engine()) 36 | assert_that(is_package()) 37 | assert_that(is_name_valid(name)) 38 | 39 | # check that input does not already exist 40 | file_path <- sprintf("srcjs/inputs/%s.js", name) 41 | assert_that(not_exists(file_path)) 42 | 43 | open_msg("shiny input", name) 44 | 45 | # init npm 46 | engine_init() 47 | 48 | # create base npm webpack files 49 | create_directory("srcjs/inputs") 50 | 51 | # creating inst packge for assets 52 | create_directory("inst/packer", recurse = TRUE) 53 | 54 | # install dev webpack + cli 55 | core_deps_install() 56 | 57 | # create config file 58 | configure( 59 | name = name, 60 | entry_dir = "inputs/", 61 | output_dir = "./inst/packer", 62 | externals = list(shiny = "Shiny", jquery = "jQuery") 63 | ) 64 | 65 | # create srcjs and files 66 | template_js_module(name, "inputs") 67 | creup_index(name, "inputs") 68 | 69 | #  creating R files 70 | template_r_function(name, "input/R/input.R") 71 | 72 | # edit package.json 73 | engine_add_scripts() 74 | 75 | # ignore files and directories 76 | ignore_files() 77 | 78 | # use shiny 79 | use_pkgs("shiny", "htmltools") 80 | 81 | # edit 82 | edit_files(edit, sprintf("srcjs/inputs/%s.js", name), sprintf("R/%s.R", name)) 83 | 84 | # wrap up 85 | end_msg() 86 | 87 | invisible(TRUE) 88 | } 89 | -------------------------------------------------------------------------------- /R/output.R: -------------------------------------------------------------------------------- 1 | #' Scaffold Shiny Output 2 | #' 3 | #' Sets basic structure for a shiny input. 4 | #' 5 | #' @param name Name of output, will define internal name binding and CSS class. 6 | #' @inheritParams scaffold_widget 7 | #' 8 | #' @return `TRUE` (invisibly) if successfully run. 9 | #' 10 | #' @examples 11 | #' if (interactive()) { 12 | #' # current directory 13 | #' wd <- getwd() 14 | #' 15 | #' # create a mock up ambiorix project 16 | #' tmp <- tmp_package() 17 | #' 18 | #' # move to package 19 | #' setwd(tmp) 20 | #' 21 | #' # scaffold ambiorix 22 | #' scaffold_output() 23 | #' 24 | #' # clean up 25 | #' setwd(wd) 26 | #' tmp_delete(tmp) 27 | #' } 28 | #' 29 | #' @export 30 | scaffold_output <- function(name, edit = NULL) { 31 | edit <- get_edit(edit) 32 | 33 | # checks 34 | assert_that(not_missing(name)) 35 | assert_that(has_engine()) 36 | assert_that(is_package()) 37 | assert_that(is_name_valid(name)) 38 | 39 | # check that input does not already exist 40 | file_path <- sprintf("srcjs/outputs/%s.js", name) 41 | assert_that(not_exists(file_path)) 42 | 43 | open_msg("shiny output", name) 44 | 45 | # init npm 46 | engine_init() 47 | 48 | # create base npm webpack files 49 | create_directory("srcjs/outputs", recurse = TRUE) 50 | 51 | # creating inst packge for assets 52 | create_directory("inst/packer", recurse = TRUE) 53 | 54 | # install dev webpack + cli 55 | core_deps_install() 56 | 57 | # edit package.json 58 | engine_add_scripts() 59 | 60 | # create config file 61 | configure( 62 | name = name, 63 | entry_dir = "outputs/", 64 | output_dir = "./inst/packer", 65 | externals = list(shiny = "Shiny", jquery = "jQuery") 66 | ) 67 | 68 | # create srcjs and files 69 | template_js_module(name, "outputs") 70 | creup_index(name, "outputs") 71 | 72 | #  creating R files 73 | template_r_function(name, "output/R/output.R") 74 | 75 | # ignore files and directories 76 | ignore_files() 77 | 78 | # use shiny 79 | use_pkgs("shiny", "htmltools") 80 | 81 | # edit 82 | edit_files(edit, sprintf("srcjs/outputs/%s.js", name), sprintf("R/%s.R", name)) 83 | 84 | # wrap up 85 | end_msg() 86 | 87 | invisible(TRUE) 88 | } 89 | -------------------------------------------------------------------------------- /R/widget.R: -------------------------------------------------------------------------------- 1 | #' Scaffold Widget 2 | #' 3 | #' Creates basic structure for a widget. 4 | #' 5 | #' @param name Name of widget, also passed to [htmlwidgets::scaffoldWidget()]. 6 | #' @param edit Automatically open pertinent files. Defaults to `NULL`, which looks 7 | #' for the environment variable `PACKER_EDIT` and opens the files specified there. 8 | #' Otherwise takes a boolean. 9 | #' 10 | #' @details Internally runs [htmlwidgets::scaffoldWidget()] do not run it prior to this function. 11 | #' 12 | #' @return `TRUE` (invisibly) if successfully run. 13 | #' 14 | #' @importFrom assertthat assert_that 15 | #' 16 | #' @examples 17 | #' if (interactive()) { 18 | #' # current directory 19 | #' wd <- getwd() 20 | #' 21 | #' # create a mock up ambiorix project 22 | #' tmp <- tmp_package() 23 | #' 24 | #' # move to package 25 | #' setwd(tmp) 26 | #' 27 | #' # scaffold ambiorix 28 | #' scaffold_widget() 29 | #' 30 | #' # clean up 31 | #' setwd(wd) 32 | #' tmp_delete(tmp) 33 | #' } 34 | #' 35 | #' @export 36 | scaffold_widget <- function(name, edit = NULL) { 37 | edit <- get_edit(edit) 38 | 39 | # checks 40 | assert_that(has_engine()) 41 | assert_that(is_package()) 42 | assert_that(not_missing(name)) 43 | assert_that(is_name_valid(name)) 44 | 45 | open_msg("widget", name) 46 | 47 | # build original scaffold 48 | scaffold_bare_widget(name) 49 | 50 | # create srcjs 51 | create_directory("srcjs") 52 | 53 | # init npm 54 | engine_init() 55 | 56 | # install dev webpack + cli 57 | core_deps_install() 58 | 59 | # create config file 60 | configure( 61 | name = name, 62 | entry_dir = "widgets/", 63 | output_dir = "./inst/htmlwidgets", 64 | externals = list(widgets = "HTMLWidgets", shiny = "Shiny") 65 | ) 66 | 67 | # copy original file 68 | widget_files(name) 69 | 70 | # edit package.json 71 | engine_add_scripts() 72 | 73 | # ignore files and directories 74 | ignore_files() 75 | 76 | # open files 77 | widget_edit(name, edit) 78 | 79 | # use htmlwidgets 80 | use_pkgs("htmlwidgets") 81 | 82 | # edit 83 | edit_files(edit, sprintf("srcjs/widgets/%s.js", name), sprintf("R/%s.R", name)) 84 | 85 | # wrap up 86 | end_msg() 87 | 88 | invisible(TRUE) 89 | } 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 | 5 | 6 | ![License](https://img.shields.io/badge/license-MIT-green?style=flat-square) 7 | ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/JohnCoene/packer?label=latest&style=flat-square) 8 | [![R-CMD-check](https://github.com/JohnCoene/packer/workflows/R-CMD-check/badge.svg)](https://github.com/JohnCoene/packer/actions) 9 | [![Codecov test coverage](https://codecov.io/gh/JohnCoene/packer/branch/master/graph/badge.svg)](https://app.codecov.io/gh/JohnCoene/packer?branch=master) 10 | 11 | 12 | [Website](https://packer.john-coene.com/) | [Installation](https://packer.john-coene.com/#/guide/installation) | [Get Started](https://packer.john-coene.com/#/guide/getting-started) | [Book](https://book.javascript-for-r.com/webpack-intro.html) 13 | 14 | ## An opinionated framework for using JavaScript with R 15 | 16 |
17 | 18 | At its core packer consists of functions to scaffold R packages powered by webpack and npm, these take the form of scaffolds which are built on top of packages. All of the scaffolds below thus need to be run from within an R package. 19 | 20 | ### Things you can do with packer 21 | 22 | - Use npm packages with htmlwidgets 23 | - Create your shiny UI with the pug templating engine 24 | - Include React/Vue in you shiny application 25 | - Bundle JavaScript files for golem 26 | - Scope CSS selectors 27 | - Use Lit web components 28 | - And so much more... 29 | 30 | ### Usage 31 | 32 | Always start from an empty package and run `scaffold_*` to set up the required basic structure. 33 | 34 | ```r 35 | packer::scaffold_input("") 36 | ``` 37 | 38 | Once the scaffold laid down you can either `bundle` the JavaScript or `watch` for changes as you develop it. 39 | 40 | ```r 41 | packer::bundle() 42 | ``` 43 | 44 | You can then document and install the package to try it out. 45 | 46 | ## Install 47 | 48 | Get the stable version from CRAN: 49 | 50 | ```r 51 | install.packages("packer") 52 | ``` 53 | 54 | Get the development version from Github with `remotes`. 55 | 56 | ```r 57 | # install.packages("remotes") 58 | remotes::install_github("JohnCoene/packer") 59 | ``` 60 | -------------------------------------------------------------------------------- /docs/guide/pwa.md: -------------------------------------------------------------------------------- 1 | # PWA 2 | 3 | Progressive Web Applications (or PWAs) are web apps that deliver an 4 | experience similar to native applications. There are many things 5 | that can contribute to that. Of these, the most significant is the 6 | ability for an app to be able to function when __offline__. This is 7 | achieved through the use of a web technology called Service Workers. 8 | 9 | You can easily add offline experience to your shiny application 10 | with a single function. 11 | 12 | From a shiny application created with golem and scaffolded with 13 | packer. 14 | 15 | ```r 16 | golem::create_golem('pwa-app') 17 | packer::scaffold_golem() 18 | ``` 19 | 20 | Then, add the workbox plugin with: 21 | 22 | ```r 23 | packer::add_plugin_workbox() 24 | ``` 25 | 26 | ```r 27 | ℹ Add the following to your JavaScript (e.g.: index.js) 28 | 29 | if ('serviceWorker' in navigator) { 30 | window.addEventListener('load', () => { 31 | navigator.serviceWorker.register('/www/service-worker.js').then(registration => { 32 | console.log('SW registered: ', registration); 33 | }).catch(registrationError => { 34 | console.log('SW registration failed: ', registrationError); 35 | }); 36 | }); 37 | } 38 | ``` 39 | 40 | Proceed as mentioned, add the code to your `srcjs/index.js` file. 41 | 42 | ```js 43 | // srcjs/index.js 44 | import { message } from './modules/message.js'; 45 | import 'shiny'; 46 | 47 | // In shiny server use: 48 | // session$sendCustomMessage('show-packer', 'hello packer!') 49 | Shiny.addCustomMessageHandler('show-packer', (msg) => { 50 | message(msg); 51 | }) 52 | 53 | if ('serviceWorker' in navigator) { 54 | window.addEventListener('load', () => { 55 | navigator.serviceWorker.register('/www/service-worker.js').then(registration => { 56 | console.log('SW registered: ', registration); 57 | }).catch(registrationError => { 58 | console.log('SW registration failed: ', registrationError); 59 | }); 60 | }); 61 | } 62 | ``` 63 | 64 | After bundling the app with `packer::bundle()`, you should see 65 | new files in the output directory (`inst/app`). 66 | 67 | ``` 68 | inst/app 69 | └── www 70 | ├── favicon.ico 71 | ├── index.js 72 | ├── index.js.map 73 | ├── service-worker.js 74 | ├── service-worker.js.map 75 | ├── workbox-15dd0bab.js 76 | └── workbox-15dd0bab.js.map 77 | ``` -------------------------------------------------------------------------------- /R/framework7.R: -------------------------------------------------------------------------------- 1 | #' Apply Framework7 2 | #' 3 | #' Apply Framework7 to a project, adds the relevant (babel) loader, installs dependencies, 4 | #' and creates, or updates, or replaces the `srcjs/index.js` file. 5 | #' 6 | #' @details After running this function and bundling the JavaScript remember to place 7 | #' `div(id = "app"), tags$script(src = "www/index.js")` at the bottom of your shiny UI. 8 | #' 9 | #' @export 10 | apply_framework7 <- function() { 11 | assert_that(has_no_babel()) 12 | assert_that(!fs::file_exists("srcjs/index.js"), msg = "`srcjs/index.js` already exists, delete or rename it") 13 | 14 | # loader 15 | # Framework7 loader ... 16 | cli::cli_h2("Framework7 loader, plugin & dependency") 17 | engine_install( 18 | "babel-loader", 19 | "@babel/core", 20 | "@babel/preset-env", 21 | "@babel/preset-react", 22 | scope = "dev" 23 | ) 24 | engine_install("framework7", scope = "prod") 25 | use_loader_framework7() 26 | # Can't use use_loader_style (fails...) 27 | use_loader_rule( 28 | c("style-loader", "css-loader"), 29 | test = "\\.css$" 30 | ) 31 | 32 | cli::cli_h2("Babel config file") 33 | babel_config("templates/framework7/_babelrc") 34 | 35 | # template 36 | cli::cli_h2("Template files") 37 | index <- pkg_file("templates/framework7/framework7.js") 38 | fs::file_copy(index, "srcjs/index.js") 39 | fs::dir_copy(pkg_file("templates/framework7/components"), "srcjs/components") 40 | cli::cli_alert_success("Added template elements") 41 | 42 | # only print if project is golem app 43 | # otherwise Rmarkdown = no need 44 | if (is_golem()) { 45 | ui_code <- framework7_ui_code_golem() 46 | cli::cli_alert_warning("Replace/edit your app_ui.R:") 47 | cli::cli_code(ui_code[["ui"]]) 48 | cli::cli_alert_warning("Replace/edit golem_add_external_resources:") 49 | cli::cli_code(ui_code[["resources"]]) 50 | } 51 | } 52 | 53 | #' Dependencies for Framework7 in Golem 54 | #' 55 | #' Includes dependencies in a shiny application. 56 | #' 57 | #' @noRd 58 | #' @keywords internal 59 | framework7_ui_code_golem <- function() { 60 | path <- system.file("templates/framework7", package = "packer") 61 | ui <- format_function_code(file.path(path, "app_ui.R")) 62 | resources <- format_function_code( 63 | file.path(path, "golem_add_external_resources.R") 64 | ) 65 | 66 | list(ui = ui, resources = resources) 67 | } 68 | -------------------------------------------------------------------------------- /R/widget-utils.R: -------------------------------------------------------------------------------- 1 | #' Copy Original Widget Scaffold 2 | #' 3 | #' Copy original scaffold into srcjs directory for webpack use. 4 | #' 5 | #' @inheritParams scaffold_widget 6 | #' 7 | #' @noRd 8 | #' @keywords internal 9 | widget_files <- function(name) { 10 | # create dirs 11 | create_directory("srcjs/modules") 12 | create_directory("srcjs/widgets") 13 | 14 | # index.js 15 | # source template 16 | path <- pkg_file("widget/javascript/widget.js") 17 | template <- readLines(path) 18 | template <- gsub("#name#", name, template) 19 | 20 | # save template 21 | path_out <- sprintf("srcjs/widgets/%s.js", name) 22 | writeLines(template, path_out) 23 | 24 | # remove existing file to avoid confusion 25 | existing_js <- sprintf("inst/htmlwidgets/%s.js", name) 26 | fs::file_delete(existing_js) 27 | 28 | if (!fs::file_exists("srcjs/modules/header.js")) { 29 | module_file <- pkg_file("widget/javascript/module.js") 30 | fs::file_copy(module_file, "srcjs/modules/header.js") 31 | } 32 | 33 | # index 34 | if (!fs::file_exists("srcjs/index.js")) { 35 | widget_create_index(name) 36 | } else { 37 | widget_update_index(name) 38 | } 39 | 40 | cli::cli_alert_success("Moved bare widget to {.file srcjs}") 41 | } 42 | 43 | widget_create_index <- function(name) { 44 | index <- sprintf("import './widgets/%s.js'", name) 45 | writeLines(index, "srcjs/index.js") 46 | cli::cli_alert_success("Created {.file srcjs/index.js}") 47 | } 48 | 49 | widget_update_index <- function(name) { 50 | index <- readLines("srcjs/index.js") 51 | import <- sprintf("import './widgets/%s.js'", name) 52 | index <- c(import, index) 53 | writeLines(index, "srcjs/index.js") 54 | cli::cli_alert_success("Updated {.file srcjs/index.js}") 55 | } 56 | 57 | # open file in editor 58 | widget_edit <- function(name, edit = FALSE) { 59 | if (!edit) { 60 | return() 61 | } 62 | 63 | # r file 64 | r_file <- sprintf("R/%s.R", name) 65 | fs::file_show(r_file) 66 | 67 | # js file 68 | fs::file_show("srcjs/index.js") 69 | } 70 | 71 | # run bare scaffol 72 | scaffold_bare_widget <- function(name) { 73 | cli::cli_process_start("Scaffolding bare widget", "Bare widget setup", "Failed to scaffold bare widget") 74 | tryCatch(widget_scaffold(name), error = function(e) cli::cli_process_failed()) 75 | cli::cli_process_done() 76 | } 77 | 78 | # wrapper to suppress messages 79 | widget_scaffold <- function(name) { 80 | suppressMessages( 81 | htmlwidgets::scaffoldWidget(name, bowerPkg = NULL, edit = FALSE) 82 | ) 83 | } 84 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(roclet_output,roclet_dev) 4 | S3method(roclet_output,roclet_prod) 5 | S3method(roclet_process,roclet_dev) 6 | S3method(roclet_process,roclet_prod) 7 | export(add_jsdoc_tutorial) 8 | export(add_plugin_clean) 9 | export(add_plugin_eslint) 10 | export(add_plugin_html) 11 | export(add_plugin_jsdoc) 12 | export(add_plugin_prettier) 13 | export(add_plugin_workbox) 14 | export(add_test_file) 15 | export(apply_framework7) 16 | export(apply_react) 17 | export(apply_vue) 18 | export(bundle) 19 | export(bundle_dev) 20 | export(bundle_prod) 21 | export(checks) 22 | export(dev_roclet) 23 | export(ease_lit) 24 | export(engine_adapt) 25 | export(engine_check) 26 | export(engine_console) 27 | export(engine_get) 28 | export(engine_set) 29 | export(engine_which) 30 | export(engine_yarn_install) 31 | export(engine_yarn_set) 32 | export(include_action_check) 33 | export(include_tests_mocha) 34 | export(include_tests_peeky) 35 | export(make_library) 36 | export(npm_console) 37 | export(npm_fix) 38 | export(npm_install) 39 | export(npm_outdated) 40 | export(npm_run) 41 | export(npm_uninstall) 42 | export(npm_update) 43 | export(npx) 44 | export(prod_roclet) 45 | export(put_precommit_hook) 46 | export(put_recommended) 47 | export(put_rprofile_adapt) 48 | export(put_test) 49 | export(run_tests) 50 | export(scaffold_ambiorix) 51 | export(scaffold_bare) 52 | export(scaffold_extension) 53 | export(scaffold_golem) 54 | export(scaffold_input) 55 | export(scaffold_leprechaun) 56 | export(scaffold_output) 57 | export(scaffold_rmd) 58 | export(scaffold_widget) 59 | export(scaffold_windy) 60 | export(set_npm) 61 | export(set_yarn) 62 | export(tmp_ambiorix) 63 | export(tmp_delete) 64 | export(tmp_golem) 65 | export(tmp_package) 66 | export(tmp_project) 67 | export(ts_get_type) 68 | export(ts_get_types) 69 | export(use_loader_babel) 70 | export(use_loader_coffee) 71 | export(use_loader_css) 72 | export(use_loader_file) 73 | export(use_loader_framework7) 74 | export(use_loader_mocha) 75 | export(use_loader_pug) 76 | export(use_loader_rule) 77 | export(use_loader_sass) 78 | export(use_loader_style) 79 | export(use_loader_svelte) 80 | export(use_loader_ts) 81 | export(use_loader_vue) 82 | export(use_tailwind) 83 | export(watch) 84 | export(yarn_add) 85 | export(yarn_clean) 86 | export(yarn_console) 87 | export(yarn_install) 88 | export(yarn_outdated) 89 | export(yarn_remove) 90 | export(yarn_run) 91 | export(yarn_upgrade) 92 | export(yarn_version) 93 | import(roxygen2) 94 | importFrom(assertthat,assert_that) 95 | importFrom(cli,cli_alert_info) 96 | -------------------------------------------------------------------------------- /tests/testthat/test-golem.R: -------------------------------------------------------------------------------- 1 | source("../fns.R") 2 | 3 | skip_on_cran() 4 | 5 | test_that("Golem Bare", { 6 | # keep working directory 7 | wd <- getwd() 8 | 9 | # test bare 10 | pkg <- create_tmp_golem() 11 | setwd(pkg) 12 | on.exit({ 13 | setwd(wd) 14 | delete_tmp_package(pkg) 15 | }) 16 | expect_output(scaffold_golem(edit = FALSE)) 17 | expect_error(scaffold_golem(edit = FALSE)) 18 | expect_message(bundle_dev()) 19 | expect_message(add_plugin_html(use_pug = TRUE)) 20 | expect_message(add_plugin_prettier()) 21 | expect_message(add_plugin_eslint()) 22 | expect_message(add_plugin_jsdoc(FALSE)) 23 | add_jsdoc_tutorial("xxx", FALSE) 24 | expect_message(add_plugin_workbox()) 25 | }) 26 | 27 | test_that("Golem CDN", { 28 | # keep working directory 29 | wd <- getwd() 30 | 31 | # test react 32 | pkg <- create_tmp_golem() 33 | setwd(pkg) 34 | expect_output(scaffold_golem(react = TRUE, edit = FALSE)) 35 | expect_message(bundle()) 36 | expect_message(use_loader_mocha(FALSE)) 37 | setwd(wd) 38 | delete_tmp_package(pkg) 39 | 40 | # test vue 41 | pkg <- create_tmp_golem() 42 | setwd(pkg) 43 | expect_output(scaffold_golem(vue = TRUE, edit = FALSE)) 44 | expect_message(bundle()) 45 | expect_message(add_plugin_clean()) 46 | setwd(wd) 47 | delete_tmp_package(pkg) 48 | }) 49 | 50 | test_that("Golem no CDN", { 51 | # keep working directory 52 | wd <- getwd() 53 | 54 | # test react 55 | pkg <- create_tmp_golem() 56 | setwd(pkg) 57 | expect_output(scaffold_golem(react = TRUE, use_cdn = FALSE, edit = FALSE)) 58 | expect_message(bundle()) 59 | expect_message(npm_console()) 60 | expect_message(npm_run("production")) 61 | setwd(wd) 62 | delete_tmp_package(pkg) 63 | 64 | # test vue 65 | pkg <- create_tmp_golem() 66 | setwd(pkg) 67 | expect_output(scaffold_golem(vue = TRUE, use_cdn = FALSE, edit = FALSE)) 68 | expect_message(bundle()) 69 | setwd(wd) 70 | delete_tmp_package(pkg) 71 | 72 | # test framework7 73 | pkg <- create_tmp_golem() 74 | setwd(pkg) 75 | expect_output(scaffold_golem(framework7 = TRUE, edit = FALSE)) 76 | expect_message(bundle()) 77 | setwd(wd) 78 | delete_tmp_package(pkg) 79 | }) 80 | 81 | test_that("Golem F7", { 82 | # keep working directory 83 | wd <- getwd() 84 | 85 | # test bare 86 | pkg <- create_tmp_golem() 87 | setwd(pkg) 88 | on.exit({ 89 | setwd(wd) 90 | delete_tmp_package(pkg) 91 | }) 92 | expect_output(scaffold_golem(framework7 = TRUE, edit = FALSE)) 93 | expect_error(scaffold_golem(edit = FALSE)) 94 | expect_message(bundle_dev()) 95 | }) 96 | -------------------------------------------------------------------------------- /R/typescript.R: -------------------------------------------------------------------------------- 1 | #' Shiny types 2 | #' 3 | #' Installs Shiny TypeScript types. 4 | #' 5 | #' @note May not work with npm, yarn is advised. 6 | #' 7 | #' @details This cannot be automated due to issues with 8 | #' both npm and yarn. 9 | #' 10 | #' - It tends to fail with npm 11 | #' - A limitation of yarn makes this impossible 12 | #' 13 | #' With yarn, you will be prompted which version of 14 | #' jQuery types you want to install, ideally install 15 | #' 3.5.5. 16 | #' 17 | #' @keywords internal 18 | #' @noRd 19 | ts_shiny_types <- function() { 20 | engine <- engine_get() 21 | 22 | if (engine == "npm") { 23 | cli::cli_alert_warning( 24 | "Installing types with npm may fail, try with yarn. See {.code engine_set}" 25 | ) 26 | } 27 | 28 | # this won't work due to patch 29 | # engine_install("rstudio/shiny", scope = "dev") 30 | 31 | engine <- engine_get() 32 | cmd <- engine_install_cmd() 33 | cli::cli_alert( 34 | "Run the following from your terminal" 35 | ) 36 | cli::cli_text( 37 | "{.code {engine} {cmd} rstudio/shiny}" 38 | ) 39 | } 40 | 41 | #' Install Types 42 | #' 43 | #' Install TypeScript types from npm. 44 | #' 45 | #' @param ... Types to install. 46 | #' @param type Name of types `@@types/*` to install. 47 | #' @param versions,version Corresponding versions of types passed 48 | #' to `...`, if `NULL` the latest version is installed. 49 | #' 50 | #' @section Functions: 51 | #' 52 | #' - `ts_get_types`: Flexible to retrieve multiple types. 53 | #' - `ts_get_type`: Convenience to easily retrieve a single type. 54 | #' 55 | #' @examples 56 | #' \dontrun{ 57 | #' ts_get_type("jquery") 58 | #' } 59 | #' \dontrun{ 60 | #' ts_get_types("@@types/jquery") 61 | #' } 62 | #' 63 | #' @name types 64 | #' @export 65 | ts_get_types <- function(..., versions = NULL) { 66 | types <- c(...) 67 | 68 | if (length(types) == 0) { 69 | stop("No types specified", call. = FALSE) 70 | } 71 | 72 | if (is.null(versions)) { 73 | engine_install(types, scope = "dev") 74 | return() 75 | } 76 | 77 | if (length(types) != length(versions)) { 78 | stop("Number of types does not match the number of versions") 79 | } 80 | 81 | types <- paste0(types, "@", versions) 82 | engine_install(types, scope = "dev") 83 | } 84 | 85 | #' @rdname types 86 | #' @export 87 | ts_get_type <- function(type, version = NULL) { 88 | if (missing(type)) { 89 | stop("Missing type", call. = FALSE) 90 | } 91 | 92 | if (!is.null(version)) { 93 | type <- sprintf("%s@%s", type, version) 94 | } 95 | 96 | arg <- sprintf("@types/%s", type) 97 | engine_install(arg) 98 | } 99 | -------------------------------------------------------------------------------- /R/golem.R: -------------------------------------------------------------------------------- 1 | #' Golem 2 | #' 3 | #' Creates the basic structure for golem app with JavaScript. 4 | #' 5 | #' @inheritParams scaffold_widget 6 | #' @param react Whether to include React, internally runs [apply_react()] 7 | #' and adapts the `srcjs/index.js` template for React. 8 | #' @param vue Whether to include Vue, internally runs [apply_vue()] and 9 | #' adapts the `srcjs/index.js` template for Vue. 10 | #' @param framework7 Whether to include Framework7, internally runs [apply_framework7()] 11 | #' and adapts the `srcjs/index.js` template for Framework7. 12 | #' @param use_cdn Whether to use the CDN for react, vue or Framework7 dependencies, 13 | #' this is passed to [apply_react()], [apply_vue()] or [apply_framework7()] if `react`, 14 | #' `vue` or `framework7` arguments are set to `TRUE` and ignored otherwise. 15 | #' 16 | #' @details Only one of `react`, `vue` or `framework7` can be set to `TRUE`. `use_cdn` is 17 | #' not supported for Framework7. 18 | #' 19 | #' @return `TRUE` (invisibly) if successfully run. 20 | #' 21 | #' @examples 22 | #' if (interactive()) { 23 | #' # current directory 24 | #' wd <- getwd() 25 | #' 26 | #' # create a mock up golem project 27 | #' tmp <- tmp_golem() 28 | #' 29 | #' # move to package 30 | #' setwd(tmp) 31 | #' 32 | #' # scaffold golem 33 | #' scaffold_golem() 34 | #' 35 | #' # clean up 36 | #' setwd(wd) 37 | #' tmp_delete(tmp) 38 | #' } 39 | #' 40 | #' @export 41 | scaffold_golem <- function( 42 | react = FALSE, 43 | vue = FALSE, 44 | framework7 = FALSE, 45 | use_cdn = TRUE, 46 | edit = NULL) { 47 | # checks 48 | assert_that(has_engine()) 49 | assert_that(is_golem()) 50 | assert_that(!has_scaffold(), msg = "Only a single golem scaffold is allowed") 51 | assert_that( 52 | !all(react, vue, framework7), 53 | msg = "Setup with either react, vue or framework7." 54 | ) 55 | 56 | open_msg("golem") 57 | 58 | # init npm 59 | engine_init() 60 | 61 | # install dependencies 62 | core_deps_install() 63 | 64 | # edit package.json 65 | engine_add_scripts() 66 | 67 | # set up dir for golem 68 | # only create dir if vue or react 69 | golem_files(react, vue, framework7) 70 | 71 | # create config file 72 | configure( 73 | name = "index", 74 | entry_dir = "", 75 | output_dir = "./inst/app/www", 76 | externals = list(shiny = "Shiny", jquery = "jQuery") 77 | ) 78 | 79 | # ignore files and directories 80 | ignore_files() 81 | 82 | if (react) apply_react(use_cdn) 83 | if (vue) apply_vue(use_cdn) 84 | if (framework7) apply_framework7() 85 | 86 | # edit 87 | edit_files(edit, "srcjs/index.js") 88 | 89 | # wrap up 90 | end_msg() 91 | 92 | invisible(TRUE) 93 | } 94 | --------------------------------------------------------------------------------