3.2.0 ā€¢ Published 5 years ago

@bkonkle/generator-react v3.2.0

Weekly downloads
-
License
BSD-2-Clause
Repository
github
Last release
5 years ago

@bkonkle/generator-react

npm license

                                          $$\
                                          $$ |
 $$$$$$\   $$$$$$\   $$$$$$\   $$$$$$$\ $$$$$$\
$$  __$$\ $$  __$$\  \____$$\ $$  _____|\_$$  _|
$$ |  \__|$$$$$$$$ | $$$$$$$ |$$ /        $$ |
$$ |      $$   ____|$$  __$$ |$$ |        $$ |$$\
$$ |      \$$$$$$$\ \$$$$$$$ |\$$$$$$$\   \$$$$  |
\__|       \_______| \_______| \_______|   \____/

Brandon's Yeoman generators for scaffolding new React applications

Installation

npm install -g @bkonkle/generator-react

You can also use yarn if you have your global folder configured:

yarn global add @bkonkle/generator-react

Yeoman

You'll also need to install Yeoman to use this generator.

npm i -g yo

(or)

```bash
yarn global add yo

Usage

Run one of the generators below, answer the questions, and you'll have a brand new web application set up in your current directory. Tada! šŸŽ‰

Web

To bootstrap a React web project, use the web generator:

mkdir my-new-web-project
cd my-new-web-project

yo @bkonkle/react:web

This results in a build setup adapted from CRA to allow prefetching (or even server rendering, if you want) and to support runtime environment variables. It uses a Webpack config adapted from CRA with tweaks from Razzle and lots of customizations. The dev process is adapted from Razzle, and it runs a base Express process at the requested port, launching the Webpack Dev Server at port + 1 to handle hot reloaded resources. Apollo and Auth0 are optionally included.

You'll get a layout that looks like this (abbreviated):

my-new-web-project
ā”œā”€ā”€ assets - build resources not exposed to the public
ā”œā”€ā”€ scripts - lightweight build tooling adapted from CRA
ā”‚    ā”œā”€ā”€ build.ts - build the project for production use
ā”‚    ā”œā”€ā”€ dev.ts - run the project in dev mode alongside Webpack Dev Server
ā”‚    ā””ā”€ā”€ run.ts - run the project in production mode using the built bundle
ā”œā”€ā”€ src
ā”‚    ā”œā”€ā”€ __tests__ - a stub folder for Jest tests
ā”‚    ā”œā”€ā”€ components - components that handle rendering and presentation
ā”‚    ā”œā”€ā”€ [data] - (if useApollo is selected) a folder for data-related modules
ā”‚    ā”‚    ā”œā”€ā”€ [ApiClient.ts] - (if useApollo is selected) code to initialize an Apollo GraphQL client
ā”‚    ā”‚    ā””ā”€ā”€ [AuthClient.ts] - (if useAuth0 is selected) code to initialize Auth0 authentication
ā”‚    ā”œā”€ā”€ state - Redux state management using thunks with context, for things like the Apollo client
ā”‚    ā”‚    ā”œā”€ā”€ [AuthState.ts] - (if useAuth0 is selected) Redux module to manage auth state
ā”‚    ā”‚    ā”œā”€ā”€ StateTypes.ts - a centralized module for types related to Redux
ā”‚    ā”‚    ā””ā”€ā”€ Store.ts - Redux store initialization and hot reloading code, with thunk context
ā”‚    ā”œā”€ā”€ views - views compose components and handle logic and integration
ā”‚    ā”‚    ā”œā”€ā”€ App.tsx - attaches providers for react-router, Redux, and optionally Apollo
ā”‚    ā”‚    ā”œā”€ā”€ DummyApp.tsx - attaches dummy providers for rendering things like the error view
ā”‚    ā”‚    ā””ā”€ā”€ Router.tsx - a simple react-router switch view using routes from Routes.tsx
ā”‚    ā”œā”€ā”€ BrowserConfig.ts - prepares and loads configs created by Config.ts below for the browser
ā”‚    ā”œā”€ā”€ Client.tsx - bootstraps the application in the browser
ā”‚    ā”œā”€ā”€ Config.ts - reads the server environment to create a config for the browser
ā”‚    ā”œā”€ā”€ Routes.tsx - uses react-router-dom and react-loadable to describe available routes
ā”‚    ā””ā”€ā”€ Server.ts - the core Express server that builds a BrowserConfig for each request
ā”œā”€ā”€ static - static files made available via the Express server
ā”‚    ā””ā”€ā”€ document.html - a webpack-html-plugin template that Server.ts injects the config into
ā”œā”€ā”€ .babelrc - includes TypeScript, Emotion, and other plugins
ā”œā”€ā”€ Dockerfile - a simple container that uses "yarn run"
ā”œā”€ā”€ tsconfig.json - used by the Babel plugin
ā”œā”€ā”€ tslint.json - starts with Microsoft contrib and overrides a lot
ā””ā”€ā”€ webpack.config.ts - adapted from CRA with customizations

Mobile

To bootstrap a React Native mobile project, use the mobile generator:

mkdir my-new-mobile-project
cd my-new--mobile-project

yo @bkonkle/react:mobile

This results in a React Native application using Expo, with React Navigation for routing.

You'll get a layout that looks like this (abbreviated):

my-new-mobile-project
ā”œā”€ā”€ assets - static resources such as images
ā”œā”€ā”€ src
ā”‚    ā”œā”€ā”€ __tests__ - a stub folder for Jest tests
ā”‚    ā”œā”€ā”€ components - components that handle rendering and presentation
ā”‚    ā”œā”€ā”€ [data] - (same as the web generator)
ā”‚    ā”œā”€ā”€ screens - screens compose components and handle logic and integration
ā”‚    ā”‚    ā””ā”€ā”€ LoginScreen.tsx - the default route, intended to render a login experience
ā”‚    ā”œā”€ā”€ state - (same as the web generator)
ā”‚    ā”œā”€ā”€ Config.ts - sets up config values for all environments, then exports the current values
ā”‚    ā”œā”€ā”€ Routes.ts - uses react-navigation to describe available screens
ā”‚    ā”œā”€ā”€ Theme.ts - some basic app-wide theming tools
ā”‚    ā””ā”€ā”€ Types.ts - some general types used across the app
ā”œā”€ā”€ .babelrc - includes the standard Expo preset
ā”œā”€ā”€ App.js - the Expo entry point, which imports the App.tsx component
ā”œā”€ā”€ tsconfig.json - (same as the web generator)
ā””ā”€ā”€ tslint.json - (same as the web generator)

GraphQL

To bootstrap a GraphQL Api based on Postgraphile, use the graphql generator:

mkdir my-new-graphql-project
cd my-new--graphql-project

yo @bkonkle/react:graphql

This results in an Express API using Postgraphile and Playground as middleware.

my-new-graphql-project
ā”œā”€ā”€ migrations - database schema migrations written in TypeScript and using Knex
ā”œā”€ā”€ sql - sql function definitions that are loaded into Postgres
ā”œā”€ā”€ src
ā”‚    ā”œā”€ā”€ __tests__ - a stub folder for Jest tests
ā”‚    ā”œā”€ā”€ utils - assorted utility modules
ā”‚    ā”‚    ā””ā”€ā”€ MigrationUtils.ts - utilities for Knex schema migrations
ā”‚    ā”œā”€ā”€ Config.ts - reads the environment and exports various config namespaces
ā”‚    ā”œā”€ā”€ Plugins.ts - Postgraphile plugins to extend the GraphQL schema
ā”‚    ā”œā”€ā”€ Server.ts - the main Express pipeline with Postgraphile and Playground
ā”‚    ā””ā”€ā”€ Types.ts - some general types used across the app
ā”œā”€ā”€ knexfile.js - Knex schema migration config
ā”œā”€ā”€ tsconfig.json - (same as the web generator)
ā””ā”€ā”€ tslint.json - (same as the web generator)