Add cli to run transforms using the codemods package (#2189)
* Build cli for codemod package * Make the thing actually work * Change files * Update readme * Update ignore path * Fix cli * Include new codemod * consistent slashes * Fix depcheck * Remove unnecessary change file * Add exe bit
This commit is contained in:
Родитель
b165a81f18
Коммит
82b813327d
|
@ -1,2 +1,2 @@
|
|||
#Ignore transforms test output files
|
||||
**/src/__testfixtures__/*.output.tsx
|
||||
**/__testfixtures__/*.output.tsx
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"type": "minor",
|
||||
"comment": "Build cli for codemod package",
|
||||
"packageName": "@fluentui-react-native/codemods",
|
||||
"email": "ruaraki@microsoft.com",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"type": "patch",
|
||||
"comment": "additional of isMobile utils",
|
||||
"packageName": "@fluentui-react-native/platform-utils",
|
||||
"email": "rohanpd.work@gmail.com",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
|
@ -8,13 +8,13 @@ This package supplies transforms that help with refactoring FURN code. The trans
|
|||
2. Run the transforms using the following command:
|
||||
|
||||
```cli
|
||||
jscodeshift -t <path to transform file> --parser=tsx --extensions=tsx <path to file to be transformed>
|
||||
npx -p @fluentui-react-native/codemods transform -t <transform_name> --path <path_to_files_to_transform>
|
||||
```
|
||||
|
||||
For example
|
||||
|
||||
```cli
|
||||
jscodeshift -t transforms/src/button-v0-to-v1.ts --parser=tsx --extensions=tsx apps/fluent-tester/src/TestComponents/Button/deprecated
|
||||
npx -p @fluentui-react-native/codemods transform -t button-v0-to-v1 --path .\apps\fluent-tester\src\TestComponents\Button\deprecated\ButtonFocusTest.tsx
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
|
|
@ -8,7 +8,11 @@
|
|||
"main": "src/index.ts",
|
||||
"module": "src/index.ts",
|
||||
"typings": "lib/index.d.ts",
|
||||
"bin": {
|
||||
"transform": "./transform.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "fluentui-scripts build",
|
||||
"just": "fluentui-scripts",
|
||||
"clean": "fluentui-scripts clean",
|
||||
"depcheck": "fluentui-scripts depcheck",
|
||||
|
@ -22,16 +26,22 @@
|
|||
"url": "https://github.com/microsoft/fluentui-react-native.git",
|
||||
"directory": "packages/codemods"
|
||||
},
|
||||
"dependencies": {
|
||||
"jscodeshift": "^0.13.1",
|
||||
"yargs": "^17.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fluentui-react-native/eslint-config-rules": "^0.1.1",
|
||||
"@fluentui-react-native/scripts": "^0.1.1",
|
||||
"@fluentui-react-native/test-tools": ">=0.1.1 <1.0.0",
|
||||
"@types/jscodeshift": "^0.11.5",
|
||||
"jscodeshift": "^0.13.1"
|
||||
"@types/jscodeshift": "^0.11.5"
|
||||
},
|
||||
"depcheck": {
|
||||
"ignoreMatches": [
|
||||
".bin"
|
||||
],
|
||||
"ignorePatterns": [
|
||||
"src/__testfixtures__/*"
|
||||
"src/transforms/__testfixtures__/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import { transform, yargsParse } from './transform';
|
||||
|
||||
transform(yargsParse(process.argv));
|
|
@ -0,0 +1,42 @@
|
|||
import path from 'path';
|
||||
import yargs from 'yargs';
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
const transformerDirectory = path.join(__dirname, 'transforms');
|
||||
const jscodeshiftExecutable = require.resolve('.bin/jscodeshift');
|
||||
|
||||
interface argsType {
|
||||
path: string;
|
||||
transform: string;
|
||||
}
|
||||
|
||||
export const yargsParse = (args: string[]): argsType => {
|
||||
return yargs([])
|
||||
.help()
|
||||
.exitProcess(false)
|
||||
.option('path', {
|
||||
alias: 'p',
|
||||
type: 'string',
|
||||
description: 'Path that transform should be run over',
|
||||
normalize: true,
|
||||
})
|
||||
.option('transform', {
|
||||
alias: 't',
|
||||
type: 'string',
|
||||
description: 'Name of transform to run',
|
||||
choices: ['button-v0-to-v1', 'deprecate-exports'],
|
||||
})
|
||||
.demandOption(['path', 'transform'])
|
||||
.parse(args);
|
||||
};
|
||||
|
||||
export const transform = (args: argsType) => {
|
||||
const codeshiftArgs = [];
|
||||
|
||||
codeshiftArgs.push('-t', path.join(transformerDirectory, args.transform + '.js'));
|
||||
codeshiftArgs.push('--parser=tsx');
|
||||
codeshiftArgs.push('--extensions=tsx');
|
||||
codeshiftArgs.push(args.path);
|
||||
|
||||
execSync(jscodeshiftExecutable + ' ' + codeshiftArgs.join(' '));
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
require('./lib-commonjs/index');
|
|
@ -5,5 +5,5 @@
|
|||
"types": ["node", "jest"]
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["src/__testfixtures__"]
|
||||
"exclude": ["src/transforms/__testfixtures__"]
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче