Skip to content

Commit

Permalink
feat(init): create api
Browse files Browse the repository at this point in the history
  • Loading branch information
blackholegalaxy committed Jan 20, 2020
0 parents commit 2160bf5
Show file tree
Hide file tree
Showing 98 changed files with 14,724 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
82 changes: 82 additions & 0 deletions .github/workflows/branch-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: branch-master
on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
test:
name: test
runs-on: windows-latest
timeout-minutes: 5
steps:
- name: setup:checkout
uses: actions/checkout@master
- name: setup:python3.7
uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: x64
- name: setup:cache:node
uses: actions/cache@v1.1.0
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}-api-test-node-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-api-test-node-
${{ runner.os }}-api-
- name: deps:install
shell: bash
run: |
yarn
- name: test:lint
shell: bash
run: |
yarn tslint
- name: test:unit
shell: bash
run: |
yarn test:ci
- name: test:coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ${{ github.workspace }}/coverage/lcov.info

build:
name: build
runs-on: windows-latest
timeout-minutes: 5
steps:
- name: setup:checkout
uses: actions/checkout@master
- name: setup:python3.7
uses: actions/setup-python@v1
with:
python-version: '3.7'
architecture: x64
- name: setup:cache
uses: actions/cache@v1.1.0
with:
path: ${{ github.workspace }}/node_modules
key: ${{ runner.os }}-api-build-node-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-api-build-node-
${{ runner.os }}-api-
- name: deps:install
shell: bash
run: |
yarn
- name: build:prod
shell: bash
run: |
yarn compile:prod
- name: build:upload:artifacts
if: github.base_ref == 0
uses: actions/upload-artifact@v1
with:
name: fsuipc-api-${{ github.sha }}
path: ${{ github.workspace }}/dist
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
coverage/
dist/
.jest-cache/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12.12.0
30 changes: 30 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
The MIT License

Copyright (c) 2017-2020 Exalif Inc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


-----

This repository and its package are not related and not affialiated with original FSUIPC/WIDEFS creator or FSUIPC/WIDEFS software.

You can find information about FSUIPC on their official website: http://www.fsuipc.com/ or on dedicated forum: https://forum.simflight.com/forum/30-fsuipc-support-pete-dowson-modules/

Please use this current library in accordance with FSUIPC terms, conditions and license.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# @fsuipc/api - FSUIPC Node API

