https://github.com/apptools-lab/codemod
🐒 AppWorks codemod scripts
https://github.com/apptools-lab/codemod
codemod codemods
Last synced: 3 months ago
JSON representation
🐒 AppWorks codemod scripts
- Host: GitHub
- URL: https://github.com/apptools-lab/codemod
- Owner: apptools-lab
- Created: 2021-06-16T08:30:02.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-09-08T04:05:26.000Z (almost 4 years ago)
- Last Synced: 2025-02-13T07:37:32.608Z (4 months ago)
- Topics: codemod, codemods
- Language: JavaScript
- Homepage:
- Size: 34.2 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# @appworks/codemod
AppWorks codemod scripts for [rax](https://rax.js.org/), [ice](https://ice.work/) and react project.
## Install
```bash
$ npm i @appworks/codemod -g
```## Usage
### 1. CLI
```bash
$ appworks-codemod [...options?]
```- `transform` - name of transform, see available transforms below.
- `path` - files or directory to transform.
- `options?` - option for [jscodeshift](https://www.npmjs.com/package/jscodeshift).Example:
```bash
$ appworks-codemod plugin-rax-component-to-component ./
```### 2. API
#### Check()
You can retrieve the recommended codemod of the current project through the `check` method.
Options:
- directory: string, the target directory path
- files: string[], the target directory files path arrayReturn:
- results: IResult[] (see interface), the target project recommended codemod info array.
Example:
```javascript
import glob from "glob";
import { check } from "@appworks/codemod";const dir = "/xxx/xx";
glob(
"**/*",
{ cwd: dir, ignore: ["**/node_modules/**"], nodir: true, realpath: true },
function (er, files) {
check(dir, files).then((results) => {
console.log(results);
});
}
);
```#### Run()
You can use the `run` method to execute specific codemod.
Options:
- directory: string, the target directory path
- files: string[], the target directory files path array
- transform: string, the name of transform, see available transforms below.Return:
- result: IResult (see interface), run codemod result.
Example:
```javascript
import glob from "glob";
import { check } from "@appworks/codemod";const dir = "/xxx/xx";
glob(
"**/*",
{ cwd: dir, ignore: ["**/node_modules/**"], nodir: true, realpath: true },
function (er, files) {
run(dir, files, "plugin-rax-component-to-component").then((result) => {
console.log(result);
});
}
);
```#### Interface
IResult:
```typescript
interface IResult {
transform: string; // transform key, see `Included Transforms`
title: string; // transform description title
title_en: string;
message: string; // transform description message
message_en: string;
severity: 0 | 1 | 2; // 0: advice 1: warning 2: error
mode: "run" | "check"; // mode, see API
docs: string; // docs url
output: string; // jscodeshift CLI output
npm_deprecate?: string; // same as https://docs.npmjs.com/cli/v7/commands/npm-deprecate/
}
```## Included Transforms
### 1. `plugin-rax-component-to-component`
Update `plugin-rax-component` to `plugin-component`. [docs](./transforms/docs/plugin-rax-component-to-component.md)
### 2. `lint-config-to-spec`
Follow Alibaba FED lint rules, and use `@iceworks/spec` best practices. [docs](./transforms/docs/lint-config-to-spec.md)