-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add empty buton codemod (#40)
- Loading branch information
1 parent
989c3f2
commit f8a6aca
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/transforms/buttonElementToComponent/buttonElementToComponent.ts
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,33 @@ | ||
import signale from 'signale' | ||
|
||
import { CodemodResult, CodemodOptions } from '../../types' | ||
import { formatWithPrettierEslint } from '../../utils' | ||
import { addClassNamesUtilImportIfNeeded } from '../../utils/classNamesUtility' | ||
|
||
/** | ||
* Convert `<button class="btn-primary" />` element to the `<Button variant="primary" />` component. | ||
*/ | ||
export async function buttonElementToComponent(options: CodemodOptions): CodemodResult { | ||
const { project, shouldWriteFiles } = options | ||
|
||
const codemodResultPromises = project.getSourceFiles().map(tsSourceFile => { | ||
const tsFilePath = tsSourceFile.getFilePath() | ||
|
||
signale.info(`Processing file "${tsFilePath}"`) | ||
|
||
/* implement transform function here */ | ||
|
||
addClassNamesUtilImportIfNeeded(tsSourceFile) | ||
formatWithPrettierEslint(tsSourceFile) | ||
|
||
return { | ||
ts: { | ||
source: tsSourceFile.getFullText(), | ||
path: tsSourceFile.getFilePath(), | ||
}, | ||
fsWritePromise: shouldWriteFiles ? Promise.all([tsSourceFile.save()]) : undefined, | ||
} | ||
}) | ||
|
||
return Promise.all(codemodResultPromises) | ||
} |
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 @@ | ||
export * from './buttonElementToComponent' |
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