Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vasco3/cuadrante-codemods
Code modifiers using jscodeshift
https://github.com/vasco3/cuadrante-codemods
codemod cuadrante-codemods ecmascript es6-modules jscodeshift
Last synced: 6 days ago
JSON representation
Code modifiers using jscodeshift
- Host: GitHub
- URL: https://github.com/vasco3/cuadrante-codemods
- Owner: vasco3
- License: mit
- Created: 2016-08-14T20:38:45.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-04T20:51:16.000Z (over 7 years ago)
- Last Synced: 2024-08-02T07:15:37.877Z (3 months ago)
- Topics: codemod, cuadrante-codemods, ecmascript, es6-modules, jscodeshift
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/cuadrante-codemods
- Size: 8.79 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-codemods - vasco3/cuadrante-codemods - Converts ES6 imports to commonJS requires. (JavaScript)
README
# cuadrante-codemods
[![Known Vulnerabilities](https://snyk.io/test/github/vasco3/cuadrante-codemods/badge.svg)](https://snyk.io/test/github/vasco3/cuadrante-codemods)
Code modifiers using jscodeshift
> Thanks to Node v6 now we don't need babel to run ES2015 in our servers.
> In that case, if you don't trading off the nice ES2015 modules for good old
> commonJS, you can run this script to liberate your server from a build process.## Requirements
- Node v6+
- npm install -g jscodeshift## Usage
- `cd` into your project directory
- `npm install cuadrante-codemods`
- `jscodeshift -t `## Example
Using `find` to loop through al the javascript files
- `find . -name '*.js' -print | xargs jscodeshift -t node_modules/cuadrante-codemods/lib/es2015modules-to-commonjs.js`
Will do the following
```diff
-import fs from 'fs'
+const fs = require('fs');-import {getWhatever, findWhatever} from 'library'
+const {getWhatever, findWhatever} = require('library');-import settings from './settings';
+const settings = require('./settings');-import homeRoute from './routes/home';
+const homeRoute = require('./routes/home');-import App from './routes/App';
+const App = require('./routes/App');-import stockOptionsGameRoute from './routes/stock-options-game';
+const stockOptionsGameRoute = require('./routes/stock-options-game');-export function wawa() { return 0; }
+exports.wawa = function wawa() {
+ return 0;
+};-export default (req, res) => { return true }
+module.exports = (req, res) => {
+ return true
+};-export const MARKER_REMOVED_OUT = 'MARKER_REMOVED_OUT';
+exports.MARKER_REMOVED_OUT = 'MARKER_REMOVED_OUT';
```## Explore
www.astexplorer.net
parser: Recast
transformer: jscodeshift### AST Types
Look for the builder method
https://github.com/benjamn/ast-types
## Inspiration
- [Converts commonJS requires to es6 imports](https://gist.github.com/dmnd/12cad812c3f969e4f76c)