@samitouri / QOS-React-2 / commits / e361fcb3e6

Add skeleton for react-codemod

cpojer committed Mar 25, 2015 at 01:27 UTC e361fcb3e63cc12ee03f2b6d53cf83dec51c160b
6 files changed +103 -1
.eslintignore
+5 -1
@@ -19,4 +19,8 @@ docs/js/
19 examples/
20 # Ignore built files.
21 build/
22 -
22 +# react-codemod
23 +npm-react-codemod/test/
24 +npm-react-codemod/scripts/
25 +npm-react-codemod/build/
26 +npm-react-codemod/node_modules/
npm-react-codemod/.npmignore new
+1
@@ -0,0 +1 @@
1 +/transforms/
npm-react-codemod/README.md new
+19
@@ -0,0 +1,19 @@
1 +## react-codemod
2 +
3 +This repository contains a collection of codemod scripts based on
4 +[JSCodeshift](https://github.com/facebook/jscodeshift) that help update React
5 +APIs.
6 +
7 +### Setup & Run
8 +
9 + * `npm install -g react-codemod`
10 + * `react-codemod <codemod-script> <file>`
11 + * Use the `-d` option for a dry-run and use `-p` to print the output
12 + for comparison
13 +
14 +### Recast Options
15 +
16 +Options to [recast](https://github.com/benjamn/recast)'s printer can be provided
17 +through the `printOptions` command line argument
18 +
19 + * `react-codemod class <file> --printOptions='{"quote":"double"}'`
npm-react-codemod/package.json new
+32
@@ -0,0 +1,32 @@
1 +{
2 + "name": "react-codemod",
3 + "version": "1.0.0",
4 + "description": "React codemod scripts",
5 + "license": "BSD-3-Clause",
6 + "repository": {
7 + "type": "git",
8 + "url": "https://github.com/facebook/react"
9 + },
10 + "scripts": {
11 + "build": "rm -rf build; babel transforms/ --out-dir=build/",
12 + "test": "jest",
13 + "prepublish": "npm run build"
14 + },
15 + "bin": {
16 + "react-codemod": "./react-codemod"
17 + },
18 + "dependencies": {
19 + "jscodeshift": "^0.1.0"
20 + },
21 + "devDependencies": {
22 + "babel": "^4.7.16",
23 + "babel-jest": "^4.0.0",
24 + "jest-cli": "^0.4.0"
25 + },
26 + "jest": {
27 + "scriptPreprocessor": "./node_modules/babel-jest",
28 + "testPathDirs": [
29 + "test"
30 + ]
31 + }
32 +}
npm-react-codemod/react-codemod new
+7
@@ -0,0 +1,7 @@
1 +#!/bin/bash
2 +
3 +DIR=$(npm root -g)/react-codemod
4 +TRANSFORM=$1
5 +shift
6 +
7 +$DIR/node_modules/.bin/jscodeshift -t $DIR/build/$TRANSFORM.js $@
npm-react-codemod/test/__tests__/transform-tests.js new
+39
@@ -0,0 +1,39 @@
1 +/*
2 + * Copyright (c) 2015-present, Facebook, Inc.
3 + * All rights reserved.
4 + *
5 + * This source code is licensed under the BSD-style license found in the
6 + * LICENSE file in the root directory of this source tree. An additional grant
7 + * of patent rights can be found in the PATENTS file in the same directory.
8 + *
9 + */
10 +
11 +"use strict";
12 +
13 +jest.autoMockOff();
14 +
15 +var fs = require('fs');
16 +var jscodeshift = require('jscodeshift');
17 +
18 +function read(fileName) {
19 + return fs.readFileSync(__dirname + '/../' + fileName, 'utf8');
20 +}
21 +
22 +function test(transformName, testFileName, options) {
23 + var path = testFileName + '.js';
24 + var source = read(testFileName + '.js');
25 + var output = read(testFileName + '.output.js');
26 +
27 + var transform = require('../../transforms/' + transformName);
28 + expect(
29 + (transform({path, source}, {jscodeshift}, options || {}) || '').trim()
30 + ).toEqual(
31 + output.trim()
32 + );
33 +}
34 +
35 +describe('Transform Tests', () => {
36 +
37 +
38 +
39 +});