jeacovy / app-mobile

Crema's starting point for Mobile Apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crema App - Mobile πŸ“±

Build Status License: MIT runs with expo

This project includes configuration and tooling that conforms to Crema's baseline best-practices for a Mobile Application.

🧰 Tools Used

  • Expo for simple configuration πŸ˜…
  • ESLint for code linting
  • Jest for unit tests
  • Loki for visual testing
  • Prettier for code formatting (via ESLint plugin)
  • Storybook for component playground (and used by Loki)
  • TypeScript for Static Typing in JavaScript (Learn)

πŸ— Setup

  1. Install Node/NPM
  2. Install NVM (Node Version Manager)
  3. nvm install 'lts/*' && nvm use
  4. npm i -g expo-cli
  5. npm i (install project dependencies)
  6. Install the ESLint plugin for your editor VS Code
  7. Enable "Auto-Fix on Save" in settings.json:
// There will likely be other settings within this JSON object...
{
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ]
}
  1. Ensure that XCode and the related command line tools are setup using this guide
  2. Ensure that Android Studio and a virtual device (Emulator) are setup using this guide
  3. Ensure that adb is setup correctly, if you have followed step 9 it should be.
    • If adb --version outputs a version then you should be good to go.

πŸ‘Ÿ Run

Start Expo

You can start the expo process with a number of different commands that each do something slightly different.

  • npm start - Starts the expo development server but does not open the app on any devices.
  • npm run start:ios, npm run start:android, npm run start:web - Starts the expo development server and attempts to open the app on a device that matches the platform in the script (i.e. ios, android, or web).
  • npm run start:visual - Starts the expo development server using the storybook entry point (i.e. index.storybook.tsx ) as well as starts the storybook server.

On Device

There are a number of different ways to run your app, some virtual and some on physical hardware.

iOS Simulator

As long as XCode is setup correctly you should be able to start the Simulator directly from the Expo dev tools by pressing i in the terminal, clicking Run on iOS simulator, or by starting the app with npm run start:ios.

Android Emulator

If Android Studio is installed correctly you should be able to open an emulator by following these steps:

  1. Open the Android Studio app
  2. Click the button Configure in the bottom right of the window
  3. Click AVD Manager from the list of options
  4. Click Launch this AVD in the Emulator (It's the green play icon )
    • If there are no devices in the list then create one by clicking Create Virtual Device
  5. You should be able to launch the app on the Emulator from the Expo dev tools by pressing a in the terminal, clicking Run on Android device/emulator, or by starting the app with npm run start:android.

Actual Device

More to come in the future, for now here are some convenient links to consider.

πŸ“‹ Test

Lint

Linting is done with ESlint and Prettier and can be ran with npm run test:lint or npm run test:lint:fix which will attempt to auto-fix any issues that it can.

The relevant configuration files are:

  • .eslintrc.js
  • .prettierrc.js

Types

Type checking is done with tsc and can be ran with npm run test:types or started in watch mode with npm run start:types.

The typescript config is at tsconfig.json.

Unit

Unit testing is done with Jest and can be ran with npm run test:unit or started in watch mode with npm run start:unit.

Visual

Visual testing is done with a combination of Storybook and Loki and has a little more setup that the other test scripts.

Start Storybook

  1. Expo needs to be started with the Storybook root, this is done by running npm run start:visual.
  2. Load the App onto any device you are testing.

At this point clicking on one of the stories in the Web UI should display that story on any device that loaded the App onto.

Story files are first placed in the same directory as the component and then imported into src/stories/index.tsx.

Notes:

  • If you are testing on Android make sure the Android Emulator is already running before you run npm run start:expo. You need to stop any other expo processes before you run this.
  • If you see adb: error: no devices/emulators found then it didn't connect to the Android emulator for some reason.
  • You may need to reload the app on the devices to connect to Storybook, you can do this with CMD+R on iOS or pulling down the notification shade and clicking reload on Android.

Run Loki

To start Loki you run npm run test:visual, npm run test:visual:ios, or npm run test:visual:android depending on which target you want to test.

🚚 Build

More to come in the future, for now here are some convenient links to consider.

Troubleshoot

More to come in the future, for now here are some convenient links to consider.

βš™οΈ Scripts

Run the following scripts with npm run <SCRIPT_HERE>:

  • start - start the expo bundler
  • start:android - start the expo bundler and an android emulator
  • start:ios - start the expo bundler and an iOS simulator
  • start:web - start the expo bundler and the web app
  • start:visual - start component playground with storybook
  • start:types - start tsc in watch mode
  • start:unit - start the unit tests in watch mode
  • test:ci - run the same tests that the CI runs
  • test:types - run tsc
  • test:lint - run linter
  • test:lint:fix - run linter and fix if possible
  • test:unit - run unit tests
  • test:visual - run visual tests with loki (this assumes that storybook is running)
  • test:visual:approve - approve visual changes
  • test:visual:update - update or create visual references
  • new:component - generate a new component
  • new:util - generate a new util
  • new:type - generate a new type

These scripts are located in package.json and do not represent the entirety of available scripts, but are the most commonly used.

πŸ› Structure

The src directory is where the meat of your app is located. Below is a printout of its file-tree with a description for each part.

src
β”œβ”€β”€ assets // Fonts, Images, Etc.
β”‚   └── logo.svg
β”œβ”€β”€ components // Create a new one with `npm run new:component`
β”‚   └── App
β”‚       β”œβ”€β”€ __snapshots__ // Generated by Jest from `test.tsx`
β”‚       β”‚   └── test.tsx.snap
β”‚       β”œβ”€β”€ README.md // Documentation
β”‚       β”œβ”€β”€ index.tsx // Main Module Code
β”‚       β”œβ”€β”€ stories.tsx // Playground stories (npm run test:playground)
β”‚       └── test.tsx // Unit Tests (Jest)
β”œβ”€β”€ types // Centralize Type Definitions
β”‚   β”œβ”€β”€ Entity.ts // Base Type
β”‚   β”œβ”€β”€ EntityThing.ts // A Sub-Type
β”‚   β”œβ”€β”€ Id.ts // A Type Alias of `string`
β”‚   β”œβ”€β”€ MapStateToProps.ts // Includes our `State`
β”‚   β”œβ”€β”€ State.ts // Redux state interface
β”‚   └── Thing.ts // Silly example used by `EntityThing`
β”œβ”€β”€ utils // Create a new one with `npm run new:util`
β”‚   β”œβ”€β”€ mySpecialUtil
β”‚   β”‚   β”œβ”€β”€ __snapshots__ // Generated by Jest from `test.ts`
β”‚   β”‚   β”‚   └── test.tsx.snap
β”‚   β”‚   β”œβ”€β”€ README.md // Documentation
β”‚   β”‚   β”œβ”€β”€ index.tsx // Main Module Code
β”‚   β”‚   └── test.tsx // Unit Tests (Jest)
β”‚   β”œβ”€β”€ decoratorCentered // Used in stories.tsx
β”‚   └── shallowRender // Used to render components in test.tsx
β”œβ”€β”€ stories // Directory used to load storybook stories in one place
β”‚   └── index.tsx
β”œβ”€β”€ index.storybook.tsx // Root Storybook UI Module
└── index.tsx // Root Module

About

Crema's starting point for Mobile Apps

License:MIT License


Languages

Language:TypeScript 98.3%Language:Shell 1.7%