Skip to content

Commit

Permalink
build config
Browse files Browse the repository at this point in the history
  • Loading branch information
nurzhan-saktaganov committed Oct 28, 2018
1 parent 2c52084 commit 013ae22
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
lib

1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ##
Expand Down Expand Up @@ -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 ##
Expand Down
65 changes: 56 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <nur92world@mail.ru>",
"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 <nur92world@mail.ru>",
"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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/protect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function protect(requirement) {
}

return function(ComponentToProtect) {
const isComponent =
const isComponent = true ||
ComponentToProtect &&
ComponentToProtect.prototype &&
ComponentToProtect.prototype instanceof Component;
Expand Down
44 changes: 44 additions & 0 deletions tools/build.js
Original file line number Diff line number Diff line change
@@ -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;
});
51 changes: 51 additions & 0 deletions webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -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'],
},
],
},
};

0 comments on commit 013ae22

Please sign in to comment.