react-native init project_name --template react-native-template-typescript
- Somehow it will error, but it's fine.
- Add this dependency,
yarn add @types/react
yarn add @types/react-native
yarn add typescript
- Change
App.js
toApp.tsx
.
- Create a new file
makefile
. - Add some command like
eslint . --cache && tsc --build
, and call itpre-commit
. - Use that command on the
package.json
. - Run
yarn pre-commit
.
npx husky-init && yarn
.- Copy
yarn pre-commit
. yarn pre-commit
will always run when you commit something.
- Add font on
src/Assets/Fonts
. - Create a new file
react-native.config.js
. - Add this code on
react-native.config.js
.
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./src/Assets/Fonts'], // stays the same
};
Add this code on package.json
"rnpm": {
"assets": [
"./src/Assets/Fonts"
]
}
- Run
npx react-native link
.
yarn add react-native-vector-icons
.yarn add @types/react-native-vector-icons
.- Copy the icon from
node_modules/react-native-vector-icons/Fonts
tosrc/Assets/Icons
. - Add
./src/Assets/Icons
inside assets onreact-native.config.js
. - Your
react-native.config.js
should be like this now,
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./src/Assets/Fonts', './src/Assets/Icons'], // stays the same
};
- Add
./src/Assets/Icons
insidernpm.assets
onpackage.json
. - Your
rnpm
onpackage.json
should be like this now,
"rnpm": {
"assets": [
"./src/Assets/Fonts",
"./src/Assets/Icons"
]
}
- Run
react-native link
.
- Open project with xcode cd
ios/open project-name.xcworkspace
. - Remove icons, open
Build Phases
, remove icons fromCopy Bundle Resources
.
yarn add -D @testing-library/react-native @types/jest ts-jest
.- Remove this lint
jest: {}
frompackage.json
. - Create a new file
jest.config.js
./** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ module.exports = { globals: { __DEV__: true, }, preset: 'react-native', testEnvironment: 'node', setupFiles: ['<rootDir>/jest/setup.ts'], testPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/jest'], };
- Create a new folder
jest
and a new filesetup.ts
. - Add this code
"jest/setup.ts"
insidetsconfig.json -> exclude
. - Add this code
ignorePatterns: ['jest/*.ts']
insideeslintrc.js
. - Add this script
"test:coverage": "TZ='Asia/Jakarta' jest --expand --collectCoverage"
and"test:view": "open coverage/lcov-report/index.html"
to collect the coverage code. - Change
pre-commit
insidemakefile
toeslint . --cache && tsc --build && yarn test:coverage -u --runInBand
to generate code coverage when committing.
This is basic ci/cd, to run lint, type check, test, and coverage
when there is a pull request to master
.
- Create a new folder
.github/workflows
fileci.yml
. - Just copy paste the
ci.yml
.
- Clone this repository.
yarn install && yarn pod-install
.yarn start
thenyarn ios
oryarn android
.