Skip to content

Commit

Permalink
style(lint): add tslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
fathyb committed Aug 13, 2018
1 parent 9bbe011 commit 74892d2
Show file tree
Hide file tree
Showing 32 changed files with 1,741 additions and 916 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
- checkout
- *getDeps
- run: yarn commitlint-circle
- run: yarn core lint

test-core:
<<: *nodeJob
Expand Down
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
semi: false
singleQuote: true
overrides:
- files: '*.{ts,js}'
options:
useTabs: true
37 changes: 27 additions & 10 deletions HACKING.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,47 @@

## Environment

This project is a Yarn workspace, npm is not supported. To install dependencies run :
This project is a Yarn workspace, npm is not supported. To install dependencies run :

```bash
$ yarn
```

### Useful commands
### Building

- Build everything:
```bash
$ yarn build
```
- Build the `@segment/react-native` package:
```bash
$ yarn core build
```
- Build the `@segment/react-native-*` packages:
```bash
$ yarn integrations build
```
- Build the test application for iOS and Android:
```bash
$ yarn test-app build
```
- Launch these three steps one by one:
```bash
$ yarn build
```

## Testing

```bash
$ yarn test
```

### Architecture

- `packages/core`: the `@segment/react-native` module
- `docs`: the generated TypeScript documentation, commited using a `lint-staged` hook
- `packages/integration-build`:
- `src`: JavaScript module
- `ios`: iOS native module
- `android`: Android native module
- `packages/integrations`:
- `integrations.yml`: the unique source of truth for supported integrations
- `generators`: a set of generators using `integrations.yml`
- `src`: a set of generators using `integrations.yml`
- `gen-integrations.js`: generates `@segment/react-native-*` packages in `build/`
- `gen-readme.js`: updates `README.md` [Integrations](README.md#integrations) section
- `test-app`
- `test-app`:
- `project`: the generated react-native test-app root
63 changes: 33 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The hassle-free way to add analytics to your React-Native app.
#### iOS

- CocoaPods (**recommended**)
- [Don't have CocoaPods setup?](#setup-cocoapods-in-an-existing-project)
- [Don't have CocoaPods setup?](#setup-cocoapods-in-an-existing-project)
- or [manually install `Analytics`](#ios-support-without-cocoapods)

## Installation
Expand All @@ -30,6 +30,7 @@ $ yarn react-native link

See the [API docs](packages/core/docs/classes/analytics.client.md) for more details.

<!-- prettier-ignore -->
```js
import analytics from '@segment/react-native'
import Mixpanel from '@segment/react-native-mixpanel'
Expand Down Expand Up @@ -65,8 +66,8 @@ analytics.screen('Home')

There are two ways to send data to your analytics services through this library:

1. [Through the Segment servers](#cloud-based-connection-modes)
2. [Directly from the device using bundled SDK’s](#packaging-device-based-destination-sdks)
1. [Through the Segment servers](#cloud-based-connection-modes)
2. [Directly from the device using bundled SDK’s](#packaging-device-based-destination-sdks)

**Note**: Refer to the specific destination’s docs to see if your tool must be bundled in the app or sent server-side.

Expand All @@ -88,23 +89,23 @@ $ yarn add @segment/react-native-google-analytics
$ yarn react-native link
```

In your code :
In your code :

```js
import analytics from '@segment/react-native'
import GoogleAnalytics from '@segment/react-native-google-analytics'

await analytics
.configure()
.using(GoogleAnalytics)
// ...
.setup('writeKey')

.configure()
.using(GoogleAnalytics)
// ...
.setup('writeKey')
```

#### Integrations

<!-- AUTOGEN:INTEGRATIONS:BEGIN -->

| Name | iOS | Android | npm package |
| -------------------------------------------------------------------------------------------------- | ------------------ | ------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| [Adjust](https://www.npmjs.com/package/@segment/react-native-adjust) | :white_check_mark: | :white_check_mark: | [`@segment/react-native-adjust`](https://www.npmjs.com/package/@segment/react-native-adjust) |
Expand All @@ -126,8 +127,8 @@ await analytics
| [Quantcast](https://www.npmjs.com/package/@segment/react-native-quantcast-android) | :x: | :white_check_mark: | [`@segment/react-native-quantcast-android`](https://www.npmjs.com/package/@segment/react-native-quantcast-android) |
| [Taplytics](https://www.npmjs.com/package/@segment/react-native-taplytics-ios) | :white_check_mark: | :x: | [`@segment/react-native-taplytics-ios`](https://www.npmjs.com/package/@segment/react-native-taplytics-ios) |
| [Tapstream](https://www.npmjs.com/package/@segment/react-native-tapstream-android) | :x: | :white_check_mark: | [`@segment/react-native-tapstream-android`](https://www.npmjs.com/package/@segment/react-native-tapstream-android) |
<!-- AUTOGEN:INTEGRATIONS:END -->

<!-- AUTOGEN:INTEGRATIONS:END -->

## Troubleshooting

Expand All @@ -141,28 +142,30 @@ However, if you cannot use Cocoapods, you can manually install our dynamic frame

Here are the steps for installing manually:

1. Download the [latest built SDK](https://github.com/segmentio/analytics-ios/releases), and unzip the zip file.
2. Drag the unzipped Analytics.framework folder into your Xcode project.
Make sure to check `Copy items if needed`.
![Add Analytics.framework](docs/ios/add-analytics-framework.png)
3. In the `General` tab for your project, search for `Embedded Binaries` and add the `Analytics.framework`.
![Embed Analytics.framework](docs/ios/embed-analytics-framework.png)
1. Download the [latest built SDK](https://github.com/segmentio/analytics-ios/releases), and unzip the zip file.
2. Drag the unzipped Analytics.framework folder into your Xcode project.
Make sure to check `Copy items if needed`.
![Add Analytics.framework](docs/ios/add-analytics-framework.png)
3. In the `General` tab for your project, search for `Embedded Binaries` and add the `Analytics.framework`.
![Embed Analytics.framework](docs/ios/embed-analytics-framework.png)

Please note, if you are choosing to not use a dependency manager, you must keep files up-to-date with regularly scheduled, manual updates.

### Setup CocoaPods in an existing project

1. Check that `ios/Podfile` doesn't exist
2. `cd ios`
3. `pod init`
4. Open `Podfile`
5. Edit your app `target` to have these `pod` declarations and the `Add new pods below this line` comment :
```ruby
target 'MyReactNativeApp' do
pod 'React', :path => '../node_modules/react-native'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

# Add new pods below this line
end
```
6. `pod install`
1. Check that `ios/Podfile` doesn't exist
2. `cd ios`
3. `pod init`
4. Open `Podfile`
5. Edit your app `target` to have these `pod` declarations and the `Add new pods below this line` comment :

```ruby
target 'MyReactNativeApp' do
pod 'React', :path => '../node_modules/react-native'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

# Add new pods below this line
end
```

6. `pod install`
Empty file removed circle
Empty file.
29 changes: 20 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,25 @@
]
},
"scripts": {
"core": "yarn workspace @segment/react-native run",
"integrations": "yarn workspace @local/integrations run",
"test-app": "yarn workspace @local/test-app run",
"core": "yarn workspace @segment/react-native",
"integrations": "yarn workspace @local/integrations",
"test-app": "yarn workspace @local/test-app",
"build:core": "yarn core build",
"build:integrations": "yarn integrations build",
"build:test-app": "yarn test-app build",
"build": "run-s build:{core,integrations,test-app}",
"test:core": "yarn core test",
"test": "run-p test:*",
"lint:prettier": "prettier $(git ls-files '**/*.ts' '**/*.js' '**/*.json' '**/*.md') --list-different",
"lint:core": "yarn core lint",
"lint": "run-s lint:*",
"docs:core": "yarn core docs",
"docs": "run-s docs:*",
"cz": "git-cz",
"precommit": "lint-staged",
"commitmsg": "commitlint -E GIT_PARAMS"
"commitmsg": "commitlint -E GIT_PARAMS",
"lint-staged:ts": "run-p build:core docs:core && git add packages/core/docs",
"lint-staged:integrations": "yarn integrations generate:readme && git add README.md"
},
"commitlint": {
"extends": [
Expand All @@ -38,13 +45,16 @@
}
},
"lint-staged": {
"packages/core/ts/**/*.ts": [
"yarn core docs --",
"git add packages/core/docs"
"packages/core/src/**/*.ts": [
"prettier --write",
"yarn lint-staged:ts"
],
"packages/integrations/integrations.yml": [
"yarn integrations generate:readme --",
"git add README.md"
"yarn lint-staged:integrations"
],
"*.{js,json,md}": [
"prettier --write",
"git add"
]
},
"devDependencies": {
Expand All @@ -57,6 +67,7 @@
"husky": "^0.14.3",
"lint-staged": "^7.2.0",
"npm-run-all": "^4.1.3",
"prettier": "^1.14.2",
"rimraf": "^2.6.2"
}
}
42 changes: 42 additions & 0 deletions packages/core/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@


## Index

### Modules

* [ChainedConfiguration](modules/analytics.chainedconfiguration.md)

### Classes

* [Client](classes/analytics.client.md)

### Type aliases

* [Integration](#integration)
* [WriteKey](#writekey)

---

## Type aliases

<a id="integration"></a>

### Integration

**ΤIntegration**: * `function` &#124; `object`
*

*Defined in analytics.ts:170*

___
<a id="writekey"></a>

### WriteKey

**ΤWriteKey**: * `string` &#124; `object`
*

*Defined in analytics.ts:172*

___

Loading

0 comments on commit 74892d2

Please sign in to comment.