bkonkle / generator-react

A Yeoman generator for React-related projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@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)

```sh
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)

About

A Yeoman generator for React-related projects

License:BSD 2-Clause "Simplified" License


Languages

Language:TypeScript 91.3%Language:JavaScript 4.0%Language:Dockerfile 2.8%Language:HTML 1.1%Language:PLpgSQL 0.7%