Skip to content

Commit

Permalink
fix: avoid removing multiple dependencies when multiple classes match…
Browse files Browse the repository at this point in the history
… at the end of the name (#35)

fix: update removeSpecificFileLines method

Remove lines only for the exact class, not for all the similar classes
which matches the target class.

For example, this avoid to delete SmartErrorDialog and ErrorDialog on
the same execution because both classes ended with ErrorDialog.
  • Loading branch information
ferrarafer authored Jul 18, 2023
1 parent 650d8b8 commit 4b0665a
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 171 deletions.
6 changes: 3 additions & 3 deletions lib/src/services/file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ class FileService {
);
}
List<String> fileLines = await readFileAsLines(filePath: filePath);
fileLines.removeWhere((line) => line.contains(recaseName.snakeCase));
fileLines.removeWhere((line) => line.contains(recaseName.pascalCase));
fileLines.removeWhere((line) => line.contains('/${recaseName.snakeCase}'));
fileLines.removeWhere((line) => line.contains(' ${recaseName.pascalCase}'));
await writeStringFile(
file: File(filePath),
fileContent: fileLines.join('\n'),
type: FileModificationType.Modify,
verbose: true,
verboseMessage: "Removed ${recaseName.pascalCase}$type from $filePath",
verboseMessage: "Removed ${recaseName.pascalCase} from $filePath",
);
}

