Compare commits

...
15 Commits
Author SHA1 Message Date
Emin Khateeb 302409b2aa fixed issue which caused always using yarn as the packager 2018-03-28 11:27:01 +02:00
Emin Khateeb 81d1c898df Merge pull request #5 from oieduardorabelo/master
[feat] add support for Yarn + inheriting exec process
2018-03-28 11:17:28 +02:00
Eduardo Rabelo ecd2665a7c fix: tidy up, moving fns to top, etc 2018-03-28 19:54:40 +13:00
Eduardo Rabelo ea53a939b8 feat: line space + stdio options 2018-03-28 19:48:30 +13:00
Eduardo Rabelo ef94173200 feat: add log message for install step 2018-03-28 19:43:51 +13:00
Eduardo Rabelo fe8abb8848 feat: add support for yarn 2018-03-28 19:39:25 +13:00
Emin Khateeb 8e8013e835 added links section to readme 2018-03-27 13:02:14 +02:00
Emin Khateeb b80fb5d42b added link to the article on medium 2018-03-27 12:45:45 +02:00
Emin Khateeb 59bf3c6fc3 removed index.js since this is included in the default rn template 2018-03-21 11:22:35 +01:00
Emin Khateeb 3f295f24b9 removed delete of the index.js 2018-03-21 11:05:13 +01:00
Emin Khateeb 166dd361d2 improved feature section in readme 2018-03-21 11:04:20 +01:00
Emin Khateeb 2139753b44 fixed error which caused the app load to fail 2018-03-21 10:59:59 +01:00
Emin Khateeb ea1c65e260 now also removing index.js in the setup script 2018-03-21 10:40:22 +01:00
Emin Khateeb e4eca8679a removed tslint for more consistency with the default RN template 2018-03-21 10:39:36 +01:00
Emin Khateeb 79b0923763 Revert "moved setup file to a separate package"
This reverts commit 4c306c4fbf.
2018-03-10 20:25:43 +01:00
14 changed files with 135 additions and 135 deletions

No files matched your search

-1
View File
@@ -1,2 +1 @@
.travis.yml
setup/
+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,
},
});
+19 -7
View File
@@ -2,8 +2,18 @@
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:
## :arrow_forward: Quick Start
```
@@ -16,12 +26,10 @@ node setup.js
### What is 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)
- [TSLint](https://github.com/palantir/tslint)
- [TSLint React](https://github.com/palantir/tslint-react)
- [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.
@@ -35,7 +43,11 @@ The React Native CLI supports automatic installation of production dependencies
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
## :globe_with_meridians: Links
- ["Using React Native with TypeScript just became simple" on Medium](https://medium.com/@emin93/react-native-typescript-b965059109d3)
## :computer: Contributing
Contributions are very welcome. Please try to stay consistent with the other files I've created.
+9 -6
View File
@@ -1,9 +1,12 @@
import * as React from "react";
import "react-native";
import { create } from "react-test-renderer";
import 'react-native';
import * as React from 'react';
import App from '../App';
import App from "../src/App";
// Note: test renderer must be required after react-native.
import * as renderer from 'react-test-renderer';
it("renders correctly", () => {
const tree = create(<App exampleProp="helloWorld" />);
it('renders correctly', () => {
const tree = renderer.create(
<App />
);
});
-3
View File
@@ -1,3 +0,0 @@
{
"react-native-setup-typescript": "*"
}
-2
View File
@@ -1,7 +1,5 @@
[
"typescript",
"tslint",
"tslint-react",
"react-native-typescript-transformer",
"ts-jest",
"@types/react",
-4
View File
@@ -1,4 +0,0 @@
import { AppRegistry } from 'react-native';
import App from './src/App';
AppRegistry.registerComponent('HelloWorld', () => App);
-1
View File
@@ -12,7 +12,6 @@
"keywords": [
"react-native",
"typescript",
"tslint",
"jest",
"template",
"boilerplate"
+46
View File
@@ -0,0 +1,46 @@
const fs = require('fs');
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);
const isYarnAvailable = () => {
try {
execSync('yarnpkg --version', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}
const packager = isYarnAvailable() ? 'yarn' : 'npm';
const execOptions = { stdio: 'inherit' };
console.log('\n🔄 Please wait...\n');
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));
console.log(`\n📦 Installing dependencies with ${packager}...\n`);
if (packager === 'yarn') {
execSync(`yarn add ${devDependencies.join(' ')} --dev --exact`, execOptions);
} else {
execSync(`npm i ${devDependencies.join(' ')} --save-dev --save-exact`, execOptions);
}
deleteFile('App.js');
deleteFile('__tests__/App.js');
deleteFile('.flowconfig');
deleteFile('devDependencies.json');
deleteFile('jest.json');
deleteFile('README.md');
deleteFile('LICENSE');
deleteFile('setup.js');
console.log(`\n✅ Setup completed! You can now start with: ${packager} start\n`);
-28
View File
@@ -1,28 +0,0 @@
const fs = require('fs');
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 ../../../../rn-cli.config.js`;
packageJson.scripts.lint = 'tslint -c tslint.json "src/**/*.{ts,tsx}"';
packageJson.jest = Object.assign(packageJson.jest, jestJson);
writeFile('package.json', JSON.stringify(packageJson, null, 2));
deleteFile('App.js');
deleteFile('__tests__/App.js');
deleteFile('.flowconfig');
deleteFile('devDependencies.json');
deleteFile('jest.json');
deleteFile('README.md');
deleteFile('LICENSE');
let commandsToExecute = `cd ../../ && npm i ${devDependencies.join(' ')} --save-dev --save-exact`;
commandsToExecute += '&& npm uninstall react-native-setup-typescript --save'
execSync(commandsToExecute);
-19
View File
@@ -1,19 +0,0 @@
{
"name": "react-native-setup-typescript",
"version": "1.0.1",
"description": "Do NOT use this as a standalone package. See: https://www.npmjs.com/package/react-native-template-typescript",
"main": "index.js",
"scripts": {
"install": "node index.js"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/emin93/react-native-template-typescript.git"
},
"author": "Emin Khateeb <emin@emin.ch>",
"license": "MIT",
"bugs": {
"url": "https://github.com/emin93/react-native-template-typescript/issues"
},
"homepage": "https://github.com/emin93/react-native-template-typescript#readme"
}
-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",
},
});
+1
View File
@@ -4,6 +4,7 @@
"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": []
}