prepared compatibility with React Native 0.56

This commit is contained in:
Emin Khateeb committed 2018-06-13 17:33:22 +02:00
1 parent c11df248ab
commit 5361316879
4 files changed
+23 -79

No files matched your search

+10 -19
View File
@@ -4,20 +4,17 @@
*
* Generated with the TypeScript template
* https://github.com/emin93/react-native-template-typescript
*
* @format
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' +
'Cmd+D or shake for dev menu',
android: 'Double tap R on your keyboard to reload,\n' +
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
@@ -26,15 +23,9 @@ export default class App extends Component<Props> {
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit App.tsx
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
<Text style={styles.welcome}>Welcome to React Native!</Text>
<Text style={styles.instructions}>To get started, edit App.tsx</Text>
<Text style={styles.instructions}>{instructions}</Text>
</View>
);
}
+4 -28
View File
@@ -31,41 +31,17 @@ node setup.js
- [Type definitions for React & React Native](https://github.com/DefinitelyTyped/DefinitelyTyped)
- [TS Jest](https://github.com/kulshekhar/ts-jest)
This template always uses the latest versions of the dependencies at the time when the setup script (`node setup.js`) is being executed. This means you don't have to worry about old versions.
This template always uses the latest versions of the dependencies at the time when the `react-native init` command is being executed. This means you don't have to worry about old versions.
Lots of :heart: and credits to the owners and maintainers of those packages.
### Why the setup script?
The React Native CLI supports automatic installation of production dependencies only. Since TypeScript and the other dependencies are dev dependencies, the setup script is being used to install those. It also takes care of obsolete files like the `.flowconfig` and the `setup.js` itself after the setup.
It deletes obsolete files like the `.flowconfig` and the `setup.js` itself after the setup.
### How will this template affect the React Native CLI workflow?
### Does debugging work?
The React Native CLI will do everything just as without a template and afterwards overwrite the files with the ones from this template. This means you don't have to worry about incompatibility issues with later React Native upgrades.
### Does debugging work too?
Yes it does, but you need to enable the `sourceMap` option in the `tsconfig.json`.
Make sure it looks something like this:
```json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"module": "es6",
"moduleResolution": "node",
"noEmit": true,
"noImplicitAny": true,
"target": "es6",
"sourceMap": true
},
"exclude": ["node_modules"]
}
```
This is not enabled by default as it is unknown if it has any negative effects on the transpilation time. For more information make sure to check out the [post by Nicolas Hémonic](https://medium.com/@NicolasHemonic/hi-mo-mac-d18286202602).
Yes it does.
## :globe_with_meridians: Links
+9 -9
View File
@@ -1,9 +1,9 @@
[
"@types/jest",
"@types/react",
"@types/react-native",
"@types/react-test-renderer",
"react-native-typescript-transformer",
"ts-jest",
"typescript"
]
{
"@types/jest": "latest",
"@types/react-native": "latest",
"@types/react-test-renderer": "latest",
"@types/react": "latest",
"react-native-typescript-transformer": "latest",
"ts-jest": "latest",
"typescript": "latest"
}
-23
View File
@@ -1,10 +1,8 @@
const fs = require('fs')
const path = require('path')
const {execSync} = require('child_process')
const packageJson = require('./package.json')
const jestConfig = require('./jest.json')
const devDependencies = require('./devDependencies.json')
const deleteFile = (fileName) => {
const filePath = path.join(process.cwd(), fileName)
@@ -16,33 +14,12 @@ const deleteFile = (fileName) => {
fs.unlinkSync(filePath)
}
const writeFile = (fileName, data) => fs.writeFileSync(path.join(process.cwd(), fileName), data)
const isYarnAvailable = () => {
try {
execSync('yarn --version', {stdio: 'ignore'})
return true
} catch (exc) {
return false
}
}
const packageManager = isYarnAvailable() ? 'yarn' : 'npm'
const execOptions = {stdio: 'inherit'}
console.log('🔄 Please wait...\n')
packageJson.jest = Object.assign(packageJson.jest, jestConfig)
writeFile('package.json', JSON.stringify(packageJson, null, 2))
console.log(`📦 Installing dependencies with ${packageManager}...\n`)
switch (packageManager) {
case 'yarn':
execSync(`yarn add ${devDependencies.join(' ')} --dev --exact`, execOptions)
break
default:
execSync(`npm i ${devDependencies.join(' ')} --save-dev --save-exact`, execOptions)
}
deleteFile('App.js')
deleteFile('__tests__/App.js')
deleteFile('.flowconfig')