Compare commits

...
13 Commits
12 changed files with 126 additions and 95 deletions

No files matched your search

-4
View File
@@ -34,10 +34,6 @@ local.properties
#
.vscode/
# TypeScript
#
lib/
# node.js
#
node_modules/
+60
View File
@@ -0,0 +1,60 @@
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/emin93/react-native-template-typescript
*/
import * as React 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' +
'Shake or press menu button for dev menu',
});
interface Props {};
export default class App extends React.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>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
+13 -9
View File
@@ -4,6 +4,13 @@ Clean and minimalist React Native template for a quick start with TypeScript.
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
- Always latest dependencies
- React Native TypeScript transformer directly integrated into the packager! (No separate process for TSC)
- Unit testing in TypeScript with Jest
## :arrow_forward: Quick Start
```
@@ -17,26 +24,23 @@ node setup.js
### What is included in this template?
- [TypeScript](https://github.com/Microsoft/TypeScript)
- [TypeScript type definitions for React & React Native](https://github.com/DefinitelyTyped/DefinitelyTyped)
- [react-native-typescript-transformer](https://github.com/ds300/react-native-typescript-transformer)
- [TSLint](https://github.com/palantir/tslint)
- [TSLint React](https://github.com/palantir/tslint-react)
- [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.
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.
### What about Jest?
This template does not cover Jest yet. For more info on the current status check the [open issue](https://github.com/emin93/react-native-template-typescript/issues/1).
### How will this template affect the React Native CLI workflow?
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.
## :hearts: Contributing
## :computer: Contributing
Contributions are very welcome. Please try to stay consistent with the other files I've created.
+12
View File
@@ -0,0 +1,12 @@
import 'react-native';
import * as React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import * as renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<App />
);
});
+3 -3
View File
@@ -1,8 +1,8 @@
[
"typescript",
"tslint",
"tslint-react",
"react-native-typescript-transformer",
"ts-jest",
"@types/react",
"@types/react-native",
"react-native-typescript-transformer"
"@types/jest"
]
+1 -1
View File
@@ -1,4 +1,4 @@
import { AppRegistry } from 'react-native';
import App from './lib/App';
import App from './App';
AppRegistry.registerComponent('HelloWorld', () => App);
+15
View File
@@ -0,0 +1,15 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
],
"modulePaths": ["<rootDir>"]
}
+4 -3
View File
@@ -10,10 +10,11 @@
"url": "git+https://github.com/emin93/react-native-template-typescript.git"
},
"keywords": [
"react",
"native",
"template",
"react-native",
"typescript",
"tslint",
"jest",
"template",
"boilerplate"
],
"author": "Emin Khateeb <emin@emin.ch>",
+8 -2
View File
@@ -3,20 +3,26 @@ const path = require('path');
const { execSync } = require('child_process');
const packageJson = require('./package.json');
const jestJson = require('./jest.json');
const devDependencies = require('./devDependencies.json');
const deleteFile = (fileName) => fs.unlinkSync(path.join(process.cwd(), fileName));
const writeFile = (fileName, data) => fs.writeFileSync(path.join(process.cwd(), fileName), data);
packageJson.scripts.start = `${packageJson.scripts.start} --config ${path.join(process.cwd(), 'rn-cli.config.js')}`;
packageJson.scripts.lint = 'tslint -c tslint.json "src/**/*.{ts,tsx}"';
console.log('🔄 Please wait...');
packageJson.scripts.start = `${packageJson.scripts.start} --config ../../../../rn-cli.config.js`;
packageJson.jest = Object.assign(packageJson.jest, jestJson);
writeFile('package.json', JSON.stringify(packageJson, null, 2));
execSync(`npm i ${devDependencies.join(' ')} --save-dev --save-exact`);
deleteFile('index.js');
deleteFile('App.js');
deleteFile('__tests__/App.js');
deleteFile('.flowconfig');
deleteFile('devDependencies.json');
deleteFile('jest.json');
deleteFile('README.md');
deleteFile('LICENSE');
deleteFile('setup.js');
-54
View File
@@ -1,54 +0,0 @@
import * as React from "react";
import { Platform, StyleSheet, Text, View } from "react-native";
const instructions = Platform.select({
android: "Double tap R on your keyboard to reload,\n" +
"Shake or press menu button for dev menu",
ios: "Press Cmd+R to reload,\n" +
"Cmd+D or shake for dev menu",
});
interface IProps {
exampleProp: string;
}
interface IState {
exampleState: string;
}
export default class App extends React.Component<IProps, IState> {
public render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Text style={styles.instructions}>
To get started, edit src/App.tsx
</Text>
<Text style={styles.instructions}>
{instructions}
</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
alignItems: "center",
backgroundColor: "#F5FCFF",
flex: 1,
justifyContent: "center",
},
instructions: {
color: "#333333",
marginBottom: 5,
textAlign: "center",
},
welcome: {
fontSize: 20,
margin: 10,
textAlign: "center",
},
});
+10 -9
View File
@@ -1,11 +1,12 @@
{
"compilerOptions": {
"target": "es2015",
"jsx": "react",
"noEmit": true,
"moduleResolution": "node",
},
"exclude": [
"node_modules"
]
"compilerOptions": {
"target": "es2015",
"jsx": "react",
"noEmit": true,
"moduleResolution": "node",
"noImplicitAny": true
},
"exclude": [
"node_modules"
]
}
-10
View File
@@ -1,10 +0,0 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-react"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}