Skip to content

Commit

Permalink
feat: Add TypeScript declaration files (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapsssito committed Feb 24, 2020
1 parent 6ca24ff commit 1c9f9b1
Show file tree
Hide file tree
Showing 16 changed files with 157 additions and 126 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,5 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v1
- name: Install dependencies
- name: CI
run: yarn ci

- name: ESLint
run: yarn lint

- name: Tests
run: yarn test
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ jobs:
uses: actions/setup-node@v1
with:
node-version: 12
- name: Install dependencies
- name: CI
run: yarn ci
- name: ESLint
run: yarn lint
- name: Tests
run: yarn test
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
97 changes: 0 additions & 97 deletions .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}],
"@semantic-release/npm",
["@semantic-release/git", {
"assets": ["CHANGELOG.md", "package.json"],
"assets": ["CHANGELOG.md", "package.json", "src/index.d.ts", "src/RNBackgroundActionsModule.d.ts"],
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
}]
]
Expand Down
4 changes: 0 additions & 4 deletions __mocks__/RNBackgroundActionsModule.js

This file was deleted.

4 changes: 2 additions & 2 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Platform, AppRegistry } from 'react-native';
import BackgroundActions from '../index';
import RNBackgroundActionsModule from '../RNBackgroundActionsModule';
import BackgroundActions from '../src/index';
import RNBackgroundActionsModule from '../src/RNBackgroundActionsModule';

// Flush promises
const flushPromises = () => new Promise(setImmediate);
Expand Down
9 changes: 9 additions & 0 deletions declaration.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"declaration": true,
"noEmit": false,
"emitDeclarationOnly": true
},
"exclude": ["__tests__", "__mocks__"]
}
5 changes: 4 additions & 1 deletion jest.setup.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
jest.mock('./RNBackgroundActionsModule');
jest.mock('./src/RNBackgroundActionsModule.js', () => ({
start: jest.fn(),
stop: jest.fn(),
}));
6 changes: 0 additions & 6 deletions jsconfig.json

This file was deleted.