Expand Down
121 changes: 73 additions & 48 deletions lib/src/templates/compiled_template_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,21 @@ Map<String, Map<String, StackedTemplate>> kCompiledStackedTemplates = {
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-dialog',
modificationTemplate: '''StackedDialog(classType: {{dialogName}}),''',
modificationProblemError: 'The dialog registration should be stored in lib/app/app.dart',
modificationName: 'Add \'{{dialogName}}\' dependency to StackedApp annotations file',
modificationProblemError:
'The dialog registration should be stored in lib/app/app.dart',
modificationName:
'Add \'{{dialogName}}\' dependency to StackedApp annotations file',
),

ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-import',
modificationTemplate: '''import \'package:{{packageName}}/{{{dialogsPath}}}/{{dialogFolderName}}/{{dialogFilename}}\';''',
modificationProblemError: 'The dialog registration should be stored in lib/app/app.dart',
modificationTemplate:
'''import \'package:{{packageName}}/{{{dialogsPath}}}/{{dialogFolderName}}/{{dialogFilename}}\';''',
modificationProblemError:
'The dialog registration should be stored in lib/app/app.dart',
modificationName: 'Add import for \'{{dialogName}}\' class',
),
],
],
),
},
'view': {
Expand Down Expand Up @@ -347,18 +350,22 @@ Map<String, Map<String, StackedTemplate>> kCompiledStackedTemplates = {
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-route',
modificationTemplate: '''MaterialRoute(page: {{viewName}}),''',
modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName: 'Add {{viewName}} route where @StackedApp annotation is located',
modificationProblemError:
'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName:
'Add {{viewName}} route where @StackedApp annotation is located',
),

ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-import',
modificationTemplate: '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''',
modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName: 'Add {{viewName}} route import where @StackedApp annotation is located',
modificationTemplate:
'''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''',
modificationProblemError:
'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName:
'Add {{viewName}} route import where @StackedApp annotation is located',
),
],
],
),
'web': StackedTemplate(
templateFiles: [
Expand Down Expand Up @@ -392,18 +399,22 @@ Map<String, Map<String, StackedTemplate>> kCompiledStackedTemplates = {
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-route',
modificationTemplate: '''CustomRoute(page: {{viewName}}),''',
modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName: 'Add {{viewName}} route where @StackedApp annotation is located',
modificationProblemError:
'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName:
'Add {{viewName}} route where @StackedApp annotation is located',
),

ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-import',
modificationTemplate: '''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''',
modificationProblemError: 'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName: 'Add {{viewName}} route import where @StackedApp annotation is located',
modificationTemplate:
'''import \'package:{{packageName}}/{{{viewImportPath}}}/{{viewFolderName}}/{{viewFileName}}\';''',
modificationProblemError:
'The structure of your stacked application is invalid. The app.dart file should be located in lib/app/',
modificationName:
'Add {{viewName}} route import where @StackedApp annotation is located',
),
],
],
),
},
'service': {
Expand All @@ -422,71 +433,81 @@ Map<String, Map<String, StackedTemplate>> kCompiledStackedTemplates = {
ModificationFile(
relativeModificationPath: 'test/helpers/test_helpers.dart',
modificationIdentifier: '// @stacked-mock-create',
modificationTemplate: '''Mock{{serviceName}} getAndRegister{{serviceName}}() {
modificationTemplate:
'''Mock{{serviceName}} getAndRegister{{serviceName}}() {
_removeRegistrationIfExists<{{serviceName}}>();
final service = Mock{{serviceName}}();
{{locatorName}}.registerSingleton<{{serviceName}}>(service);
return service;
}''',
modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart',
modificationProblemError:
'The test mocks and helpers should be stored in test/helpers/test_helpers.dart',
modificationName: 'Add {{serviceName}} mock to test helpers',
),

ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-service',
modificationTemplate: '''LazySingleton(classType: {{serviceName}}),''',
modificationProblemError: 'The service registration should be stored in lib/app/app.dart',
modificationName: 'Add {{serviceName}} dependency to StackedApp annotations file',
modificationTemplate:
'''LazySingleton(classType: {{serviceName}}),''',
modificationProblemError:
'The service registration should be stored in lib/app/app.dart',
modificationName:
'Add {{serviceName}} dependency to StackedApp annotations file',
),

ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-import',
modificationTemplate: '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''',
modificationProblemError: 'The service registration should be stored in lib/app/app.dart',
modificationName: 'Add {{serviceName}} import to StackedApp annotations file',
modificationTemplate:
'''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''',
modificationProblemError:
'The service registration should be stored in lib/app/app.dart',
modificationName:
'Add {{serviceName}} import to StackedApp annotations file',
),

ModificationFile(
relativeModificationPath: 'test/helpers/test_helpers.dart',
modificationIdentifier: '// @stacked-mock-spec',
modificationTemplate: '''MockSpec<{{serviceName}}>(onMissingStub: OnMissingStub.returnDefault),''',
modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart',
modificationTemplate:
'''MockSpec<{{serviceName}}>(onMissingStub: OnMissingStub.returnDefault),''',
modificationProblemError:
'The test mocks and helpers should be stored in test/helpers/test_helpers.dart',
modificationName: 'Create {{serviceName}} mock to test helpers',
),

ModificationFile(
relativeModificationPath: 'test/helpers/test_helpers.dart',
modificationIdentifier: '// @stacked-mock-register',
modificationTemplate: '''getAndRegister{{serviceName}}();''',
modificationProblemError: 'The test mocks and helpers should be stored in test/helpers/test_helpers.dart',
modificationProblemError:
'The test mocks and helpers should be stored in test/helpers/test_helpers.dart',
modificationName: 'Add {{serviceName}} register to test helpers',
),

ModificationFile(
relativeModificationPath: 'test/helpers/test_helpers.dart',
modificationIdentifier: '// @stacked-import',
modificationTemplate: '''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''',
modificationProblemError: 'It seems your test_helpers.dart file is not in test/helpers/test_helpers.dart. Add a stacked.json file and set the path for \'test_helpers_path\' to the folder we can locate your test_helpers.dart file',
modificationTemplate:
'''import \'package:{{packageName}}/{{{serviceImportPath}}}/{{serviceFilename}}\';''',
modificationProblemError:
'It seems your test_helpers.dart file is not in test/helpers/test_helpers.dart. Add a stacked.json file and set the path for \'test_helpers_path\' to the folder we can locate your test_helpers.dart file',
modificationName: 'Add {{serviceName}} import to test helpers',
),
],
],
),
},
'bottom_sheet': {
'empty': StackedTemplate(
templateFiles: [
TemplateFile(
relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetModelTestPath,
relativeOutputPath:
kBottomSheetEmptyTemplateGenericSheetModelTestPath,
content: kBottomSheetEmptyTemplateGenericSheetModelTestContent,
fileType: FileType.text),
TemplateFile(
relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetModelPath,
content: kBottomSheetEmptyTemplateGenericSheetModelContent,
fileType: FileType.text),
TemplateFile(
relativeOutputPath: kBottomSheetEmptyTemplateGenericSheetUseModelPath,
relativeOutputPath:
kBottomSheetEmptyTemplateGenericSheetUseModelPath,
content: kBottomSheetEmptyTemplateGenericSheetUseModelContent,
fileType: FileType.text),
TemplateFile(
Expand All @@ -498,19 +519,23 @@ return service;
ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-bottom-sheet',
modificationTemplate: '''StackedBottomsheet(classType: {{sheetName}}),''',
modificationProblemError: 'The bottom sheet registration should be stored in lib/app/app.dart',
modificationName: 'Add \'{{sheetName}}\' dependency to StackedApp annotations file',
modificationTemplate:
'''StackedBottomsheet(classType: {{sheetName}}),''',
modificationProblemError:
'The bottom sheet registration should be stored in lib/app/app.dart',
modificationName:
'Add \'{{sheetName}}\' dependency to StackedApp annotations file',
),

ModificationFile(
relativeModificationPath: 'lib/app/app.dart',
modificationIdentifier: '// @stacked-import',
modificationTemplate: '''import \'package:{{packageName}}/{{{bottomSheetsPath}}}/{{sheetFolderName}}/{{sheetFilename}}\';''',
modificationProblemError: 'The bottom sheet registration should be stored in lib/app/app.dart',
modificationTemplate:
'''import \'package:{{packageName}}/{{{bottomSheetsPath}}}/{{sheetFolderName}}/{{sheetFilename}}\';''',
modificationProblemError:
'The bottom sheet registration should be stored in lib/app/app.dart',
modificationName: 'Add import for \'{{sheetName}}\' class',
),
],
],
),
},
};
Loading

0 comments on commit 4b0665a

Please sign in to comment.