Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/prop types #13

Merged
merged 4 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ng2react/core",
"version": "1.6.1",
"version": "1.7.0",
"description": "Convert AngularJS 1.x components to React components",
"main": "./dist/cjs/api/main.js",
"module": "./dist/esm/api/main.js",
Expand Down
4 changes: 3 additions & 1 deletion src/assets/prompt_base.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ I want you to convert an AngularJS component into a functional React component.
- The code:
- So that I can programmatically find your code, please top and tail it with `// ___NG2R_START___`
and `// ___NG2R_END___`,
- Your code should be written in ${LANGUAGE}
- Your code should be written in ${LANGUAGE}${ADDITIONA_CODE_INSTRUCTIONS}
- Below the code:
- list any potential issues you have identified

Expand Down Expand Up @@ -49,5 +49,7 @@ const MyComponent = ({myProp, children}) => {
)
}

export default MyComponent

// ___NG2R_END___
```
12 changes: 10 additions & 2 deletions src/assets/prompt_patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ I want you to deal with certain code patterns in a specific way. Here are the pa

### Example Response:

```jsx
const StateBindingExample = ({twoWayBinding, onTwoWayBindingChange}) => {
```tsx
type Props = {
twoWayBinding: boolean
onTwoWayBindingChange: (newValue: boolean) => void
}
const StateBindingExample = ({twoWayBinding, onTwoWayBindingChange}: Props) => {
const handleTwoWayBindingChange = (e) => {
onTwoWayBindingChange(e.target.checked)
}
Expand All @@ -24,6 +28,7 @@ const StateBindingExample = ({twoWayBinding, onTwoWayBindingChange}) => {
</div>
)
}
export default StateBindingExample
```

## Pattern 2: One-way bindings / String Bindings
Expand Down Expand Up @@ -62,6 +67,7 @@ const StateBindingExample = ({oneWayBinding: initialOneWayBinding, readOnlyOneWa
</div>
)
}
export default StateBindingExample
```

## Pattern 3: Service Injection
Expand All @@ -84,6 +90,7 @@ const ServiceInjectionExample = ({}) => {

return <>...</>
}
export default ServiceInjectionExample
```

## Pattern 4: Require Controller
Expand All @@ -103,6 +110,7 @@ angular.module('myApp').component('myComponent', {
const RequireControllerExample = ({myController}) => {
return <>...</>
}
export default RequireControllerExample
```

## Any other patterns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,19 @@ export function buildGptMessage(
const [code, sourceLanguage] = buildCode('component', component, sourceRoot, template, controller)

const language = (targetLanguage ?? sourceLanguage) === 'typescript' ? 'Typescript' : 'JavaScript'
const additionalCodeInstructions =
language === 'Typescript' ? '\n - If props are used, please define the prop types' : ''

return [
{
role: 'user',
content: preparePrompt(PROMPT_BASE.replace('${LANGUAGE}', language), { language }),
content: preparePrompt(
PROMPT_BASE.replace('${LANGUAGE}', language).replace(
'${ADDITIONA_CODE_INSTRUCTIONS}',
additionalCodeInstructions
),
{ language }
),
},
{
role: 'user',
Expand Down
8 changes: 4 additions & 4 deletions src/test/openai-conversion/gpt-prompt-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ describe('Given a source file that has a JavaScript extension', () => {
expect(prompt).toContain('- Your code should be written in JavaScript')
})

it('Then the prompt should contain tsx examples', () => {
it('Then the prompt should contain tsx and jsx examples', () => {
expect(prompt).toContain('```jsx')
expect(prompt).not.toContain('```tsx')
expect(prompt).toContain('```tsx')
})
})

Expand Down Expand Up @@ -112,8 +112,8 @@ describe('Given a source file that has a Typescript extension But JavaScript was
expect(prompt).toContain('- Your code should be written in JavaScript')
})

it('Then the prompt should contain tsx examples', () => {
it('Then the prompt should contain tsx and jsx examples', () => {
expect(prompt).toContain('```jsx')
expect(prompt).not.toContain('```tsx')
expect(prompt).toContain('```tsx')
})
})
Loading