File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ import signale from 'signale'
2+
3+ import { CodemodResult , CodemodOptions } from '../../types'
4+ import { formatWithPrettierEslint } from '../../utils'
5+ import { addClassNamesUtilImportIfNeeded } from '../../utils/classNamesUtility'
6+
7+ /**
8+ * Convert `<button class="btn-primary" />` element to the `<Button variant="primary" />` component.
9+ */
10+ export async function buttonElementToComponent ( options : CodemodOptions ) : CodemodResult {
11+ const { project, shouldWriteFiles } = options
12+
13+ const codemodResultPromises = project . getSourceFiles ( ) . map ( tsSourceFile => {
14+ const tsFilePath = tsSourceFile . getFilePath ( )
15+
16+ signale . info ( `Processing file "${ tsFilePath } "` )
17+
18+ /* implement transform function here */
19+
20+ addClassNamesUtilImportIfNeeded ( tsSourceFile )
21+ formatWithPrettierEslint ( tsSourceFile )
22+
23+ return {
24+ ts : {
25+ source : tsSourceFile . getFullText ( ) ,
26+ path : tsSourceFile . getFilePath ( ) ,
27+ } ,
28+ fsWritePromise : shouldWriteFiles ? Promise . all ( [ tsSourceFile . save ( ) ] ) : undefined ,
29+ }
30+ } )
31+
32+ return Promise . all ( codemodResultPromises )
33+ }
Original file line number Diff line number Diff line change 1+ export * from './buttonElementToComponent'
Original file line number Diff line number Diff line change 1+ import { buttonElementToComponent } from './buttonElementToComponent'
12import { classNameTemplateToClassnamesCall } from './classNameTemplateToClassnamesCall'
23import { globalCssToCssModule } from './globalCssToCssModule/globalCssToCssModule'
34
45export const transforms = {
6+ buttonElementToComponent,
57 globalCssToCssModule,
68 classNameTemplateToClassnamesCall,
79} as const
You can’t perform that action at this time.
0 commit comments