diff --git a/.travis.yml b/.travis.yml index b3540ac..d156815 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: node_js node_js: - - "11" + - '11' diff --git a/package.json b/package.json index 1061a3e..a75ba25 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "source": "src/rehook/index.js", "types": "dist/rehook.d.ts", "devDependencies": { - "@otris/jsdoc-tsd": "^1.0.4", "babel-eslint": "9.0.0", "enzyme": "^3.7.0", "enzyme-adapter-react-16": "^1.6.0", @@ -31,10 +30,14 @@ "react-scripts": "2.1.0", "rollup": "^0.67.1", "rollup-plugin-babel": "^4.0.3", + "rollup-plugin-cleaner": "^0.2.0", "rollup-plugin-commonjs": "^9.2.0", + "rollup-plugin-copy": "^0.2.3", "rollup-plugin-node-resolve": "^3.4.0", "rollup-plugin-replace": "^2.1.0", - "rollup-plugin-uglify": "^6.0.0" + "rollup-plugin-uglify": "^6.0.0", + "tslint": "^5.11.0", + "tslint-config-airbnb": "^5.11.1" }, "peerDependencies": { "react": "^16.7.0-alpha.0", @@ -44,12 +47,12 @@ "start": "react-scripts start", "build": "react-scripts build", "test:eslint": "eslint src --fix", + "test:tslint": "tslint src/rehook/index.d.ts --project tsconfig.json --fix", "test:jest": "react-scripts test", - "test": "CI=true npm run test:eslint && CI=true npm run test:jest --findRelatedTests", + "test": "CI=true npm run test:eslint && CI=true npm run test:tslint && CI=true npm run test:jest --findRelatedTests", "eject": "react-scripts eject", "build:bundle": "NODE_ENV='production' rollup --config rollup.config.js", - "build:types": "jsdoc -t node_modules/@otris/jsdoc-tsd -r ./src/rehook -d dist/rehook.d.ts", - "prepublish": "npm run build:bundle && npm run build:types" + "prepublish": "npm run build:bundle" }, "browserslist": [ ">0.2%", diff --git a/rollup.config.js b/rollup.config.js index 4ab3d10..c966bae 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,13 +1,18 @@ -import replace from 'rollup-plugin-replace'; -import resolve from 'rollup-plugin-node-resolve'; -import commonjs from 'rollup-plugin-commonjs'; -import babel from 'rollup-plugin-babel'; +import replace from 'rollup-plugin-replace' +import resolve from 'rollup-plugin-node-resolve' +import commonjs from 'rollup-plugin-commonjs' +import babel from 'rollup-plugin-babel' +import copy from 'rollup-plugin-copy' +import cleaner from 'rollup-plugin-cleaner' export default [ { input: './src/rehook/index.js', external: ['react', 'react-dom'], plugins: [ + cleaner({ + targets: ['dist'], + }), replace({ 'process.env.NODE_ENV': JSON.stringify('production'), }), @@ -19,6 +24,10 @@ export default [ exclude: 'node_modules/**', runtimeHelpers: true, }), + copy({ + 'src/rehook/index.d.ts': 'dist/rehook.d.ts', + verbose: true, + }), ], output: [ { diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts new file mode 100644 index 0000000..6431bc5 --- /dev/null +++ b/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/src/rehook/index.d.ts b/src/rehook/index.d.ts new file mode 100644 index 0000000..5094650 --- /dev/null +++ b/src/rehook/index.d.ts @@ -0,0 +1,148 @@ +/** + * + * @param condition + * @param left + * @param right + * @returns + */ +export function branch( + condition: Function, + left: Function, + right: Function +): Function + +/** + * + * @param component + * @returns + */ +export function catchRender(component: Function): Object + +/** + * + * @param defaultProps + * @returns + */ +export function defaultProps(defaultProps: Object): Object + +/** + * + * @param propName + * @returns + */ +export function flattenProp(propName: string | symbol): Object + +/** + * + * @param spec + * @returns + */ +export function lifecycle(spec: Object): Object + +/** + * + * @param fn + * @returns + */ +export function mapProps(fn: Function): Object + +/** + * + * @param propName + * @param enhance + * @returns + */ +export function namespace(propName: string | symbol, enhance: Function): Object + +/** + * + * @param fns + * @returns + */ +export function pipe(...fns: Function): Object + +/** + * + * @param a + * @param b + * @returns + */ +export function renameProp(a: string | symbol, b: string | symbol): Object + +/** + * + * @param propMap + * @returns + */ +export function renameProps(propMap: Object): Object + +/** + * + * @param comp + * @returns + */ +export function renderComponent(comp: any): Object + +/** + * + * @returns + */ +export function renderNothing(): Object + +/** + * + * @param handlers + * @returns + */ +export function withHandlers(handlers: Object): Object + +/** + * + * @param shouldMapOrKeys + * @param createProps + * @returns + */ +export function withPropsOnChange( + shouldMapOrKeys: any, + createProps: Function +): Object + +/** + * + * @param fn + */ +export function withProps(fn: object | ((props: object) => object)): (props: object) => { [key: string]: string } + +/** + * + * @param stateName + * @param dispatchName + * @param reducer + * @param initialValue + */ +export function withReducer( + stateName: string | symbol, + dispatchName: string | symbol, + reducer: Function, + initialValue: any +): void + +/** + * + * @param initialValue + * @param handlers + * @returns + */ +export function withStateHandlers(initialValue: any, handlers: Object): Object + +/** + * + * @param stateName + * @param stateUpdaterName + * @param initialState + */ +export function withState( + stateName: string | symbol, + stateUpdaterName: string | symbol, + initialState: any +): void diff --git a/src/rehook/render-nothing.js b/src/rehook/render-nothing.js index 3b055f1..98a7663 100644 --- a/src/rehook/render-nothing.js +++ b/src/rehook/render-nothing.js @@ -3,7 +3,7 @@ */ const renderNothing = (/* props */) => { // eslint-disable-next-line - throw null; + throw null } export default renderNothing diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..58b8599 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "target": "es5", + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "preserve" + }, + "include": ["src"] +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..6c881e9 --- /dev/null +++ b/tslint.json @@ -0,0 +1,18 @@ +{ + "extends": [ + "tslint:latest" + ], + "rules": { + "semicolon": [ + true, + "never" + ], + "ban-types": [ + false + ], + "trailing-comma": [ + true, + "never" + ] + } +} \ No newline at end of file