diff --git a/README.md b/README.md index 75aed91b989..b7fc5c6a6e4 100644 --- a/README.md +++ b/README.md @@ -1,203 +1,5 @@ -# Create React App [![Build Status](https://travis-ci.org/facebook/create-react-app.svg?branch=master)](https://travis-ci.org/facebook/create-react-app) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-green.svg)](https://github.com/facebook/create-react-app/pulls) +# JetBridge Starter Kit -Create React apps with no build configuration. +### To use: -- [Creating an App](#creating-an-app) – How to create a new app. -- [User Guide](https://facebook.github.io/create-react-app/) – How to develop apps bootstrapped with Create React App. - -Create React App works on macOS, Windows, and Linux.
-If something doesn’t work, please [file an issue](https://github.com/facebook/create-react-app/issues/new). - -## Quick Overview - -```sh -npx create-react-app my-app -cd my-app -npm start -``` - -_([npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) comes with npm 5.2+ and higher, see [instructions for older npm versions](https://gist.github.com/gaearon/4064d3c23a77c74a3614c498a8bb1c5f))_ - -Then open [http://localhost:3000/](http://localhost:3000/) to see your app.
-When you’re ready to deploy to production, create a minified bundle with `npm run build`. - -

-npm start -

- -### Get Started Immediately - -You **don’t** need to install or configure tools like Webpack or Babel.
-They are preconfigured and hidden so that you can focus on the code. - -Just create a project, and you’re good to go. - -## Creating an App - -**You’ll need to have Node 8.10.0 or later on your local development machine** (but it’s not required on the server). You can use [nvm](https://github.com/creationix/nvm#installation) (macOS/Linux) or [nvm-windows](https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows) to easily switch Node versions between different projects. - -To create a new app, you may choose one of the following methods: - -### npx - -```sh -npx create-react-app my-app -``` - -_([npx](https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b) comes with npm 5.2+ and higher, see [instructions for older npm versions](https://gist.github.com/gaearon/4064d3c23a77c74a3614c498a8bb1c5f))_ - -### npm - -```sh -npm init react-app my-app -``` - -_`npm init ` is available in npm 6+_ - -### Yarn - -```sh -yarn create react-app my-app -``` - -_`yarn create` is available in Yarn 0.25+_ - -It will create a directory called `my-app` inside the current folder.
-Inside that directory, it will generate the initial project structure and install the transitive dependencies: - -``` -my-app -├── README.md -├── node_modules -├── package.json -├── .gitignore -├── public -│ ├── favicon.ico -│ ├── index.html -│ └── manifest.json -└── src - ├── App.css - ├── App.js - ├── App.test.js - ├── index.css - ├── index.js - ├── logo.svg - └── serviceWorker.js -``` - -No configuration or complicated folder structures, just the files you need to build your app.
-Once the installation is done, you can open your project folder: - -```sh -cd my-app -``` - -Inside the newly created project, you can run some built-in commands: - -### `npm start` or `yarn start` - -Runs the app in development mode.
-Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will automatically reload if you make changes to the code.
-You will see the build errors and lint warnings in the console. - -

-Build errors -

- -### `npm test` or `yarn test` - -Runs the test watcher in an interactive mode.
-By default, runs tests related to files changed since the last commit. - -[Read more about testing.](https://facebook.github.io/create-react-app/docs/running-tests) - -### `npm run build` or `yarn build` - -Builds the app for production to the `build` folder.
-It correctly bundles React in production mode and optimizes the build for the best performance. - -The build is minified and the filenames include the hashes.
- -Your app is ready to be deployed. - -## User Guide - -You can find detailed instructions on using Create React App and many tips in [its documentation](https://facebook.github.io/create-react-app/). - -## How to Update to New Versions? - -Please refer to the [User Guide](https://facebook.github.io/create-react-app/docs/updating-to-new-releases) for this and other information. - -## Philosophy - -- **One Dependency:** There is just one build dependency. It uses Webpack, Babel, ESLint, and other amazing projects, but provides a cohesive curated experience on top of them. - -- **No Configuration Required:** You don't need to configure anything. A reasonably good configuration of both development and production builds is handled for you so you can focus on writing code. - -- **No Lock-In:** You can “eject” to a custom setup at any time. Run a single command, and all the configuration and build dependencies will be moved directly into your project, so you can pick up right where you left off. - -## What’s Included? - -Your environment will have everything you need to build a modern single-page React app: - -- React, JSX, ES6, TypeScript and Flow syntax support. -- Language extras beyond ES6 like the object spread operator. -- Autoprefixed CSS, so you don’t need `-webkit-` or other prefixes. -- A fast interactive unit test runner with built-in support for coverage reporting. -- A live development server that warns about common mistakes. -- A build script to bundle JS, CSS, and images for production, with hashes and sourcemaps. -- An offline-first [service worker](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers) and a [web app manifest](https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/), meeting all the [Progressive Web App](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) criteria. (_Note: Using the service worker is opt-in as of `react-scripts@2.0.0` and higher_) -- Hassle-free updates for the above tools with a single dependency. - -Check out [this guide](https://github.com/nitishdayal/cra_closer_look) for an overview of how these tools fit together. - -The tradeoff is that **these tools are preconfigured to work in a specific way**. If your project needs more customization, you can ["eject"](https://facebook.github.io/create-react-app/docs/available-scripts#npm-run-eject) and customize it, but then you will need to maintain this configuration. - -## Popular Alternatives - -Create React App is a great fit for: - -- **Learning React** in a comfortable and feature-rich development environment. -- **Starting new single-page React applications.** -- **Creating examples** with React for your libraries and components. - -Here are a few common cases where you might want to try something else: - -- If you want to **try React** without hundreds of transitive build tool dependencies, consider [using a single HTML file or an online sandbox instead](https://reactjs.org/docs/try-react.html). - -- If you need to **integrate React code with a server-side template framework** like Rails, Django or Symfony, or if you’re **not building a single-page app**, consider using [nwb](https://github.com/insin/nwb), or [Neutrino](https://neutrino.js.org/) which are more flexible. For Rails specifically, you can use [Rails Webpacker](https://github.com/rails/webpacker). For Symfony, try [Symfony's Webpack Encore](https://symfony.com/doc/current/frontend/encore/reactjs.html). - -- If you need to **publish a React component**, [nwb](https://github.com/insin/nwb) can [also do this](https://github.com/insin/nwb#react-components-and-libraries), as well as [Neutrino's react-components preset](https://neutrino.js.org/packages/react-components/). - -- If you want to do **server rendering** with React and Node.js, check out [Next.js](https://github.com/zeit/next.js/) or [Razzle](https://github.com/jaredpalmer/razzle). Create React App is agnostic of the backend, and just produces static HTML/JS/CSS bundles. - -- If your website is **mostly static** (for example, a portfolio or a blog), consider using [Gatsby](https://www.gatsbyjs.org/) instead. Unlike Create React App, it pre-renders the website into HTML at the build time. - -- Finally, if you need **more customization**, check out [Neutrino](https://neutrino.js.org/) and its [React preset](https://neutrino.js.org/packages/react/). - -All of the above tools can work with little to no configuration. - -If you prefer configuring the build yourself, [follow this guide](https://reactjs.org/docs/add-react-to-an-existing-app.html). - -## Contributing - -We'd love to have your helping hand on `create-react-app`! See [CONTRIBUTING.md](CONTRIBUTING.md) for more information on what we're looking for and how to get started. - -## React Native - -Looking for something similar, but for React Native?
-Check out [Expo CLI](https://github.com/expo/expo-cli). - -## Acknowledgements - -We are grateful to the authors of existing related projects for their ideas and collaboration: - -- [@eanplatter](https://github.com/eanplatter) -- [@insin](https://github.com/insin) -- [@mxstbr](https://github.com/mxstbr) - -## License - -Create React App is open source software [licensed as MIT](https://github.com/facebook/create-react-app/blob/master/LICENSE). +`create-react-app myapp --typescript --scripts-version jetbridge-react-scripts` diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index e4a93a37e03..2a5d67b49be 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -1,10 +1,10 @@ { - "name": "react-scripts", - "version": "3.0.1", + "name": "jetbridge-react-scripts", + "version": "1.0.0", "description": "Configuration and scripts for Create React App.", "repository": { "type": "git", - "url": "https://github.com/facebook/create-react-app.git", + "url": "https://github.com/jetbridge/create-react-app.git", "directory": "packages/react-scripts" }, "license": "MIT", @@ -12,7 +12,7 @@ "node": ">=8.10" }, "bugs": { - "url": "https://github.com/facebook/create-react-app/issues" + "url": "https://github.com/jetbridge/create-react-app/issues" }, "files": [ "bin", diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 9b473ab3d95..a6d0a3cd992 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -32,6 +32,10 @@ function isInGitRepository() { } } +function initStorybook() { + execSync('npx -p @storybook/cli sb init'); +} + function isInMercurialRepository() { try { execSync('hg --cwd . root', { stdio: 'ignore' }); @@ -91,6 +95,38 @@ module.exports = function( // Copy over some of the devDependencies appPackage.dependencies = appPackage.dependencies || {}; + appPackage.dependencies = { + ...appPackage.dependencies, + axios: 'latest', + classnames: 'latest', + '@jetbridge/frontend-core': + 'git+ssh://git@github.com:jetbridge/frontend-core.git', + }; + + appPackage.devDependencies = { + '@storybook/addon-actions': 'latest', + '@storybook/addon-centered': 'latest', + '@storybook/addon-info': 'latest', + '@storybook/addon-links': 'latest', + '@storybook/addons': 'latest', + '@types/node': 'latest', + '@types/react': 'latest', + '@types/storybook__react': 'latest', + 'lint-staged': 'latest', + prettier: 'latest', + eslint: 'latest', + husky: 'latest', + }; + + appPackage.husky = { + hooks: { + 'pre-commit': 'lint-staged', + }, + }; + appPackage['lint-staged'] = { + '**/*.{js,jsx,ts,tsx}': ['prettier --write', 'eslint --fix', 'git add'], + }; + const useTypeScript = appPackage.dependencies['typescript'] != null; // Setup the script rules @@ -99,11 +135,9 @@ module.exports = function( build: 'react-scripts build', test: 'react-scripts test', eject: 'react-scripts eject', - }; - - // Setup the eslint config - appPackage.eslintConfig = { - extends: 'react-app', + lint: 'eslint src/**/*.ts src/**/*.tsx', + fix: + 'prettier --write src/**/*.ts src/**/*.tsx && eslint --fix src/**/*.ts src/**/*.tsx', }; // Setup the browsers list @@ -204,6 +238,9 @@ module.exports = function( console.log('Initialized a git repository.'); } + console.log('Initializing storybook...'); + initStorybook(); + // Display the most elegant way to cd. // This needs to handle an undefined originalDirectory for // backward compatibility with old global-cli's. @@ -255,7 +292,7 @@ module.exports = function( ); } console.log(); - console.log('Happy hacking!'); + console.log(chalk.green("Let's Make It Happen!")); }; function isReactInstalled(appPackage) { diff --git a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js index a73b8c0db3b..ad22009c608 100644 --- a/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js +++ b/packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js @@ -257,7 +257,7 @@ function verifyTypeScriptSetup() { if (!fs.existsSync(paths.appTypeDeclarations)) { fs.writeFileSync( paths.appTypeDeclarations, - `/// ${os.EOL}` + `/// ${os.EOL}` ); } } diff --git a/packages/react-scripts/template-typescript/.circleci/config.yml b/packages/react-scripts/template-typescript/.circleci/config.yml new file mode 100644 index 00000000000..313eaba3e7c --- /dev/null +++ b/packages/react-scripts/template-typescript/.circleci/config.yml @@ -0,0 +1,48 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2 +jobs: + build: + docker: + - image: circleci/node:10 + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: Install yarn dependencies + command: yarn install + - run: + name: Install JUnit coverage reporter + command: yarn add --dev jest-junit + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + - run: + name: Build application + command: + yarn build + - run: + name: ESLint + command: | + mkdir -p ~/reports + yarn lint --format junit --output-file ~/reports/eslint.xml + - run: + name: Run tests + command: yarn test --coverage --collectCoverage=true --runInBand --reporters=default --reporters=jest-junit + environment: + JEST_JUNIT_OUTPUT: 'reports/junit/js-test-results.xml' + - store_test_results: + path: reports + - store_artifacts: + path: coverage diff --git a/packages/react-scripts/template-typescript/.eslintrc.js b/packages/react-scripts/template-typescript/.eslintrc.js new file mode 100644 index 00000000000..e70e017f24e --- /dev/null +++ b/packages/react-scripts/template-typescript/.eslintrc.js @@ -0,0 +1,29 @@ +module.exports = { + parser: '@typescript-eslint/parser', + extends: ['plugin:@typescript-eslint/recommended', 'plugin:react/recommended', 'react-app'], + plugins: ['@typescript-eslint', 'react'], + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + settings: { + react: { + version: 'detect', + }, + }, + rules: { + '@typescript-eslint/indent': ['warn', 2], + '@typescript-eslint/interface-name-prefix': 'off', + '@typescript-eslint/camelcase': 'off', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/explicit-member-accessibility': 'off', + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/class-name-casing': 'warn', // withTheme, etc + '@typescript-eslint/explicit-function-return-type': 'off', // just infer it... + 'react/prop-types': 'off', // use TS + '@typescript-eslint/member-delimiter-style': 'off', + 'jsx-a11y/alt-text': 'off', + '@typescript-eslint/prefer-interface': 'off', + }, +} diff --git a/packages/react-scripts/template-typescript/.prettierrc.yaml b/packages/react-scripts/template-typescript/.prettierrc.yaml new file mode 100644 index 00000000000..435d2da7e0e --- /dev/null +++ b/packages/react-scripts/template-typescript/.prettierrc.yaml @@ -0,0 +1,5 @@ +tabWidth: 2 +semi: false +singleQuote: true +printWidth: 120 +trailingComma: es5 diff --git a/packages/react-scripts/template-typescript/.storybook/addons.js b/packages/react-scripts/template-typescript/.storybook/addons.js new file mode 100644 index 00000000000..402ccc13eba --- /dev/null +++ b/packages/react-scripts/template-typescript/.storybook/addons.js @@ -0,0 +1,2 @@ +import '@storybook/addon-actions/register' +import '@storybook/addon-links/register' diff --git a/packages/react-scripts/template-typescript/README.md b/packages/react-scripts/template-typescript/README.md index 897dc836601..51e34f1d79f 100644 --- a/packages/react-scripts/template-typescript/README.md +++ b/packages/react-scripts/template-typescript/README.md @@ -1,10 +1,14 @@ -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). +# JetBridge Frontend Starter Kit + +For best practices, consult [Notion](https://www.notion.so/jetbridge/Starting-A-New-Project-cf03a080207b4569b53bb3b7d06f7f2c). + +This project was bootstrapped with [Create React App](https://github.com/jetbridge/create-react-app) ## Available Scripts In the project directory, you can run: -### `npm start` +### `yarn start` Runs the app in the development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. @@ -12,12 +16,12 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser. The page will reload if you make edits.
You will also see any lint errors in the console. -### `npm test` +### `yarn test` Launches the test runner in the interactive watch mode.
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. -### `npm run build` +### `yarn build` Builds the app for production to the `build` folder.
It correctly bundles React in production mode and optimizes the build for the best performance. @@ -27,18 +31,106 @@ Your app is ready to be deployed! See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. -### `npm run eject` +### `yarn storybook` + +Launches the [storybook](https://github.com/storybooks/storybook) environment. + +### `yarn lint` + +Runs linter over all files in `./src` folder and its subfolders + +### `yarn fix` + +Runs linter over all files in `./src` folder and its subfolders and applies the code formatting fixes where possible + +### `yarn test` + +Runs jest tests in a watch mode + +## Code style + +### Basic Rules + +- Only include one React component per file. + - However, multiple [Stateless, or Pure, Components](https://facebook.github.io/react/docs/reusable-components.html#stateless-functions) are allowed per file +- Always use TSX syntax. + +### Indentation: + +Use 2 spaces for indentation + +### Naming: + +- **Extensions**: Use `.tsx` extension for React components. +- **Filename**: Use PascalCase for filenames. E.g., `AdminDashboard.tsx`. + **Reference Naming**: Use PascalCase for React components and camelCase for their instances. + +```tsx +// bad +import reservationCard from './ReservationCard' + +// good +import ReservationCard from './ReservationCard' + +// bad +const ReservationItem = + +// good +const reservationItem = +``` + +- **Component Naming**: Use the filename as the component name. For example, `ReservationCard.tsx` should have a reference name of `ReservationCard`. However, for root components of a directory, use `index.tsx` as the filename and use the directory name as the component name: + + ```tsx + // bad + import Footer from './Footer/Footer' + + // bad + import Footer from './Footer/index' + + // good + import Footer from './Footer' + ``` + +- **Types naming**: interface names should start with I: + `tsx ILoginScreenProps: { }` + +- **Higher-order Component Naming**: Use a composite of the higher-order component’s name and the passed-in component’s name as the `displayName` on the generated component. For example, the higher-order component `withFoo()`, when passed a component `Bar` should produce a component with a `displayName` of `withFoo(Bar)`. + +### Types: + +Always specify prop types and state types for components and functions. Return types for API Requests are required. + +### Props -**Note: this is a one-way operation. Once you `eject`, you can’t go back!** +- Always use camelCase for prop names. -If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + ```tsx + // bad + -Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + // good + + ``` -You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. +- We don’t recommend using indexes for keys if the order of items may change. -## Learn More +```tsx +// bad +{ + todos.map((todo, index) => ) +} -You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). +// good +{ + todos.map(todo => ) +} +``` -To learn React, check out the [React documentation](https://reactjs.org/). +- Do not do props drilling. We recommend using [React Context API](https://reactjs.org/docs/context.html) for passing props down to the children's children components. diff --git a/packages/react-scripts/template-typescript/public/favicon.ico b/packages/react-scripts/template-typescript/public/favicon.ico deleted file mode 100644 index a11777cc471..00000000000 Binary files a/packages/react-scripts/template-typescript/public/favicon.ico and /dev/null differ diff --git a/packages/react-scripts/template-typescript/public/index.html b/packages/react-scripts/template-typescript/public/index.html index dd1ccfd4cd3..d3249b9b42e 100644 --- a/packages/react-scripts/template-typescript/public/index.html +++ b/packages/react-scripts/template-typescript/public/index.html @@ -19,7 +19,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + JetBridge App diff --git a/packages/react-scripts/template-typescript/public/manifest.json b/packages/react-scripts/template-typescript/public/manifest.json index 1f2f141fafd..df642cd44fe 100644 --- a/packages/react-scripts/template-typescript/public/manifest.json +++ b/packages/react-scripts/template-typescript/public/manifest.json @@ -1,6 +1,6 @@ { - "short_name": "React App", - "name": "Create React App Sample", + "short_name": "JetBridge App", + "name": "JetBridge App Starter Kit", "icons": [ { "src": "favicon.ico", diff --git a/packages/react-scripts/template-typescript/src/App.css b/packages/react-scripts/template-typescript/src/App.css deleted file mode 100644 index b41d297cab1..00000000000 --- a/packages/react-scripts/template-typescript/src/App.css +++ /dev/null @@ -1,33 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - animation: App-logo-spin infinite 20s linear; - height: 40vmin; - pointer-events: none; -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/packages/react-scripts/template-typescript/src/App.tsx b/packages/react-scripts/template-typescript/src/App.tsx index 226ee6316af..7407deeb593 100644 --- a/packages/react-scripts/template-typescript/src/App.tsx +++ b/packages/react-scripts/template-typescript/src/App.tsx @@ -1,26 +1,12 @@ -import React from 'react'; -import logo from './logo.svg'; -import './App.css'; +import * as React from 'react' const App: React.FC = () => { return ( -
-
- logo -

- Edit src/App.tsx and save to reload. -

- - Learn React - -
+
+

New JetBridge App!

+

Enjoy!

- ); + ) } -export default App; +export default App diff --git a/packages/react-scripts/template-typescript/src/logo.svg b/packages/react-scripts/template-typescript/src/logo.svg deleted file mode 100644 index 6b60c1042f5..00000000000 --- a/packages/react-scripts/template-typescript/src/logo.svg +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - -