diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..39886c6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,10 @@ +{ + "presets": [ + "es2015", + "stage-0", + "react" + ], + "plugins": [ + "transform-flow-strip-types" + ] +} diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..680a40f --- /dev/null +++ b/.eslintrc @@ -0,0 +1,121 @@ +{ + + "parser": "babel-eslint", + + "env": { + "es6": true, + "jest": true, + "node": true, + "browser": true + }, + + "plugins": [ + "jsdoc", + "flowtype", + "require-jsdoc" + ], + + "rules": { + "indent": ["error", 2, { "CallExpression": {"arguments": "first"}, "SwitchCase": 1 }], + "strict": 0, + "import/no-extraneous-dependencies": 0, + "import/no-named-as-default": 0, + "no-duplicate-imports": 0, + "no-underscore-dangle": 0, + "class-methods-use-this": 0, + "jsdoc/check-param-names": 1, + "jsdoc/check-tag-names": 1, + "jsdoc/check-types": 1, + "jsdoc/newline-after-description": 1, + "jsdoc/require-description-complete-sentence": 1, + "jsdoc/require-hyphen-before-param-description": 1, + "jsdoc/require-param": 1, + "jsdoc/require-param-description": 1, + "jsdoc/require-param-type": 1, + "jsdoc/require-returns-description": 1, + "jsdoc/require-returns-type": 1, + "require-jsdoc": 2, + "valid-jsdoc": 2, + "flowtype/boolean-style": [ + 2, + "boolean" + ], + "flowtype/define-flow-type": 1, + "flowtype/delimiter-dangle": [ + 2, + "never" + ], + "flowtype/generic-spacing": [ + 2, + "never" + ], + "flowtype/no-primitive-constructor-types": 2, + "flowtype/no-weak-types": 1, + "flowtype/object-type-delimiter": [ + 2, + "comma" + ], + "flowtype/require-parameter-type": 2, + "flowtype/require-return-type": [ + 2, + "always", + { + "annotateUndefined": "never", + "excludeArrowFunctions": true + } + ], + "flowtype/require-valid-file-annotation": 2, + "flowtype/semi": [ + 2, + "always" + ], + "flowtype/space-after-type-colon": [ + 2, + "always" + ], + "flowtype/space-before-generic-bracket": [ + 2, + "never" + ], + "flowtype/space-before-type-colon": [ + 2, + "never" + ], + "flowtype/type-id-match": [ + 2, + "^([A-Z][a-z0-9]+)+Type$" + ], + "flowtype/union-intersection-spacing": [ + 2, + "always" + ], + "flowtype/use-flow-type": 1, + "flowtype/valid-syntax": 1 + }, + + "parserOptions": { + "ecmaVersion": 7, + "experimentalObjectRestSpread": true, + "sourceType": "module" + }, + + "extends": [ + "airbnb", + "plugin:flowtype/recommended" + ], + + "settings": { + "flowtype": { + "onlyFilesWithFlowAnnotation": true + }, + "require-jsdoc": ["error", { + "require": { + "FunctionDeclaration": true, + "MethodDefinition": true, + "ClassDeclaration": true, + "ArrowFunctionExpression": false + } + }] + } + +} diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 0000000..4a58bdc --- /dev/null +++ b/.flowconfig @@ -0,0 +1,7 @@ +[ignore] + +[include] + +[libs] + +[options] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9657746 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +lib/ +node_modules/ +coverage/ +npm-debug.log +.idea +lerna-debug.log +dump.rdb diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..77d92d7 --- /dev/null +++ b/.npmignore @@ -0,0 +1,7 @@ +src/ +coverage/ +wallaby.js +webpack.config.js +.babelrc +.eslintrc +.flowconfig diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9a7d7c1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Tim Mikeladze + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..12b17d1 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# roles-react + +REST packages for https://github.com/Intelight/roles + +[![npm](https://img.shields.io/npm/v/roles-react.svg)](https://www.npmjs.com/package/roles-react) [![CircleCI](https://circleci.com/gh/Intelight/roles-react.svg?style=svg)](https://circleci.com/gh/Intelight/roles-react)[![Coverage Status](https://coveralls.io/repos/github/intelight/roles-react/badge.svg?branch=master)](https://coveralls.io/github/intelight/roles-react?branch=master) ![MIT License](https://img.shields.io/badge/license-MIT-blue.svg) diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..31e8e27 --- /dev/null +++ b/circle.yml @@ -0,0 +1,3 @@ +machine: + node: + version: 6.2.1 diff --git a/package.json b/package.json new file mode 100644 index 0000000..9fac733 --- /dev/null +++ b/package.json @@ -0,0 +1,64 @@ +{ + "name": "roles-react", + "version": "0.0.1", + "description": "Roles React components", + "main": "lib/index.js", + "publishConfig": { + "access": "public" + }, + "scripts": { + "start": "webpack -p --config --progress --watch", + "compile": "babel ./src --out-dir ./lib", + "flow:check": "flow check", + "prepublish": "npm run compile", + "pretest": "npm run lint", + "test": "npm run testonly", + "test-ci": "npm lint && npm coverage", + "testonly": "jest", + "lint": "eslint src", + "coverage": "npm run testonly -- --coverage", + "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage" + }, + "jest": { + "testEnvironment": "node", + "testRegex": "(/.*.(test|spec)).(js|jsx)$" + }, + "repository": { + "type": "git", + "url": "https://github.com/intelight/roles-react" + }, + "keywords": [ + "roles", + "permissions" + ], + "author": "Tim Mikeladze", + "license": "MIT", + "dependencies": { + "lodash": "^4.16.4" + }, + "devDependencies": { + "babel-cli": "^6.18.0", + "babel-core": "^6.18.0", + "babel-eslint": "^7.1.0", + "babel-loader": "^6.2.7", + "babel-plugin-transform-flow-strip-types": "^6.21.0", + "babel-preset-es2015": "^6.18.0", + "babel-preset-react": "^6.22.0", + "babel-preset-stage-0": "^6.22.0", + "coveralls": "^2.11.14", + "eslint": "^3.11.1", + "eslint-config-airbnb": "^13.0.0", + "eslint-config-airbnb-base": "^9.0.0", + "eslint-plugin-flowtype": "^2.29.1", + "eslint-plugin-import": "^2.2.0", + "eslint-plugin-jsdoc": "^2.4.0", + "eslint-plugin-jsx-a11y": "^2.2.3", + "eslint-plugin-react": "^6.7.1", + "eslint-plugin-require-jsdoc": "^1.0.4", + "flow-bin": "^0.37.0", + "jest": "^18.0.0", + "regenerator-runtime": "^0.9.6", + "webpack": "^1.13.3", + "webpack-node-externals": "^1.5.4" + } +} diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..3ba6b7b --- /dev/null +++ b/src/index.js @@ -0,0 +1,39 @@ +// import { Component, PropTypes } from 'react'; +// import Roles from './roles'; +// +// class RoleCheck extends Component { +// static propTypes = { +// children: PropTypes.node.isRequired, +// roles: PropTypes.oneOfType([ +// PropTypes.string, +// PropTypes.array, +// ]), +// group: PropTypes.string.isRequired, +// userId: PropTypes.string.isRequired, +// } +// constructor(props, context) { +// super(props, context); +// this.state = { +// isLoading: true, +// hasAccess: false, +// }; +// } +// componentDidMount() { +// const { roles, group, userId } = this.props; +// // TODO Catch and handle promise error +// const promise = roles +// ? Roles.userIsInRole(userId, roles, group) +// : Roles.userIsInGroup(userId, group); +// promise.then((res) => { +// this.setState({ +// isLoading: false, +// hasAccess: res, +// }); +// }); +// } +// render() { +// return this.state.hasAccess && this.props.children; +// } +// } +// +// export default RoleCheck; diff --git a/src/index.spec.js b/src/index.spec.js new file mode 100644 index 0000000..289e2c7 --- /dev/null +++ b/src/index.spec.js @@ -0,0 +1,5 @@ +describe('empty test suite', () => { + it('empty test', () => { + + }); +}); diff --git a/wallaby.js b/wallaby.js new file mode 100644 index 0000000..f9c6d62 --- /dev/null +++ b/wallaby.js @@ -0,0 +1,22 @@ +module.exports = function (wallaby) { + return { + files: [ + 'src/**/*.js', + '!src/**/*.spec.js', + ], + + tests: [ + 'src/**/*.spec.js', + ], + + compilers: { + 'src/**/*.js': wallaby.compilers.babel(), + }, + + env: { + type: 'node', + }, + + testFramework: 'jest', + }; +}; diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..5d0985f --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,27 @@ +const path = require('path'); +const nodeExternals = require('webpack-node-externals'); + +module.exports = { + entry: './src/index.js', + target: 'node', + externals: [nodeExternals()], + output: { + path: path.join(__dirname, '/lib'), + filename: 'index.js', + library: 'roles-react', + libraryTarget: 'umd', + }, + modulesDirectories: [ + 'src', + 'node_modules', + ], + module: { + loaders: [ + { + test: /\.js$/, + loader: 'babel', + exclude: /node_modules/, + }, + ], + }, +};