Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add s2s-plugins-redux
Browse files Browse the repository at this point in the history
  • Loading branch information
akameco committed Oct 11, 2017
1 parent 8895110 commit 0c3e361
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
74 changes: 74 additions & 0 deletions packages/s2s-plugins-redux/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @flow
const path = require('path')

const actionTypesPlugin = require('babel-plugin-s2s-action-types').default
const actionCreaterPlugin = require('babel-plugin-s2s-action-creater').default
const reducerCaseCreaterPlugin = require('babel-plugin-s2s-reducer-case-creater')
.default
const actionRootPlugin = require('babel-plugin-s2s-action-root').default
const reducerTestCasePlugin = require('babel-plugin-s2s-reducer-test-case')
.default
const stateRootPlugin = require('babel-plugin-s2s-state-root').default
const reducerRootPlugin = require('babel-plugin-s2s-reducer-root').default

const cwd = process.cwd()

const getRootDir = (...x) => path.resolve(cwd, 'src', ...x)
const getTyepDir = x => getRootDir('types', x)

const rootReducerPath = getRootDir('reducer.js')
const rootActionPath = getTyepDir('action.js')
const rootStatePath = getTyepDir('state.js')

const plugins = [
{
test: /actionTypes.js$/,
plugin: [actionTypesPlugin, { removePrefix: 'src/containers' }],
},
{
test: /actionTypes.js$/,
output: 'actions.js',
plugin: [actionCreaterPlugin],
},
{
test: /actionTypes.js$/,
input: 'reducer.js',
output: 'reducer.js',
plugin: [reducerCaseCreaterPlugin],
},
{
test: /actionTypes.js$/,
input: rootActionPath,
output: rootActionPath,
plugin: [
actionRootPlugin,
{ input: 'src/**/actionTypes.js', output: rootActionPath },
],
},
{
test: /containers\/.+reducer.js/,
input: 'reducer.test.js',
output: 'reducer.test.js',
plugin: [reducerTestCasePlugin],
},
{
test: /containers\/.+reducer.js/,
input: rootStatePath,
output: rootStatePath,
plugin: [
stateRootPlugin,
{ input: 'src/containers/**/reducer.js', output: rootStatePath },
],
},
{
test: /containers\/.+reducer.js/,
input: rootReducerPath,
output: rootReducerPath,
plugin: [
reducerRootPlugin,
{ input: 'src/containers/**/reducer.js', output: rootReducerPath },
],
},
]

module.exports = plugins
26 changes: 26 additions & 0 deletions packages/s2s-plugins-redux/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "s2s-plugins-redux",
"version": "0.0.0",
"description": "s2s plugins for redux",
"license": "MIT",
"repository": "akameco/s2s-plugins",
"author": {
"name": "akameco",
"email": "akameco.t@gmail.com",
"url": "akameco.github.io"
},
"engines": {
"node": ">=6"
},
"main": "index.js",
"files": ["index.js"],
"dependencies": {
"babel-plugin-s2s-action-creater": "^0.2.2",
"babel-plugin-s2s-action-root": "^0.3.2",
"babel-plugin-s2s-action-types": "^0.4.2",
"babel-plugin-s2s-reducer-case-creater": "^0.1.1",
"babel-plugin-s2s-reducer-root": "^0.2.2",
"babel-plugin-s2s-reducer-test-case": "^0.4.2",
"babel-plugin-s2s-state-root": "^0.2.2"
}
}
42 changes: 42 additions & 0 deletions packages/s2s-plugins-redux/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# s2s-plugins-redux

> s2s plugins for redux

## Plugins

### babel-plugin-s2s-action-creater
### babel-plugin-s2s-action-root
### babel-plugin-s2s-action-types
### babel-plugin-s2s-reducer-case-creater
### babel-plugin-s2s-reducer-root
### babel-plugin-s2s-reducer-test-case
### babel-plugin-s2s-state-root

## Usage

s2s.config.js

```js
const plugins = require('s2s-plugins-redux')

module.exports = {
watch: './**/*.js',
plugins,
templates: [
{ test: /containers\/.*\/index.js/, input: 'containers.js' },
{ test: /components\/.*\/index.js/, input: 'components.js' },
{ test: /components\/.*\/index.test.js/, input: 'component.test.js' },
{ test: /reducer.js/, input: 'reducer.js' },
{ test: /reducer.js/, input: 'reducer.test.js', output: 'reducer.test.js' },
{ test: /reducer.js/, input: 'actionTypes.js', output: 'actionTypes.js' },
{ test: /selectors.js/, input: 'selectors.js' },
{ test: /selectors.test.js/, input: 'selectors.test.js' },
{ test: /logic.js/, input: 'logic.js' },
],
}

```

### Examples
[s2s-examples/shopping-cart](https://github.com/akameco/s2s-examples/tree/master/shopping-cart)

0 comments on commit 0c3e361

Please sign in to comment.