Add skeleton for react-codemod

This commit is contained in:
cpojer 2015-03-25 01:27:45 -07:00
parent 45fdb4ba79
commit e361fcb3e6
6 changed files with 103 additions and 1 deletions

View File

@ -19,4 +19,8 @@ docs/js/
examples/
# Ignore built files.
build/
# react-codemod
npm-react-codemod/test/
npm-react-codemod/scripts/
npm-react-codemod/build/
npm-react-codemod/node_modules/

View File

@ -0,0 +1 @@
/transforms/

View File

@ -0,0 +1,19 @@
## react-codemod
This repository contains a collection of codemod scripts based on
[JSCodeshift](https://github.com/facebook/jscodeshift) that help update React
APIs.
### Setup & Run
* `npm install -g react-codemod`
* `react-codemod <codemod-script> <file>`
* Use the `-d` option for a dry-run and use `-p` to print the output
for comparison
### Recast Options
Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
through the `printOptions` command line argument
* `react-codemod class <file> --printOptions='{"quote":"double"}'`

View File

@ -0,0 +1,32 @@
{
"name": "react-codemod",
"version": "1.0.0",
"description": "React codemod scripts",
"license": "BSD-3-Clause",
"repository": {
"type": "git",
"url": "https://github.com/facebook/react"
},
"scripts": {
"build": "rm -rf build; babel transforms/ --out-dir=build/",
"test": "jest",
"prepublish": "npm run build"
},
"bin": {
"react-codemod": "./react-codemod"
},
"dependencies": {
"jscodeshift": "^0.1.0"
},
"devDependencies": {
"babel": "^4.7.16",
"babel-jest": "^4.0.0",
"jest-cli": "^0.4.0"
},
"jest": {
"scriptPreprocessor": "./node_modules/babel-jest",
"testPathDirs": [
"test"
]
}
}

View File

@ -0,0 +1,7 @@
#!/bin/bash
DIR=$(npm root -g)/react-codemod
TRANSFORM=$1
shift
$DIR/node_modules/.bin/jscodeshift -t $DIR/build/$TRANSFORM.js $@

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
"use strict";
jest.autoMockOff();
var fs = require('fs');
var jscodeshift = require('jscodeshift');
function read(fileName) {
return fs.readFileSync(__dirname + '/../' + fileName, 'utf8');
}
function test(transformName, testFileName, options) {
var path = testFileName + '.js';
var source = read(testFileName + '.js');
var output = read(testFileName + '.output.js');
var transform = require('../../transforms/' + transformName);
expect(
(transform({path, source}, {jscodeshift}, options || {}) || '').trim()
).toEqual(
output.trim()
);
}
describe('Transform Tests', () => {
});