-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve codemod templates (#7585)
- Loading branch information
1 parent
5ff90c2
commit f37d428
Showing
3 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/codemods/_templates/codemod-test/new/input-testfixture.ejs.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/codemods/_templates/codemod-test/new/transformer.ejs.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
to: src/transforms/v<%= version %>/<%= h.changeCase.paramCase(name) %>.ts | ||
--- | ||
import { API, FileInfo } from 'jscodeshift'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
const componentName = '<%= name %>'; | ||
export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) { | ||
const { alias } = options; | ||
const j = api.jscodeshift; | ||
const source = j(file.source); | ||
const { localName } = getImportInfo(j, file, componentName, alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
return source.toSource(); | ||
} |