mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Add skeleton for react-codemod
This commit is contained in:
parent
45fdb4ba79
commit
e361fcb3e6
|
|
@ -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/
|
||||
|
|
|
|||
1
npm-react-codemod/.npmignore
Normal file
1
npm-react-codemod/.npmignore
Normal file
|
|
@ -0,0 +1 @@
|
|||
/transforms/
|
||||
19
npm-react-codemod/README.md
Normal file
19
npm-react-codemod/README.md
Normal 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"}'`
|
||||
32
npm-react-codemod/package.json
Normal file
32
npm-react-codemod/package.json
Normal 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"
|
||||
]
|
||||
}
|
||||
}
|
||||
7
npm-react-codemod/react-codemod
Executable file
7
npm-react-codemod/react-codemod
Executable 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 $@
|
||||
39
npm-react-codemod/test/__tests__/transform-tests.js
Normal file
39
npm-react-codemod/test/__tests__/transform-tests.js
Normal 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', () => {
|
||||
|
||||
|
||||
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user