From 013ae22ad4f5d2956dcb61e4055e03834f867201 Mon Sep 17 00:00:00 2001 From: Nurzhan Saktaganov Date: Sun, 28 Oct 2018 23:17:12 +0300 Subject: [PATCH] build config --- .babelrc | 18 ++++++++++++ .gitignore | 3 ++ .npmignore | 1 + README.md | 6 ++-- package.json | 65 ++++++++++++++++++++++++++++++++++++------ src/protect.jsx | 2 +- tools/build.js | 44 ++++++++++++++++++++++++++++ webpack.config.prod.js | 51 +++++++++++++++++++++++++++++++++ 8 files changed, 178 insertions(+), 12 deletions(-) create mode 100644 .babelrc create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 tools/build.js create mode 100644 webpack.config.prod.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..2ea147f --- /dev/null +++ b/.babelrc @@ -0,0 +1,18 @@ +{ + "presets": [ + "env", + "react", + "stage-1" + ], + "plugins": [ + ], + "env": { + "production": { + "plugins": [ + "transform-react-constant-elements", + "transform-react-remove-prop-types", + "transform-object-rest-spread" + ] + } + } + } \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..83dbaee --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +lib + diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 6a66094..4ec7d9b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ `react-rbac-guard` is a module allowing to manage visibility of particular components depending on user credentials (or current permissions set). Module uses approach that was inspired by "react-redux-connect" module. +__The package currently in the early development stage.__ + ## Dependensies ## React RBAC requires either React [new context API](https://reactjs.org/docs/context.html) or React [legacy context API](https://reactjs.org/docs/legacy-context.html) support. @@ -10,7 +12,7 @@ Module tries to use new context API (React version >= 16.3) if available. Otherw ## Installation ## ```bash -#TODO +$> npm install react-rbac-guard ``` ## Integration in 5 easy steps ## @@ -149,7 +151,7 @@ const credentials = new Credentials(...); ## Demo ## -To see demos please visit [TODO]. +To see demos please visit [https://codesandbox.io/s/znmxlw59jm](https://codesandbox.io/s/znmxlw59jm). ## License ## diff --git a/package.json b/package.json index 258354e..0b9e4e3 100644 --- a/package.json +++ b/package.json @@ -1,23 +1,70 @@ { "name": "react-rbac-guard", - "version": "0.0.1", + "version": "0.0.3", "description": "Module allowing to manage visibility of particular components depending on user credentials", - "main": "src/index.js", + "main": "./lib/index.js", + "engines": { + "npm": ">=4" + }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "clean-dist": "rm -rf ./lib && mkdir ./lib", + "prebuild": "npm run clean-dist", + "build": "node tools/build.js" }, - "repository": { - "type": "git", - "url": "git+https://github.com/nurzhan-saktaganov/react-rbac-guard.git" + "author": "Nurzhan Saktaganov ", + "license": "MIT", + "dependencies": { + "uglifyjs-webpack-plugin": "^2.0.1" + }, + "devDependencies": { + "babel-cli": "^6.24.1", + "babel-core": "^6.25.0", + "babel-loader": "^7.1.1", + "babel-plugin-transform-react-constant-elements": "^6.23.0", + "babel-plugin-transform-react-remove-prop-types": "^0.4.6", + "babel-plugin-transform-object-rest-spread": "^6.26.0", + "babel-polyfill": "^6.23.0", + "babel-preset-env": "^1.5.2", + "babel-preset-react": "^6.24.1", + "babel-preset-react-hmre": "^1.1.1", + "babel-preset-stage-1": "^6.24.1", + "babel-register": "^6.24.1", + "chai": "^4.0.2", + "chai-as-promised": "^7.1.0", + "chai-enzyme": "^0.8.0", + "chalk": "^2.0.1", + "coveralls": "^3.0.2", + "enzyme": "^2.9.1", + "eslint-watch": "^3.1.2", + "html-webpack-plugin": "^2.29.0", + "husky": "^1.0.0-rc.15", + "isparta": "^4.0.0", + "jsdom": "^11.2.0", + "mocha": "^3.4.2", + "prop-types": "^15.5.10", + "react": "^15.6.1", + "react-dom": "^15.6.2", + "sinon": "^2.3.6", + "sinon-chai": "^2.11.0", + "webpack": "^3.0.0" + }, + "peerDependencies": { + "react": ">0.14.0 || >15.0.0", + "react-dom": ">0.14.0 || >15.0.0" }, "keywords": [ + "react", "rbac", + "permission", "guard", "protect", - "congitional render" + "conditional render" ], - "author": "Nurzhan Saktaganov ", - "license": "MIT", + "repository": { + "type": "git", + "url": "git+https://github.com/nurzhan-saktaganov/react-rbac-guard.git" + }, "bugs": { "url": "https://github.com/nurzhan-saktaganov/react-rbac-guard/issues" }, diff --git a/src/protect.jsx b/src/protect.jsx index ae5a2c7..f8d2d7f 100644 --- a/src/protect.jsx +++ b/src/protect.jsx @@ -9,7 +9,7 @@ function protect(requirement) { } return function(ComponentToProtect) { - const isComponent = + const isComponent = true || ComponentToProtect && ComponentToProtect.prototype && ComponentToProtect.prototype instanceof Component; diff --git a/tools/build.js b/tools/build.js new file mode 100644 index 0000000..dc33f05 --- /dev/null +++ b/tools/build.js @@ -0,0 +1,44 @@ +// More info on Webpack's Node API here: https://webpack.github.io/docs/node.js-api.html +// Allowing console calls below since this is a build file. +/* eslint-disable no-console */ +const chalk = require('chalk'); +const webpack = require('webpack'); +const config = require('../webpack.config.prod'); + +const chalkConfig = { + chalkError: chalk.red, + chalkSuccess: chalk.green, + chalkWarning: chalk.yellow, + chalkProcessing: chalk.blue, +}; + +const { chalkError, chalkSuccess, chalkWarning, chalkProcessing } = chalkConfig; + +process.env.NODE_ENV = 'production'; // this assures React is built in prod mode and that the Babel dev config doesn't apply. + +console.log(chalkProcessing('Generating minified bundle. This will take a moment...')); + +webpack(config).run((error, stats) => { + if (error) { // so a fatal error occurred. Stop here. + console.log(chalkError(error)); + return 1; + } + + const jsonStats = stats.toJson(); + + if (jsonStats.hasErrors) { + return jsonStats.errors.map(error => console.log(chalkError(error))); + } + + if (jsonStats.hasWarnings) { + console.log(chalkWarning('Webpack generated the following warnings: ')); + jsonStats.warnings.map(warning => console.log(chalkWarning(warning))); + } + + console.log(`Webpack stats: ${stats}`); + + // if we got this far, the build succeeded. + console.log(chalkSuccess('Your app is compiled in production mode in /lib. It\'s ready to roll!')); + + return 0; +}); diff --git a/webpack.config.prod.js b/webpack.config.prod.js new file mode 100644 index 0000000..d32b6b4 --- /dev/null +++ b/webpack.config.prod.js @@ -0,0 +1,51 @@ +'use strict'; + +const webpack = require('webpack'); +const path = require('path'); + +module.exports = { + externals: [ + { + 'react-dom': { + root: 'ReactDOM', + commonjs2: 'react-dom', + commonjs: 'react-dom', + amd: 'react-dom' + }, + }, + { + react: { + root: 'React', + commonjs2: 'react', + commonjs: 'react', + amd: 'react', + }, + }, + ], + resolve: { + extensions: ['.js', '.jsx', '.json'], + modules: [ + 'node_modules', + path.join(__dirname, 'src'), + ], + }, + devtool: 'source-map', + entry: './src/index.js', + output: { + filename: 'index.js', + library: 'react-rbac-guard', + libraryTarget: 'umd', + path: path.resolve(__dirname, 'lib'), + umdNamedDefine: true, + }, + module: { + rules: + [ + { + test: /\.jsx$/, + exclude: /node_modules/, + loader: ['babel-loader'], + }, + ], + }, +};