23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,27 @@
"android",
"ios"
],
"main": "index.js",
"files": [
"/android/src/",
"/android/build.gradle",
"/ios",
"!Podfile*",
"/windows",
"/src",
"/lib",
"/*.podspec",
"/jest"
],
"types": "src/index.d.ts",
"main": "src/index.js",
"scripts": {
"ci": "yarn install --frozen-lockfile",
"ci": "yarn install --frozen-lockfile && yarn lint && yarn declaration:build && yarn checkjs && yarn test",
"lint": "eslint .",
"checkjs": "tsc",
"eslint:fix": "yarn eslint --fix",
"test": "jest ./__tests__/",
"declaration:build": "tsc -p ./declaration.tsconfig.json",
"prepublishOnly": "yarn declaration:build && yarn checkjs",
"pods": "cd ios && pod install"
},
"repository": {
Expand All @@ -38,6 +53,7 @@
"@semantic-release/github": "^7.0.0",
"@semantic-release/npm": "^7.0.0",
"@types/jest": "^25.1.3",
"@types/react-native": "^0.61.17",
"babel-jest": "^24.9.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
Expand All @@ -48,7 +64,8 @@
"prettier": "^1.18.2",
"react": "16.9.0",
"react-native": "^0.61.4",
"semantic-release": "^17.0.1"
"semantic-release": "^17.0.1",
"typescript": "^3.8.2"
},
"dependencies": {}
}
2 changes: 2 additions & 0 deletions src/RNBackgroundActionsModule.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default RNBackgroundActions;
declare const RNBackgroundActions: any;
File renamed without changes.
69 changes: 69 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export default backgroundServer;
export type BackgroundTaskOptions = {
taskName: string;
taskTitle: string;
taskDesc: string;
taskIcon: {
name: string;
type: string;
package?: string | undefined;
};
color?: string | undefined;
parameters?: any;
};
declare const backgroundServer: BackgroundServer;
/**
* @typedef {{taskName: string,
* taskTitle: string,
* taskDesc: string,
* taskIcon: {name: string, type: string, package?: string},
* color?: string,
* parameters?: any}} BackgroundTaskOptions
*/
declare class BackgroundServer {
_runnedTasks: number;
_stopTask: () => void;
_isRunning: boolean;
/**
* Returns if the current background task is running.
*
* It returns `true` if `start()` has been called and the task has not finished.
*
* It returns `false` if `stop()` has been called, **even if the task has not finished**.
*/
isRunning(): boolean;
/**
* @param {(taskData: any) => Promise<void>} task
* @param {BackgroundTaskOptions} options
* @returns {Promise<void>}
*/
async start(task: (taskData: any) => Promise<void>, options: {
taskName: string;
taskTitle: string;
taskDesc: string;
taskIcon: {
name: string;
type: string;
package?: string | undefined;
};
color?: string | undefined;
parameters?: any;
}): Promise<void>;
/**
* @private
* @param {(taskData: any) => Promise<void>} task
* @param {any} [parameters]
*/
private _generateTask;
/**
* @private
* @param {BackgroundTaskOptions} options
*/
private _normalizeOptions;
/**
* Stops the background task.
*
* @returns {Promise<void>}
*/
async stop(): Promise<void>;
}
8 changes: 8 additions & 0 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class BackgroundServer {
/**
* @param {(taskData: any) => Promise<void>} task
* @param {BackgroundTaskOptions} options
* @returns {Promise<void>}
*/
async start(task, options) {
this._runnedTasks++;
Expand All @@ -46,6 +47,7 @@ class BackgroundServer {
}

/**
* @private
* @param {(taskData: any) => Promise<void>} task
* @param {any} [parameters]
*/
Expand All @@ -60,6 +62,7 @@ class BackgroundServer {
}

/**
* @private
* @param {BackgroundTaskOptions} options
*/
_normalizeOptions(options) {
Expand All @@ -72,6 +75,11 @@ class BackgroundServer {
};
}

/**
* Stops the background task.
*
* @returns {Promise<void>}
*/
async stop() {
this._stopTask();
await RNBackgroundActions.stop();
Expand Down
10 changes: 10 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true,
},
"include": ["src/index.js", "__tests__/", "__mocks__/"],
}
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,26 @@
resolved "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/prop-types@*":
version "15.7.3"
resolved "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==

"@types/react-native@^0.61.17":
version "0.61.17"
resolved "https://registry.npmjs.org/@types/react-native/-/react-native-0.61.17.tgz#5994af207c2339d498ebd8bd427c68074ce9e744"
integrity sha512-12qKZz/ob56lglVRAIDgqDchcyO0g5lZtrjxCTQDNJv8HFHZMcZx78+/CjKsu3LGs6KbajkZ1+0htqiaxr5JVA==
dependencies:
"@types/react" "*"

"@types/react@*":
version "16.9.22"
resolved "https://registry.npmjs.org/@types/react/-/react-16.9.22.tgz#f0288c92d94e93c4b43e3f5633edf788b2c040ae"
integrity sha512-7OSt4EGiLvy0h5R7X+r0c7S739TCU/LvWbkNOrm10lUwNHe7XPz5OLhLOSZeCkqO9JSCly1NkYJ7ODTUqVnHJQ==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

"@types/retry@^0.12.0":
version "0.12.0"
resolved "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz#2b35eccfcee7d38cd72ad99232fbd58bffb3c84d"
Expand Down Expand Up @@ -2634,6 +2654,11 @@ cssstyle@^1.0.0:
dependencies:
cssom "0.3.x"

csstype@^2.2.0:
version "2.6.9"
resolved "https://registry.npmjs.org/csstype/-/csstype-2.6.9.tgz#05141d0cd557a56b8891394c1911c40c8a98d098"
integrity sha512-xz39Sb4+OaTsULgUERcCk+TJj8ylkL4aSVDQiX/ksxbELSqwkgt4d4RD7fovIdgJGSuNYqwZEiVjYY5l0ask+Q==

currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.npmjs.org/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
Expand Down Expand Up @@ -8803,6 +8828,11 @@ typedarray@^0.0.6:
resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=

typescript@^3.8.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.2.tgz#91d6868aaead7da74f493c553aeff76c0c0b1d5a"
integrity sha512-EgOVgL/4xfVrCMbhYKUQTdF37SQn4Iw73H5BgCrF1Abdun7Kwy/QZsE/ssAy0y4LxBbvua3PIbFsbRczWWnDdQ==

ua-parser-js@^0.7.18:
version "0.7.21"
resolved "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.21.tgz#853cf9ce93f642f67174273cc34565ae6f308777"
Expand Down

0 comments on commit 1c9f9b1

Please sign in to comment.