Skip to content

Commit ebadb28

Browse files
authored
add typescript support included in the cli (#179)
1 parent 0fda53b commit ebadb28

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1603
-142
lines changed

Diff for: .github/workflows/CI.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
name: CI
22

33
on:
4+
pull_request:
5+
branches: [ master ]
46
push:
57
branches:
68
- '*'
79

810
jobs:
9-
install-lint-test:
11+
install-lint-test-type:
1012
runs-on: ubuntu-latest
1113
steps:
1214
- uses: actions/checkout@v2
1315
- name: Install yarn dependencies
1416
run: |
1517
cd template
1618
yarn install
19+
yarn add -D typescript @types/jest @types/react @types/react-native @types/react-test-renderer @types/fbemitter @types/react-redux
1720
- name: Run linters
1821
run: |
1922
cd template
@@ -25,3 +28,8 @@ jobs:
2528
cd template
2629
cp src/Config/index.example.js src/Config/index.js
2730
yarn test
31+
- name: Run type check
32+
run: |
33+
cd template
34+
cp plugins/typescript/template/tsconfig.dev.json plugins/typescript/template/tsconfig.json
35+
yarn type-check

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ local.properties
1515
npm-debug.log
1616
yarn-error.log
1717

18+
node_modules
19+
1820
# Ignore specific files copying by RN CLI
1921
template/.gitignore
2022
template/.gitattributes

Diff for: .npmignore

+20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
.DS_Store
2+
build/
3+
.idea
4+
.gradle
5+
local.properties
6+
*.iml
7+
npm-debug.log
8+
yarn-error.log
9+
node_modules
210
template/node_modules
11+
template/src/Config/index.js
12+
template/src/Config/index.ts
13+
template/ts-src-override/tsconfig.dev.ts
14+
template/ts-src-override/tsconfig.ts
315
template/ios/Pods
416
template/android/app/build
517
template/android/.gradle
618
template/android/.idea
19+
template/.buckconfig
20+
template/.eslintrc.js
21+
template/.flowconfig
22+
template/.gitattributes
23+
template/.gitignore
24+
template/.prettierrc.js
25+
template/.watchmanconfig
26+
template/plugins/README.md
727
documentation
828
.idea
929
.github

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018 The Coding Machine
3+
Copyright (c) 2021 The Coding Machine
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+10-25
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
<img src="documentation/static/img/TOM-Legend.png" alt="Logo" width="100%">
33
</div>
44

5-
![GitHub Release Date](https://img.shields.io/github/release-date/thecodingmachine/react-native-boilerplate)
6-
![GitHub last commit](https://img.shields.io/github/last-commit/thecodingmachine/react-native-boilerplate)
7-
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/thecodingmachine/react-native-boilerplate)
8-
![GitHub commits since latest release](https://img.shields.io/github/commits-since/thecodingmachine/react-native-boilerplate/latest)
9-
![GitHub top language](https://img.shields.io/github/languages/top/thecodingmachine/react-native-boilerplate)
5+
![React Native Boilerplate License](https://img.shields.io/github/license/thecodingmachine/react-native-boilerplate)
6+
![React Native Boilerplate Version](https://flat.badgen.net/npm/v/@thecodingmachine/react-native-boilerplate)
7+
![React Native Boilerplate Release Date](https://img.shields.io/github/release-date/thecodingmachine/react-native-boilerplate)
8+
![React Native Boilerplate Download](https://flat.badgen.net/npm/dt/@thecodingmachine/react-native-boilerplate)
9+
![React Native Boilerplate Stars](https://img.shields.io/github/stars/thecodingmachine/react-native-boilerplate)
10+
![React Native Boilerplate Top Language](https://img.shields.io/github/languages/top/thecodingmachine/react-native-boilerplate)
11+
![React Native Boilerplate TypeScript](https://badgen.net/npm/types/tslib)
12+
[![CI](https://github.com/thecodingmachine/react-native-boilerplate/actions/workflows/CI.yml/badge.svg)](https://github.com/thecodingmachine/react-native-boilerplate/actions/workflows/CI.yml)
1013

1114
# TheCodingMachine React Native boilerplate
1215

@@ -18,7 +21,6 @@ The boilerplate provides **an optimized architecture for building solid cross-pl
1821
If you love this boilerplate, give us a star, you will be a ray of sunshine in our lives :)
1922
```
2023

21-
2224
## Requirements
2325

2426
Node 10 or greater is required. Development for iOS requires a Mac and Xcode 9.4 or up, and will target iOS 9 and up.
@@ -35,27 +37,10 @@ To create a new project using the boilerplate simply run :
3537
npx react-native init MyApp --template @thecodingmachine/react-native-boilerplate
3638
```
3739

38-
Assuming you have all the requirements installed, you can setup and run the project by running:
39-
40-
- `yarn install` to install the dependencies
41-
- run the following steps for your platform
42-
43-
### Android
44-
45-
- only the first time you run the project, you need to generate a `debug key` with:
46-
- `cd android/app`
47-
- `keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000`
48-
- `cd ../..` to come back to the root folder
49-
- `yarn start` to start the metro bundler, in a dedicated terminal
50-
- `yarn android` to run the Android application (remember to start a simulator or connect an Android phone)
51-
52-
### iOS
40+
Assuming you have all the requirements installed, you can run the project by running:
5341

54-
- `cd ios`
55-
- `pod install` to install pod dependencies
56-
- `cd ..` to come back to the root folder
5742
- `yarn start` to start the metro bundler, in a dedicated terminal
58-
- `yarn ios` to run the iOS application (remember to start a simulator or connect an iPhone phone)
43+
- `yarn <platform>` to run the *platform* application (remember to start a simulator or connect a device)
5944

6045
## Digging Deeper
6146

Diff for: documentation/docs/1_Introduction/1_1_RNBoilerplate.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ The driving goal of the architecture of the boilerplate is separation of concern
4343

4444
The boilerplate contains:
4545

46-
- a [React Native](https://facebook.github.io/react-native/) (v**0.63.3**) application (in "[ejected](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md)" mode to allow using dependencies that rely on native code)
46+
- a [React Native](https://facebook.github.io/react-native/) (v**0.64.0**) application (in "[ejected](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md)" mode to allow using dependencies that rely on native code)
4747
- a [clear directory layout](#directory-layout) to provide a base architecture for your application
4848
- [Redux](https://redux.js.org/) (v**4.0.5**) to help manage state
4949
- [Redux Persist](https://github.com/rt2zz/redux-persist) (v**6.0.0**) to persist the Redux state
5050
- [React Navigation](https://reactnavigation.org/) (v**5**) to handle routing and navigation in the app, with a splash screen setup by default
51-
- [redux toolkit](https://github.com/infinitered/reduxsauce) (v**1.4.0**) to make redux easier
52-
- [axios](https://github.com/axios/axios) (v**0.20.0**) to make API calls
51+
- [redux toolkit](https://github.com/infinitered/reduxsauce) (v**1.5.0**) to make redux easier
52+
- [axios](https://github.com/axios/axios) (v**0.21.1**) to make API calls
5353
- [prettier](https://prettier.io/) and [eslint](https://eslint.org/) preconfigured for React Native
54-
- [react-native-flipper](https://fbflipper.com/) (v**0.62.0**) to debug react-native and [redux-flipper](https://github.com/jk-gan/redux-flipper) (v**1.3.2**) to debug redux
54+
- [react-native-flipper](https://fbflipper.com/) (v**0.75.1**) to debug react-native and [redux-flipper](https://github.com/jk-gan/redux-flipper) (v**1.4.2**) to debug redux
5555

5656
The boilerplate includes an example (displaying fake user data) from UI components to the business logic. The example is easy to remove so that it doesn't get in the way.
5757

Diff for: documentation/docs/2_Getting Started/2_1_Installation.md

+7-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ title: Installation
55

66
## Requirements
77

8-
Node 10 or greater is required. Development for iOS requires a Mac and Xcode 9.4 or up, and will target iOS 9 and up.
8+
Node 12 or greater is required. Development for iOS requires a Mac and Xcode 10 or up.
99

1010
You also need to install the dependencies required by React Native:
1111

@@ -20,26 +20,14 @@ To create a new project using the boilerplate simply run :
2020
npx react-native init MyApp --template @thecodingmachine/react-native-boilerplate
2121
```
2222

23-
## Running the project
24-
25-
Assuming you have all the requirements installed, you can setup and run the project by running:
26-
27-
- `yarn install` to install the dependencies
28-
- run the following steps for your platform
23+
## Running with typescript
2924

30-
### Android
25+
During the installation the cli will ask you if you want to use typescript, tap on the `y` key and all the requirement will be set.
26+
to type check your project just run `yarn tsc`.
3127

32-
- only the first time you run the project, you need to generate a debug key with:
33-
- `cd android/app`
34-
- `keytool -genkey -v -keystore debug.keystore -storepass android -alias androiddebugkey -keypass android -keyalg RSA -keysize 2048 -validity 10000`
35-
- `cd ../..` to come back to the root folder
36-
- `yarn start` to start the metro bundler, in a dedicated terminal
37-
- `yarn android` to run the Android application (remember to start a simulator or connect an Android phone)
28+
## Running the project
3829

39-
### iOS
30+
Assuming you have all the requirements installed, you can run the project by running:
4031

41-
- `cd ios`
42-
- `pod install` to install pod dependencies
43-
- `cd ..` to come back to the root folder
4432
- `yarn start` to start the metro bundler, in a dedicated terminal
45-
- `yarn ios` to run the iOS application (remember to start a simulator or connect an iPhone phone)
33+
- `yarn <platform>` to run the *platform* application (remember to start a simulator or connect a device)

Diff for: documentation/docs/3_Guides/3_4_ReduxStore.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ For each wrapped action, a reducer is associated.
7575

7676
## Redux-toolkit-wrapper
7777
The boilerplate includes a [wrapper of redux-toolkit](https://github.com/thecodingmachine/redux-toolkit-wrapper) to make it easier to use. It provides three helpers.
78-
If your are not familiar with redux-toolkit, please have a look at their [documentation](https://redux-toolkit.js.org/api/configureStore).
78+
If you are not familiar with redux-toolkit, please have a look at their [documentation](https://redux-toolkit.js.org/api/configureStore).
7979

8080
### buildAsyncState
8181
`buildAsyncState` create a loading and error state. You can scope it in a key.
@@ -121,7 +121,7 @@ Will generate:
121121

122122
Where fetchOneUserService is an async function.
123123
So, when the fetchOneUserService is launched the action `user/fetchOne/pending` is dispatched.
124-
When the fetchOneUserService is endded the action `user/fetchOne/fulfilled` is dispatched.
124+
When the fetchOneUserService is ended the action `user/fetchOne/fulfilled` is dispatched.
125125
When the fetchOneUserService throw an error the action `user/fetchOne/rejected` is dispatched.
126126

127127
### buildAsyncReducers

Diff for: package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thecodingmachine/react-native-boilerplate",
3-
"version": "2.2.5",
3+
"version": "3.0.0",
44
"description": "TheCodingMachine React Native Boilerplate",
55
"repository": {
66
"type": "git",
@@ -23,5 +23,9 @@
2323
"thecodingmachine",
2424
"react-native",
2525
"starter-kit"
26-
]
26+
],
27+
"dependencies": {
28+
"prompts": "^2.4.1",
29+
"kleur": "^4.1.4"
30+
}
2731
}

Diff for: post-init.script.js

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,7 @@
11
#!/usr/bin/env node
2+
const { rmdir } = require('fs').promises;
3+
const { applyPlugins } = require('./template/plugins');
24

3-
const fs = require('fs')
4-
fs.copyFile('src/Config/index.example.js', 'src/Config/index.js', (err) => {
5-
if (err) throw err;
6-
console.log('src/Config/index.example.js was copied to src/Config/index.js');
5+
applyPlugins().then(async () => {
6+
await rmdir('./plugins', { recursive: true });
77
});
8-
9-
console.log("TheCodingMachine React-Native Boilerplate initialized with success !");
10-
console.log("" +
11-
" .-` `:: \n" +
12-
" `///////////// `/shhhy+- ://. /sy/ /ss/ :NMN: \n" +
13-
" `sssssyhhhyhhy:` `yMMMMNNMMMd. osss: `hMMMh- .-` `+ss: +MMm/. \n" +
14-
" :MMM+----. `mMMm+:-`.oo/` osssyo` `dMMMMh- ohhh- `oyy+- sMMd/. \n" +
15-
" :MMM+` oMMN/- osssyhs`.mMMMMMh- -hds` .syy+- `hMMh:` \n" +
16-
" :MMM+` hMMd: oss-ohhhMMMhdMMh- `. +NNm/. .dMMy:` \n" +
17-
" :MMM+` oMMN/ oss-`shdMMd:dMMh- :-` sMMd/. -NMMo- \n" +
18-
" :MMM+` `mMMm/` `/+:. oss- `sdMd:.hMMh- hMys- `hMMh:` -hdy-` \n" +
19-
" :MMM+` `yMMMMdssss+ oss. `oh/- hMMh- -hyo: dMMs:` -ss+` \n" +
20-
" .oys:` .+yhyo/- -::` `` -syo- ..` +mo- `// \n" +
21-
" `` ``` `` `. ")
22-
23-
console.log('- If you need to read more about this boilerplate : https://thecodingmachine.github.io/react-native-boilerplate/')
24-
console.log('- If you have some troubles : https://github.com/thecodingmachine/react-native-boilerplate/issues')
25-
console.log('- If you love this boilerplate, give us a star, you will be a ray of sunshine in our lives :) https://github.com/thecodingmachine/react-native-boilerplate')

Diff for: template/_eslintrc.js

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ module.exports = {
99
semi: ['error', 'never'],
1010
'object-curly-spacing': ['error', 'always'],
1111
'array-bracket-spacing': ['error', 'never'],
12+
'react/require-default-props': ['error'],
13+
'react/default-props-match-prop-types': ['error'],
14+
'react/sort-prop-types': ['error'],
1215
},
1316
settings: {
1417
'import/resolver': {

Diff for: template/_gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ buck-out/
5757

5858
# CocoaPods
5959
/ios/Pods/
60+
61+
template/plugins/typescript/template/tsconfig.json

Diff for: template/package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "boilerplate",
3-
"version": "2.2.5",
3+
"version": "3.0.0",
44
"private": true,
55
"scripts": {
66
"android": "react-native run-android",
77
"ios": "react-native run-ios",
88
"start": "react-native start",
99
"test": "jest",
10-
"lint": "eslint ."
10+
"lint": "eslint .",
11+
"type-check": "tsc --build plugins/typescript/template/tsconfig.json"
1112
},
1213
"dependencies": {
1314
"@react-native-async-storage/async-storage": "^1.14.1",
@@ -16,9 +17,10 @@
1617
"@react-navigation/native": "^5.9.3",
1718
"@react-navigation/stack": "^5.14.3",
1819
"@reduxjs/toolkit": "^1.5.0",
19-
"@thecodingmachine/redux-toolkit-wrapper": "1.3.0",
20+
"@thecodingmachine/redux-toolkit-wrapper": "2.0.1",
2021
"axios": "^0.21.1",
2122
"i18next": "^19.9.2",
23+
"prop-types": "^15.7.2",
2224
"react": "17.0.1",
2325
"react-i18next": "^11.8.10",
2426
"react-native": "0.64.0",

Diff for: template/plugins/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# PLUGINS
2+
3+
Now we introduce the plugins system to be able to add, remove, print, normalize every file/directory into the boilerplate during the installation.
4+
With this system, we have added the typescript support.
5+
6+
## Plugin definition
7+
A plugin is defined by 3 files :
8+
- _prompts.js
9+
- plugin.js
10+
- index.js
11+
12+
| Files | Type | Description |
13+
| :----------- | :---------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
14+
| _prompts.js | `module.exports = <PromptObject> / module.exports = null` | The `<PromptObject>` definition available [here](https://github.com/terkelg/prompts#-prompt-objects). `null` means, the plugin doesn't need prompts to run. |
15+
| plugin.js | `module.exports = { async apply(value, previousValues) { // Add code here }}` | The `apply` function is the one that apply the refactoring of the boilerplate. `value` is the result of the prompt, `previousValues` is previous responses of previous prompts and it's defined like `{ <plugin_name>: <value> }`. |
16+
| index.js | `module.exports = { name: <pluginName>, <promptsOptions>, <apply> }` | The `pluginName` is a string, `promptsOptions` is imported from `_prompts.js` and apply from `plugin.js`. |
17+
18+
## files structure
19+
20+
### _prompts.js
21+
``` javascript
22+
module.exports = {
23+
type: 'confirm',
24+
name: 'value', // Always use value
25+
message: 'Using typescript ?',
26+
initial: false,
27+
}
28+
```
29+
### plugin.js
30+
```javascript
31+
const { green, blue } = require('kleur')
32+
33+
module.exports = {
34+
async apply(value, previousValues) {__
35+
return new Promise(resolve => {
36+
if (value) {
37+
console.log('TheCodingMachine React-Native Boilerplate initialized the TYPESCRIPT please wait !',)
38+
} else {
39+
console.log('TheCodingMachine React-Native Boilerplate initialized the JAVASCRIPT please wait !',)
40+
}
41+
resolve()
42+
})
43+
},
44+
}
45+
46+
```
47+
### index.js
48+
```javascript
49+
const promptsOptions = require('./_prompts');
50+
const { apply } = require('./plugin');
51+
52+
module.exports = {
53+
name: 'typescript',
54+
promptsOptions,
55+
apply,
56+
};
57+
```

0 commit comments

Comments
 (0)