Open AliEl-Zayat opened 7 months ago
d8f9057ac2
)[!TIP] I can email you next time I complete a pull request if you set up your email here!
Here are the GitHub Actions logs prior to making any changes:
ab8d02d
Checking src/extension.ts for syntax errors... ✅ src/extension.ts has no syntax errors!
1/1 ✓Checking src/extension.ts for syntax errors... ✅ src/extension.ts has no syntax errors!
Sandbox passed on the latest main
, so sandbox checks will be enabled for this issue.
I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.
src/utils/FileSystemUtils.ts
✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/e85714d2362d2de85befe1123eedfa8813dae077 Edit
Create src/utils/FileSystemUtils.ts with contents:
• Create a new utility class `FileSystemUtils` in `src/utils/FileSystemUtils.ts`.
• This class will abstract away the file system operations from `extension.ts`, making the code more modular and easier to test.
• Implement methods such as `createDirectory`, `appendToFile`, and `createFileWithContent` that wrap the `fs` operations used in `extension.ts`.
• Import `fs` from "fs/promises" at the top of the file.
src/utils/FileSystemUtils.ts
✓ Edit
Check src/utils/FileSystemUtils.ts with contents:
Ran GitHub Actions for e85714d2362d2de85befe1123eedfa8813dae077:
src/utils/VSCodeUtils.ts
✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/25af428a8f4b155bba44f65e124b25a44b6ba9ab Edit
Create src/utils/VSCodeUtils.ts with contents:
• Create a new utility class `VSCodeUtils` in `src/utils/VSCodeUtils.ts`.
• This class will abstract VS Code API calls, making `extension.ts` less tightly coupled to the VS Code API.
• Implement methods to get workspace configuration values, show information messages, and show error messages.
• Import necessary entities from `vscode` at the top of the file.
src/utils/VSCodeUtils.ts
✓ Edit
Check src/utils/VSCodeUtils.ts with contents:
Ran GitHub Actions for 25af428a8f4b155bba44f65e124b25a44b6ba9ab:
src/templates/ComponentTemplateGenerator.ts
✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/1627a02777cd903af947ce8816f0482ecd629970 Edit
Create src/templates/ComponentTemplateGenerator.ts with contents:
• Create a new class `ComponentTemplateGenerator` in `src/templates/ComponentTemplateGenerator.ts`.
• This class will handle the generation of component templates, making `nativeComponentTemplate.ts` more modular and extensible.
• Implement methods for generating each part of the component template (e.g., component body, styles, index file content).
• Import necessary templates and utilities as needed.
src/templates/ComponentTemplateGenerator.ts
✓ Edit
Check src/templates/ComponentTemplateGenerator.ts with contents:
Ran GitHub Actions for 1627a02777cd903af947ce8816f0482ecd629970:
src/extension.ts
✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/ece3ed7c6aedab837d3f811da0a22b1c85dbc3a3 Edit
Modify src/extension.ts with contents:
• Refactor the `activate` function to use the new `FileSystemUtils` and `VSCodeUtils` classes for file system operations and VS Code API calls, respectively.
• Replace direct `fs` and `vscode` API calls with calls to the methods of `FileSystemUtils` and `VSCodeUtils`.
• This will make the `activate` function more focused on the extension logic rather than the details of file system operations and VS Code API interactions.
--- +++ @@ -59,25 +59,15 @@ context.subscriptions.push( vscode.commands.registerCommand("zayat-utilities.createScreen", () => { - vscode.window - .showInputBox({ - placeHolder: "Enter Screen Name", - prompt: "Enter Screen Name", - value: "", - }) - .then((value) => action(typeof value === "string" ? value : "", true)); + VSCodeUtils.showInputBox("Enter Screen Name", "Enter Screen Name", "") + .then((value) => action(value, true)); }) ); context.subscriptions.push( vscode.commands.registerCommand("zayat-utilities.createComponent", () => { - vscode.window - .showInputBox({ - placeHolder: "Enter component Name", - prompt: "Enter component Name", - value: "", - }) - .then((value) => action(typeof value === "string" ? value : "", false)); + VSCodeUtils.showInputBox("Enter component Name", "Enter component Name", "") + .then((value) => action(value, false)); }) ); }
src/extension.ts
✓ Edit
Check src/extension.ts with contents:
Ran GitHub Actions for ece3ed7c6aedab837d3f811da0a22b1c85dbc3a3:
src/nativeComponentTemplate.ts
✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/859c68e1926694e8454298ac6989339212767175 Edit
Modify src/nativeComponentTemplate.ts with contents:
• Refactor the file to use the new `ComponentTemplateGenerator` class.
• Replace the `nativeComponentTemplate`, `nativeStylesTemplate`, and `nativeIndexTemplate` functions with calls to the corresponding methods of `ComponentTemplateGenerator`.
• This will make adding new templates or modifying existing ones easier and more organized.
--- +++ @@ -1,51 +1,13 @@ -export const nativeComponentTemplate = ( - componentName: string, - isTS = false, - isScreen = false -) => { - const screenOrComponentImport = isScreen - ? "import { SafeAreaView } from 'react-native-safe-area-context';" - : "import { View } from 'react-native'"; - const screenOrComponentReturn = isScreen - ? `- ` - : `- `; +import { ComponentTemplateGenerator } from './templates/ComponentTemplateGenerator'; - const constantToReturn = isTS - ? `type T${componentName}Props = {}; - -const ${componentName} = ({}:T${componentName}Props) => {` - : `const ${componentName} = ({}) => {`; - - return `import React from 'react'; -${screenOrComponentImport} - -import getStyles from './${componentName}.styles'; - -${constantToReturn} - const styles = getStyles(); - return ( -${screenOrComponentReturn} - ); -}; - -export default ${componentName}; -`; -}; - -export const nativeStylesTemplate = (isScreen = false) => { - return `import { StyleSheet } from 'react-native'; - -export default function getStyles() { - return StyleSheet.create({ - container: {${isScreen ? "\n flex: 1," : ""} - }, - }); -} -`; +export const nativeComponentTemplate = (componentName: string, isTS = false, isScreen = false) => { + const generator = new ComponentTemplateGenerator(componentName, isTS, isScreen); + return generator.generateComponentBody(); + const generator = new ComponentTemplateGenerator('', false, isScreen); + return generator.generateStyles(); }; export const nativeIndexTemplate = (componentName: string) => { - return `export { default } from './${componentName}';\n`; + const generator = new ComponentTemplateGenerator(componentName, false, false); + return generator.generateIndexFileContent(); };
src/nativeComponentTemplate.ts
✓ Edit
Check src/nativeComponentTemplate.ts with contents:
Ran GitHub Actions for 859c68e1926694e8454298ac6989339212767175:
I have finished reviewing the code for completeness. I did not find errors for sweep/improve_the_code_readability_and_solidit
.
💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.
This is an automated message generated by Sweep AI.
Something went wrong in generateStyles and generateIndex
Details
refactor the extension.ts and nativeComponentTemplate.ts to be more SOLID and more readable and more scalable and more maintainable
Checklist
- [X] Create `src/utils/FileSystemUtils.ts` ✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/e85714d2362d2de85befe1123eedfa8813dae077 [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/utils/FileSystemUtils.ts) - [X] Running GitHub Actions for `src/utils/FileSystemUtils.ts` ✓ [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/utils/FileSystemUtils.ts) - [X] Create `src/utils/VSCodeUtils.ts` ✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/25af428a8f4b155bba44f65e124b25a44b6ba9ab [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/utils/VSCodeUtils.ts) - [X] Running GitHub Actions for `src/utils/VSCodeUtils.ts` ✓ [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/utils/VSCodeUtils.ts) - [X] Create `src/templates/ComponentTemplateGenerator.ts` ✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/1627a02777cd903af947ce8816f0482ecd629970 [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/templates/ComponentTemplateGenerator.ts) - [X] Running GitHub Actions for `src/templates/ComponentTemplateGenerator.ts` ✓ [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/templates/ComponentTemplateGenerator.ts) - [X] Modify `src/extension.ts` ✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/ece3ed7c6aedab837d3f811da0a22b1c85dbc3a3 [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/extension.ts) - [X] Running GitHub Actions for `src/extension.ts` ✓ [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/extension.ts) - [X] Modify `src/nativeComponentTemplate.ts` ✓ https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/commit/859c68e1926694e8454298ac6989339212767175 [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/nativeComponentTemplate.ts) - [X] Running GitHub Actions for `src/nativeComponentTemplate.ts` ✓ [Edit](https://github.com/AliEl-Zayat/zayat-utils-vsce-extension/edit/sweep/improve_the_code_readability_and_solidit/src/nativeComponentTemplate.ts)