[![Coverage Status](https://coveralls.io/repos/github/fsuipc-node/api/badge.svg?branch=master)](https://coveralls.io/github/fsuipc-node/api?branch=master)

Tooling to use FSUIPC external application interface, with nodeJS.

## Disclamer

This API is a wrapper around [fsuipc-node adapter by koesie10](https://github.com/koesie10/fsuipc-node) meant to create a simple API around all available fsuipc offsets.

Please find any information about FSUIPC on [their website](http://www.fsuipc.com/).

## Requirements
In order for [`fsuipc`](https://github.com/koesie10/fsuipc-node) (fsuipc-node) and `@fsuipc/api` (this package) to work, and so this API, you must have on your machine:
- Windows 10 64bits
- node 12+
- python 3.7 (don't forget to add it to your PATH)
- visualstudio 2017+ with desktop C++ package
- fsuipc installed as flight simulator plugin

Node API usage requirements:
- `rxjs` >= 6.5.0

## Installation
```
npm i --save @fsuipc/api
or
yarn add @fsuipc/api
```

## API Usage

After import, you can use `FsuipcApi` to listen to provided values.

### Import

```typescript
import { FsuipcApi } from '@fsuipc/api';
```

### Instantiate

```typescript
const fsuipcApi = new FsuipcApi(Simulator.FSX);
```
### Init

`FsuipcApi.init()` returns a promise when you are properly connected to FSUIPC stream. In case your flight simulator isn't running, this will throw an error.

### Listen to offsets values

`FsuipcApi.listen()` methods takes 2-3 arguments:
- `interval` [*number*]: interval at which values will be polled from FSUIPC stream
- `offsetsList` [*string[]*]: a list of string representing offsets you want to subscribe on
- `terminateOnError` [*boolean* = *true*]: if set to true, if any value is errored, you will be disconnected from FSUIPC stream

This method returns a `ConvertedOffsetValues` observable. You can subscribe to this observable to handle values polled from stream.

### Complete example

```typescript
import { FsuipcApi } from '@fsuipc/api';

const fsuipcApi = new FsuipcApi(Simulator.FSX);

fsuipcApi.init().then(() => {
fsuipcApi.listen(1000, [
'gs',
'altitude',
'comFreq',
'lights',
]).subscribe((result) => {
// Use the result here
console.log(JSON.stringify(result));
});
}).catch((e) =>
console.error(e)
);
```
24 changes: 24 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
'ts-jest': {
tsConfig: 'tests/tsconfig.spec.json',
}
},
cacheDirectory: '.jest-cache',
moduleNameMapper: {
'@shared/(.*)': '<rootDir>/src/shared/$1',
'@offsets/(.*)': '<rootDir>/src/lib/offsets/$1',
'@offsets': '<rootDir>/src/lib/offsets/index.ts',
'@mappings/(.*)': '<rootDir>/src/lib/convert/mappings/$1',
'@convert/(.*)': '<rootDir>/src/lib/convert/$1',
},
collectCoverageFrom: [
'**/*.ts',
'!**/node_modules/**',
'!**/*.d.ts',
'!**/index.ts',
'!**/types/**/*.ts',
],
};
19 changes: 19 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"env": {
"NODE_ENV": "development"
},
"watch": [
"tsconfig.json",
"tsconfig.app.json",
"tslint.json",
"src/**/*.ts"
],
"execMap": {
"ts": "ts-node --files --type-check --project tsconfig.app.json -r tsconfig-paths/register"
},
"events": {
"start": "tslint -p tsconfig.app.json -c tslint.json",
"restart": "tslint -p tsconfig.app.json -c tslint.json"
},
"delay": "500"
}
53 changes: 53 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "@fsuipc/api",
"version": "0.1.0",
"author": {
"name": "FSUIPC-Node Opensource Team",
"url": "https://github.com/fsuipc-node"
},
"repository": {
"type" : "git",
"url" : "https://github.com/fsuipc-node/api"
},
"homepage": "https://github.com/fsuipc-node",
"license": "MIT",
"main": "./api.js",
"types": "./lib/index.d.ts",
"scripts": {
"start": "nodemon --exec cross-env TS_NODE_FILES=true TS_NODE_TYPE_CHECK=true TS_NODE_PROJECT=src/tsconfig.app.json node --inspect -r tsconfig-paths/register -r ts-node/register ./src/api.ts",
"compile:dev": "tsc --declaration -p src/tsconfig.app.json",
"compile:prod": "tsc --declaration -p src/tsconfig.prod.json",
"postcompile:dev": "npx tscpaths -v -r -p src/tsconfig.app.json -s ./dist",
"postcompile:prod": "npx tscpaths -v -r -p src/tsconfig.prod.json -s ./dist && yarn copy:docs && yarn copy:package",
"copy:docs": "cp README.md LICENSE dist/",
"copy:package": "node scripts/clean-pkg",
"test": "jest --watch",
"test:ci": "jest --coverage",
"tslint": "tslint -p src/tsconfig.app.json -c tslint.json && tslint -p tests/tsconfig.spec.json -c tslint.json",
"changelog": "npx conventional-changelog -p angular -i CHANGELOG.md -s"
},
"dependencies": {
"fsuipc": "0.3.0",
"rxjs": "6.5.4",
"vm2": "3.8.4"
},
"peerDependencies": {
"fsuipc": "^0.3.0",
"rxjs": "^6.5.0",
"vm2": "^3.8.0"
},
"devDependencies": {
"@exalif/tscpaths": "0.1.3",
"@types/jest": "24.0.25",
"@types/node": "13.1.6",
"conventional-changelog-cli": "2.0.31",
"cross-env": "6.0.3",
"jest": "24.9.0",
"nodemon": "2.0.2",
"ts-jest": "24.3.0",
"ts-node": "8.6.1",
"tsconfig-paths": "3.9.0",
"tslint": "5.20.1",
"typescript": "3.7.4"
}
}
14 changes: 14 additions & 0 deletions scripts/clean-pkg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');

const ORIG_PKG_PATH = path.resolve(__dirname, '../package.json');
const DEST = path.resolve(__dirname, '../dist/package.json');

const pkgData = require(ORIG_PKG_PATH);

delete pkgData.scripts;
delete pkgData.devDependencies;

fs.writeFileSync(DEST, JSON.stringify(pkgData, null, 2), (err) => {
if (err) throw err;
});
Loading

0 comments on commit 2160bf5

Please sign in to comment.