Skip to content

Commit

Permalink
feat: improve codemod templates (#7585)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackySoul authored Sep 16, 2024
1 parent 5ff90c2 commit f37d428
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
to: src/transforms/__testfixtures__/<%= name %>/basic.input.tsx
to: src/transforms/v<%= version %>/__testfixtures__/<%= h.changeCase.paramCase(name) %>/basic.input.tsx
---
import { } from '@vkontakte/vkui';
import React from 'react';
Expand Down
6 changes: 3 additions & 3 deletions packages/codemods/_templates/codemod-test/new/test.ejs.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
to: src/transforms/__tests__/<%= name %>.ts
to: src/transforms/v<%= version %>/__tests__/<%= h.changeCase.paramCase(name) %>.ts
---
jest.autoMockOff();

import { defineSnapshotTestFromFixture } from '../../testHelpers/testHelper';
import { defineSnapshotTestFromFixture } from '../../../testHelpers/testHelper';

const name = '<%= name %>';
const name = '<%= h.changeCase.paramCase(name) %>';
const fixtures = ['basic'] as const;

describe(name, () => {
Expand Down
22 changes: 22 additions & 0 deletions packages/codemods/_templates/codemod-test/new/transformer.ejs.t
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();
}

0 comments on commit f37d428

Please sign in to comment.