diff --git a/babel-plugin/LICENSE b/babel-plugin/LICENSE new file mode 100644 index 0000000..817f3da --- /dev/null +++ b/babel-plugin/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Konrad LisiczyƄski + +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/babel-plugin/README.md b/babel-plugin/README.md new file mode 100644 index 0000000..3e4eb1b --- /dev/null +++ b/babel-plugin/README.md @@ -0,0 +1,16 @@ +# babel-plugin-redux-smart-actions + +[![npm version](https://badge.fury.io/js/redux-smart-actions.svg)](https://badge.fury.io/js/babel-plugin-redux-smart-actions) +[![Build Status](https://travis-ci.org/klis87/redux-smart-actions.svg?branch=master)](https://travis-ci.org/klis87/redux-smart-actions) +[![Coverage Status](https://coveralls.io/repos/github/klis87/redux-smart-actions/badge.svg?branch=master)](https://coveralls.io/github/klis87/redux-smart-actions?branch=master) +[![Known Vulnerabilities](https://snyk.io/test/github/klis87/redux-smart-actions/badge.svg)](https://snyk.io/test/github/klis87/redux-smart-actions) +[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) + +Babel plugin for [redux-smart-actions](https://github.com/klis87/redux-smart-actions), +which together provide the fastest possible way to write Redux actions and thunks! + +See `redux-smart-actions` docs for usage. + +## Licence + +MIT diff --git a/babel-plugin/package.json b/babel-plugin/package.json new file mode 100644 index 0000000..fe8aa30 --- /dev/null +++ b/babel-plugin/package.json @@ -0,0 +1,24 @@ +{ + "name": "babel-plugin-redux-smart-actions", + "version": "0.1.1", + "description": "Babel plugin for redux-smart-actions to reduce boilerplate even more", + "main": "src/index.js", + "module": "src/index.js", + "jsnext:main": "src/index.js", + "repository": "git@github.com:klis87/redux-smart-actions.git", + "author": "Konrad Lisiczynski ", + "license": "MIT", + "keywords": [ + "redux", + "actions", + "thunks", + "redux-actions", + "redux-thunk", + "babel", + "babel-plugin" + ], + "homepage": "https://github.com/klis87/redux-smart-actions", + "bugs": { + "url": "https://github.com/klis87/redux-smart-actions/issues" + } +} diff --git a/babel-plugin/src/index.js b/babel-plugin/src/index.js new file mode 100644 index 0000000..ea766e6 --- /dev/null +++ b/babel-plugin/src/index.js @@ -0,0 +1,43 @@ +const { declare } = require('@babel/helper-plugin-utils'); +const { types: t } = require('@babel/core'); + +module.exports = declare(api => { + api.assertVersion(7); + + return { + visitor: { + ImportSpecifier(path) { + if (path.node.imported.name === 'createSmartAction') { + path.node.imported.name = 'createAction'; + path.node.local.name = 'createAction'; + } else if (path.node.imported.name === 'createSmartThunk') { + path.node.imported.name = 'createThunk'; + path.node.local.name = 'createThunk'; + } + }, + VariableDeclarator(path) { + if ( + path.node.init && + path.node.init.callee && + path.node.init.callee.name === 'createSmartAction' + ) { + path.node.init.callee.name = 'createAction'; + path.node.init.arguments = [ + t.stringLiteral(path.node.id.name), + ...path.node.init.arguments, + ]; + } else if ( + path.node.init && + path.node.init.callee && + path.node.init.callee.name === 'createSmartThunk' + ) { + path.node.init.callee.name = 'createThunk'; + path.node.init.arguments = [ + t.stringLiteral(path.node.id.name), + ...path.node.init.arguments, + ]; + } + }, + }, + }; +});