fitbit-sdk-types
Advanced tools
Comparing version 3.2.12 to 3.3.0-0
{ | ||
"name": "fitbit-sdk-types", | ||
"version": "3.2.12", | ||
"version": "3.3.0-0", | ||
"author": "Sergio Morchón Poveda <sergio.morchon@outlook.com>", | ||
@@ -24,20 +24,19 @@ "description": "Types for Fitbit SDK.", | ||
"scripts": { | ||
"test-app": "tsc -p test-code-samples/app", | ||
"test-companion": "tsc -p test-code-samples/companion", | ||
"test-settings": "tsc -p test-code-samples/settings", | ||
"test": "npm run test-app && npm run test-companion && npm run test-settings", | ||
"test:app": "tsc -p test-code-samples/app", | ||
"test:companion": "tsc -p test-code-samples/companion", | ||
"test:settings": "tsc -p test-code-samples/settings", | ||
"test": "npm run test:app && npm run test:companion && npm run test:settings", | ||
"prettier": "prettier **/*.ts **/*.tsx **/*.json **/*.md", | ||
"tslint": "tslint types/**/*.ts", | ||
"check-code": "npm run tslint && npm run prettier -- -l", | ||
"fix-code": "tslint --project types --fix && npm run prettier -- --write", | ||
"fix-code": "tslint types/**/*.ts --fix && npm run prettier -- --write", | ||
"prepublishOnly": "npm run check-code && npm test" | ||
}, | ||
"devDependencies": { | ||
"@types/glob": "^7.1.1", | ||
"@types/node": "^10.12.24", | ||
"@types/node": "^10.12.27", | ||
"prettier": "^1.16.4", | ||
"tslint": "^5.12.1", | ||
"tslint": "^5.13.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.3.3" | ||
"typescript": "^3.3.3333" | ||
} | ||
} |
@@ -10,4 +10,2 @@ # Fitbit SDK Types ✔ | ||
### ✨ Automatic configuration | ||
1. First, create your Fitbit CLI project following the official instructions at https://dev.fitbit.com/build/guides/command-line-interface/. | ||
@@ -17,64 +15,2 @@ 2. Then, from that project root, run `npx fitbit-sdk-types apply` to apply TypeScript to your existing Fitbit project. | ||
This is a shortand script that performs step by step the same actions described below. | ||
### ✍ Manual configuration | ||
1. Execute `npm install --save-dev fitbit-sdk-types` to add this type definitions. | ||
2. `include` them in your project's `tsconfig.json` file. It may look like this **tsconfig.json**: | ||
```json | ||
{ | ||
"extends": "./node_modules/@fitbit/sdk/sdk-tsconfig.json", | ||
"include": ["node_modules/fitbit-sdk-types/types", "**/*.ts", "**/*.tsx"] | ||
} | ||
``` | ||
3. Rename your files from `.js` to `.ts` and use it. For example, **app/index.ts**: | ||
```typescript | ||
import { Accelerometer } from 'accelerometer'; | ||
const acc = new Accelerometer(); | ||
console.log(acc.activated); | ||
console.log(acc.potato); // error | ||
``` | ||
#### Strict configuration | ||
Add the following configurations for each target. | ||
**app/tsconfig.json** | ||
```json | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["../node_modules/fitbit-sdk-types/types/device.d.ts", "**/*.ts"] | ||
} | ||
``` | ||
**companion/tsconfig.json** | ||
```json | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": [ | ||
"../node_modules/fitbit-sdk-types/types/companion.d.ts", | ||
"**/*.ts" | ||
] | ||
} | ||
``` | ||
**settings/tsconfig.json** | ||
```json | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": [ | ||
"../node_modules/fitbit-sdk-types/types/settings.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx" | ||
] | ||
} | ||
``` | ||
## Benefits of using types | ||
@@ -105,6 +41,8 @@ | ||
You can see a ton of official examples working as tests right here, under the `./test` path. | ||
You can see a ton of official examples working as tests right here, under the `./test-code-samples` path. | ||
## Gotchas | ||
### Be strict... | ||
- 🧐 **To have a _full type experience_**: add the `strict` mode to your **tsconfig.json**: | ||
@@ -120,2 +58,10 @@ | ||
### ... Or not | ||
You can always place `// @ts-ignore` right above that line of code that you know that _should_ work, and probably needs to have it's typings fixed. | ||
## SDK Support | ||
Only the latest SDK version is supported. Also don't expect this project version to match the official SDK version. | ||
## Contributing | ||
@@ -127,3 +73,3 @@ | ||
### 💪 Make a PR with: | ||
### 💪 Make a PR | ||
@@ -130,0 +76,0 @@ 1. The use cases you think that must be covered, under a meaningful section inside **test-code-samples/**. |
const { name: moduleName, version: moduleVersion } = require('../package.json'); | ||
const { execSync } = require('child_process'); | ||
const { existsSync, readFileSync, writeFileSync, renameSync } = require('fs'); | ||
const { existsSync, writeFileSync, renameSync } = require('fs'); | ||
const { join } = require('path'); | ||
const {walkFiles} = require('./file-system'); | ||
const { walkFiles } = require('./file-system'); | ||
@@ -28,2 +28,8 @@ const moduleDependency = `${moduleName}@${moduleVersion}`; | ||
/** | ||
* @param {string} target | ||
*/ | ||
const getTypesPathForTarget = target => | ||
`../node_modules/fitbit-sdk-types/types/${target}`; | ||
const commonTsConfig = { | ||
@@ -39,6 +45,3 @@ extends: '../tsconfig.json', | ||
...commonTsConfig, | ||
include: [ | ||
...commonTsConfig.include, | ||
'../node_modules/fitbit-sdk-types/types/device.d.ts', | ||
], | ||
include: [getTypesPathForTarget('device'), ...commonTsConfig.include], | ||
}, | ||
@@ -50,6 +53,3 @@ }, | ||
...commonTsConfig, | ||
include: [ | ||
...commonTsConfig.include, | ||
'../node_modules/fitbit-sdk-types/types/companion.d.ts', | ||
], | ||
include: [getTypesPathForTarget('companion'), ...commonTsConfig.include], | ||
}, | ||
@@ -62,5 +62,5 @@ }, | ||
include: [ | ||
getTypesPathForTarget('settings'), | ||
...commonTsConfig.include, | ||
'**/*.tsx', | ||
'../node_modules/fitbit-sdk-types/types/settings.d.ts', | ||
], | ||
@@ -99,22 +99,4 @@ }, | ||
); | ||
}; | ||
} | ||
}); | ||
const projectTsConfigFileName = './tsconfig.json'; | ||
const projectTsConfig = JSON.parse( | ||
readFileSync(projectTsConfigFileName).toString('utf-8'), | ||
); | ||
projectTsConfig.include = [ | ||
'node_modules/fitbit-sdk-types/types', | ||
'**/*.ts', | ||
'**/*.tsx', | ||
]; | ||
projectTsConfig.compilerOptions = { | ||
...projectTsConfig.compilerOptions, | ||
strict: true, | ||
}; | ||
tryRun( | ||
() => writeFileSync(projectTsConfigFileName, stringify(projectTsConfig)), | ||
`adding type references to ${projectTsConfigFileName}`, | ||
); | ||
}; |
@@ -12,14 +12,6 @@ declare module 'peer' { | ||
type BatteryLevel = 'empty' | 'low' | 'medium' | 'high' | 'unknown'; | ||
interface PeerDevice { | ||
interface PeerDevice extends BasicDeviceInfo { | ||
readonly batteryLevel: BatteryLevel; | ||
readonly lastSyncTime: Date; | ||
readonly modelId: string; | ||
readonly modelName: string; | ||
readonly screen: { | ||
readonly width: number; | ||
readonly height: number; | ||
}; | ||
readonly type: string; | ||
} | ||
const device: PeerDevice; | ||
} |
@@ -1,16 +0,10 @@ | ||
declare module 'device' { | ||
interface Device { | ||
readonly bodyColor: string | undefined; | ||
readonly firmwareVersion: string; | ||
readonly lastSyncTime: Date; | ||
readonly modelId: string; | ||
readonly modelName: string; | ||
readonly screen: { | ||
readonly width: number; | ||
readonly height: number; | ||
}; | ||
readonly type: string; | ||
} | ||
const me: Device; | ||
interface BasicDeviceInfo { | ||
readonly lastSyncTime: Date; | ||
readonly modelId: string; | ||
readonly modelName: string; | ||
readonly screen: { | ||
readonly width: number; | ||
readonly height: number; | ||
}; | ||
readonly type: string; | ||
} |
@@ -11,7 +11,1 @@ declare function clearInterval(handle: number): void; | ||
): number; | ||
//#region device | ||
declare function cancelAnimationFrame(handle: number): void; | ||
declare function requestAnimationFrame( | ||
handler: (timestamp: number) => void, | ||
): number; | ||
//#endregion |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
60
45232
1495
1
74