Skip to content

Commit

Permalink
add typescript and lint back
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Ginzberg committed Feb 20, 2018
1 parent e0d4638 commit 71af841
Show file tree
Hide file tree
Showing 15 changed files with 446 additions and 62 deletions.
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,17 @@ node_modules/
npm-debug.log

# Android
#
.idea
.gradle
local.properties
*.iml
/android/
/android/

# Jest
#
.jest

# Typescript
#
artifacts
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ brew install watchman
## install react native cli
npm install react-native-cli -g

## install tslint
npm install tslint -g

# In separate terminals
yarn start
yarn run start:ios
yarn run start:android
yarn start:ios
yarn start:android

# Interesting Commands
yarn run lint
yarn run build
yarn lint
yarn build
yarn test
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import com.android.build.OutputFile
*/

project.ext.react = [
entryFile: "src/index.js"
entryFile: "artifacts/index.js"
]

apply from: "../../node_modules/react-native/react.gradle"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/java/com/oddsare/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected List<ReactPackage> getPackages() {

@Override
protected String getJSMainModuleName() {
return "src/index";
return "artifacts/index";
}
};

Expand Down
2 changes: 1 addition & 1 deletion ios/oddsare/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
NSURL *jsCodeLocation;

jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"src/index" fallbackResource:nil];
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"artifacts/index" fallbackResource:nil];

RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"oddsare"
Expand Down
42 changes: 37 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,52 @@
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"start:android": "react-native run-android",
"start:ios": "react-native run-ios"
"tsc": "tsc",
"clean": "rimraf artifacts",
"build": "yarn clean && yarn tsc",
"watch": "yarn build -w",
"lint": "tslint -c tslint.json 'src/**/*.{ts,tsx}'",
"start:android": "yarn build && concurrently -r 'yarn watch' 'react-native run-android'",
"start:ios": "yarn build && concurrently -r 'yarn watch' 'react-native run-ios'",
"prepush": "yarn lint"
},
"dependencies": {
"react": "16.2.0",
"react-native": "0.53.0"
},
"devDependencies": {
"@types/jest": "^22.1.3",
"@types/react": "^16.0.38",
"@types/react-native": "^0.52.12",
"@types/react-test-renderer": "^16.0.1",
"babel-jest": "22.2.2",
"babel-preset-react-native": "4.0.0",
"concurrently": "^3.5.1",
"husky": "^0.14.3",
"jest": "22.3.0",
"react-test-renderer": "16.2.0"
"react-test-renderer": "16.2.0",
"rimraf": "^2.6.2",
"ts-jest": "^22.0.4",
"tslint": "^5.9.1",
"typescript": "^2.7.2"
},
"jest": {
"preset": "react-native"
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"transform": {
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest",
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"testPathIgnorePatterns": [
"\\.snap$",
"<rootDir>/node_modules/",
"<rootDir>/artifacts/"
],
"cacheDirectory": ".jest/cache"
}
}
}
38 changes: 19 additions & 19 deletions src/App.js → src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
* https://github.com/facebook/react-native
*/

import React, { Component } from 'react';
import * as React from "react";
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
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'
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",
});

export default class App extends Component {
render() {
export default class App extends React.Component<{}> {
public render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Expand All @@ -38,19 +38,19 @@ export default class App extends Component {

const styles = StyleSheet.create({
container: {
alignItems: "center",
backgroundColor: "#F5FCFF",
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
justifyContent: "center",
},
instructions: {
color: "#333333",
marginBottom: 5,
textAlign: "center",
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
margin: 10,
textAlign: "center",
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
}
});
10 changes: 0 additions & 10 deletions src/__tests__/App.test.js

This file was deleted.

8 changes: 8 additions & 0 deletions src/__tests__/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as React from "react";
import * as renderer from "react-test-renderer";
import App from "../App";

it("renders correctly", () => {
const tree = renderer.create(<App />).toJSON();
expect(tree).toMatchSnapshot();
});
4 changes: 0 additions & 4 deletions src/index.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { AppRegistry } from "react-native";
import App from "./App";

AppRegistry.registerComponent("oddsare", () => App);
58 changes: 58 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./artifacts", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */

/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
},
"include": ["./src/"]
}
9 changes: 9 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
Loading

0 comments on commit 71af841

Please sign in to comment.