cremalab / app-mobile

Crema's starting point for Mobile Apps
MIT License
4 stars 3 forks source link

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

πŸ— 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"
    ]
    }
  8. Ensure that XCode and the related command line tools are setup using this guide
  9. Ensure that Android Studio and a virtual device (Emulator) are setup using this guide
  10. 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.

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:

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:

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>:

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