Skip to content

Commit eb3a2cc

Browse files
committed
install ts deps && port app to typescript
1 parent e517043 commit eb3a2cc

File tree

10 files changed

+462
-81
lines changed

10 files changed

+462
-81
lines changed

mobile-react-native/.flowconfig

Lines changed: 0 additions & 54 deletions
This file was deleted.

mobile-react-native/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,11 @@ buck-out/
5454

5555
# Bundle artifact
5656
*.jsbundle
57+
58+
# temporial
59+
/coverage
60+
*.tmp
61+
*.old
62+
63+
# preserve
64+
!.gitkeep

mobile-react-native/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { AppRegistry } from 'react-native';
2-
import App from './App';
2+
import { App } from './src';
33

44
AppRegistry.registerComponent('TypeScriptRN', () => App);

mobile-react-native/package.json

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,70 @@
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start",
7-
"test": "jest"
7+
"android": "node node_modules/react-native/local-cli/cli.js run-android",
8+
"ios": "node node_modules/react-native/local-cli/cli.js run-ios",
9+
"test": "jest",
10+
"test:all": "tsc && yarn lint && jest",
11+
"updateSnapshot": "jest --updateSnapshot",
12+
"testCoverage": "jest --coverage",
13+
"lint": " tslint -c tslint.json -e 'node_modules/**/*' -e 'scripts/**/*' '**/*.ts?(x)'",
14+
"lint:fix": "tslint -c tslint.json --fix -e 'node_modules/**/*' -e 'scripts/**/*' '**/*.ts?(x)'"
15+
},
16+
"author": "Wang Guan <[email protected]>",
17+
"private": true,
18+
"engines": {
19+
"node": ">= 8.0.0"
820
},
921
"dependencies": {
1022
"react": "16.3.1",
11-
"react-native": "0.55.1"
23+
"react-native": "0.55.1",
24+
"tslib": "^1.9.0"
1225
},
1326
"devDependencies": {
27+
"@types/jest": "^22.2.2",
28+
"@types/react": "^16.3.4",
29+
"@types/react-native": "^0.52.23",
30+
"@types/react-test-renderer": "^16.0.1",
1431
"babel-jest": "22.4.3",
1532
"babel-preset-react-native": "4.0.0",
1633
"jest": "22.4.3",
17-
"react-test-renderer": "16.3.1"
34+
"react-native-typescript-transformer": "^1.2.4",
35+
"react-test-renderer": "^16.3.1",
36+
"ts-jest": "^22.4.2",
37+
"tslint": "^5.9.1",
38+
"tslint-config-airbnb": "^5.8.0",
39+
"typescript": "^2.8.1"
1840
},
1941
"jest": {
20-
"preset": "react-native"
42+
"preset": "react-native",
43+
"transform": {
44+
"^.+\\.tsx?$": "ts-jest"
45+
},
46+
"transformIgnorePatterns": [
47+
"node_modules/(?!.*)"
48+
],
49+
"testMatch": [
50+
"/**/__test__/*.(ts|js|tsx|jsx)",
51+
"/**/*\\.(spec|test)\\.(ts|js|tsx|jsx)"
52+
],
53+
"collectCoverageFrom": [
54+
"src/**/*.(ts|tsx)",
55+
"!**/node_modules",
56+
"!/coverage"
57+
],
58+
"moduleFileExtensions": [
59+
"ts",
60+
"tsx",
61+
"js",
62+
"jsx",
63+
"json",
64+
"node"
65+
],
66+
"coverageReporters": [
67+
"json",
68+
"lcov",
69+
"text",
70+
"html"
71+
]
2172
}
22-
}
73+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
getTransformModulePath() {
3+
return require.resolve("react-native-typescript-transformer");
4+
},
5+
getSourceExts() {
6+
return ["ts", "tsx"];
7+
},
8+
};

mobile-react-native/App.js renamed to mobile-react-native/src/app.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/**
2-
* Sample React Native App
2+
* TS version of "Sample React Native App" created by `react-native init`
33
* https://github.com/facebook/react-native
44
* @flow
55
*/
66

7-
import React, { Component } from 'react';
7+
import * as React from 'react';
8+
import { Component } from 'react';
89
import {
910
Platform,
1011
StyleSheet,
@@ -20,7 +21,7 @@ const instructions = Platform.select({
2021
});
2122

2223
type Props = {};
23-
export default class App extends Component<Props> {
24+
export class App extends Component<Props> {
2425
render() {
2526
return (
2627
<View style={styles.container}>
@@ -56,3 +57,4 @@ const styles = StyleSheet.create({
5657
marginBottom: 5,
5758
},
5859
});
60+

mobile-react-native/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { App } from './app';

mobile-react-native/tsconfig.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
5+
"module": "es6", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
"allowJs": true, /* Allow javascript files to be compiled. */
8+
"checkJs": true, /* Report errors in .js files. */
9+
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
// "declaration": true, /* Generates corresponding '.d.ts' file. */
11+
// "sourceMap": true, /* Generates corresponding '.map' file. */
12+
// "outFile": "./", /* Concatenate and emit output to single file. */
13+
// "outDir": "./", /* Redirect output structure to the directory. */
14+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
15+
// "removeComments": true, /* Do not emit comments to output. */
16+
"noEmit": true, /* Do not emit outputs. */
17+
"importHelpers": true, /* Import emit helpers from 'tslib'. */
18+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
19+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
20+
/* Strict Type-Checking Options */
21+
"strict": true, /* Enable all strict type-checking options. */
22+
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
23+
"strictNullChecks": true, /* Enable strict null checks. */
24+
"strictFunctionTypes": true, /* Enable strict checking of function types. */
25+
"strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
26+
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
27+
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
28+
/* Additional Checks */
29+
"noUnusedLocals": false, /* Report errors on unused locals. */
30+
"noUnusedParameters": true, /* Report errors on unused parameters. */
31+
"noImplicitReturns": false, /* Report error when not all code paths in function return a value. */
32+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
33+
/* Module Resolution Options */
34+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
35+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
36+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
37+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
38+
// "typeRoots": [], /* List of folders to include type definitions from. */
39+
// "types": [], /* Type declaration files to be included in compilation. */
40+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
41+
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
42+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
43+
/* Source Map Options */
44+
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
45+
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
46+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
47+
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
48+
/* Experimental Options */
49+
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
50+
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
51+
},
52+
"exclude": [
53+
"node_modules",
54+
"scripts",
55+
"rn-cli.config.js",
56+
"coverage"
57+
]
58+
}

mobile-react-native/tslint.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"defaultSeverity": "error",
3+
"extends": [
4+
"tslint-config-airbnb"
5+
],
6+
"formatter": "stylish",
7+
"jsRules": {},
8+
"rules": {
9+
"variable-name": [
10+
true,
11+
"ban-keywords",
12+
"check-format",
13+
"allow-pascal-case",
14+
"allow-leading-underscore"
15+
],
16+
"quotemark": false,
17+
"max-line-length": [true, 160],
18+
"no-increment-decrement": false,
19+
"function-name": false,
20+
"no-this-assignment": false,
21+
"indent": [true, "spaces", 2]
22+
},
23+
"rulesDirectory": []
24+
}

0 commit comments

Comments
 (0)