Compare commits

...
17 Commits
Author SHA1 Message Date
Emin Khateeb 10fac6c22f Update tsconfig.json
reverted wrong react jsx mode
2018-07-03 11:24:48 +02:00
Emin Khateeb 172b32155d Update tsconfig.json
addressed issue (https://github.com/emin93/react-native-template-typescript/issues/17) which caused typescript to fail compilation of a newly created project
2018-07-03 11:24:03 +02:00
Emin Khateeb 2d7334d61e setup can now be done with a single line command 2018-06-14 12:51:19 +02:00
Emin Khateeb caae886d8f setup script is now working dir independent 2018-06-14 12:25:57 +02:00
Emin Khateeb 270f516448 Update setup.js
now also deleting devDependencies.json after the setup
2018-06-14 11:04:23 +02:00
Emin Khateeb 8ed8b19828 fixed delete method 2018-06-14 10:06:43 +02:00
Emin Khateeb c66f735c19 removed deletes of non-existing files 2018-06-14 10:05:17 +02:00
Emin Khateeb b2f6208cb4 minor wording change 2018-06-14 08:36:41 +02:00
Emin Khateeb 3b10c51f74 removed npm version badge 2018-06-13 20:48:01 +02:00
Emin Khateeb 8d885ab3f5 Simplified README.md 2018-06-13 19:35:56 +02:00
Emin Khateeb b937346ac2 Merge pull request #16 from emin93/rn-0.56
RN 0.56 support
2018-06-13 18:44:26 +02:00
Emin Khateeb cd047d58f0 added link to Albert Gao's article 2018-06-13 18:32:35 +02:00
Emin Khateeb 6a8da82688 added demonstration of working breakpoints 2018-06-13 18:16:16 +02:00
Emin Khateeb ac23b8ac83 removed tests directory to be more consistent with the latest rn 2018-06-13 18:04:48 +02:00
Emin Khateeb 987fe89238 removed reference to package manager 2018-06-13 17:52:27 +02:00
Emin Khateeb 5361316879 prepared compatibility with React Native 0.56 2018-06-13 17:33:22 +02:00
Emin Khateeb c11df248ab changed jsx mode to react-native 2018-06-13 17:17:27 +02:00
6 changed files with 47 additions and 124 deletions

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>
);
}
+20 -45
View File
@@ -1,75 +1,50 @@
# :space_invader: React Native Template TypeScript · [![npm](https://img.shields.io/npm/v/react-native-template-typescript.svg)](https://www.npmjs.com/package/react-native-template-typescript) [![Travis](https://img.shields.io/travis/emin93/react-native-template-typescript.svg)](https://travis-ci.org/emin93/react-native-template-typescript)
# :space_invader: React Native Template TypeScript · [![Build Status](https://travis-ci.org/emin93/react-native-template-typescript.svg?branch=master)](https://travis-ci.org/emin93/react-native-template-typescript)
Clean and minimalist React Native template for a quick start with TypeScript.
[![Header](https://cdn-images-1.medium.com/max/500/1*E9RnPOATuhjuNrlFkv5oSg.jpeg)](https://medium.com/@emin93/react-native-typescript-b965059109d3)
This template can be used with the React Native CLI, which means it doesn't mess with the platform specific files. Instead of including a lot of dependencies, my aim when creating this template was to provide a very easy and minimalist way to start your React Native project with TypeScript. Of course you can always include other dependencies as you need them.
## :star: Features
- Seamless integration with the React Native CLI! :sparkles:
- Consistent with the default React Native template (no additional stuff)
- React Native TypeScript transformer directly integrated into the packager (no separate process for `tsc`)
- Unit testing in TypeScript with TS Jest
- Always latest dependencies :raised_hands:
- Seamlessly integrated into the React Native CLI! :sparkles:
- Consistent with the default React Native template
- React Native TypeScript Transformer included
- Unit testing in TypeScript with TS Jest
- Always latest dependencies :raised_hands:
## :arrow_forward: Quick Start
```
react-native init MyApp --template typescript
cd MyApp
node setup.js
```bash
react-native init MyApp --template typescript && node MyApp/setup.js
```
## :question: FAQ
### What is included in this template?
### What's included in this template?
- [TypeScript](https://github.com/Microsoft/TypeScript)
- [React Native TypeScript transformer](https://github.com/ds300/react-native-typescript-transformer)
- [Type definitions for React & React Native](https://github.com/DefinitelyTyped/DefinitelyTyped)
- [TS Jest](https://github.com/kulshekhar/ts-jest)
- [TypeScript](https://github.com/Microsoft/TypeScript)
- [React Native TypeScript Transformer](https://github.com/ds300/react-native-typescript-transformer)
- [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.
Yes it does.
### 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).
[![Demonstration of working breakpoints in Visual Studio Code](https://cdn-images-1.medium.com/max/1600/1*ZXfzgq1xKz1B3chYy9xE7w.png)](https://medium.com/@emin93/react-native-typescript-b965059109d3)
## :globe_with_meridians: Links
- ["Using React Native with TypeScript just became simple" on Medium](https://medium.com/@emin93/react-native-typescript-b965059109d3)
- ["Using React Native with TypeScript just became simple" on Medium](https://medium.com/@emin93/react-native-typescript-b965059109d3)
- ["24 tips for React Native you probably want to know" on Albert Gao's blog](http://albertgao.xyz/2018/05/30/24-tips-for-react-native-you-probably-want-to-know/#9-For-Typescript)
## :computer: Contributing
-12
View File
@@ -1,12 +0,0 @@
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<App />
);
});
+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"
}
+6 -38
View File
@@ -1,55 +1,23 @@
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)
const deleteFile = (fileName) => fs.unlinkSync(path.join(__dirname, fileName))
const writeFile = (fileName, data) => fs.writeFileSync(path.join(__dirname, fileName), data)
if (!fs.existsSync(filePath)) {
return
}
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')
console.log('🔄 Setting up...')
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')
deleteFile('App.js')
deleteFile('devDependencies.json')
deleteFile('jest.json')
deleteFile('README.md')
deleteFile('LICENSE')
deleteFile('README.md')
deleteFile('setup.js')
console.log(`\n✅ Setup completed! You can now start with: ${packageManager} start\n`)
console.log(`✅ Setup completed!`)
+2 -1
View File
@@ -2,7 +2,8 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react",
"jsx": "react-native",
"lib": ["es6"],
"module": "es6",
"moduleResolution": "node",
"noEmit": true,