Skip to content

Commit

Permalink
chore: add empty buton codemod (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
valerybugakov authored Oct 12, 2021
1 parent 989c3f2 commit f8a6aca
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
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)
}
1 change: 1 addition & 0 deletions src/transforms/buttonElementToComponent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './buttonElementToComponent'
2 changes: 2 additions & 0 deletions src/transforms/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { buttonElementToComponent } from './buttonElementToComponent'
import { classNameTemplateToClassnamesCall } from './classNameTemplateToClassnamesCall'
import { globalCssToCssModule } from './globalCssToCssModule/globalCssToCssModule'

export const transforms = {
buttonElementToComponent,
globalCssToCssModule,
classNameTemplateToClassnamesCall,
} as const
Expand Down

0 comments on commit f8a6aca

Please sign in to comment.