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

fix: avoid removing multiple dependencies when multiple classes match at the end of the name #35

Merged
merged 1 commit into from
Jul 18, 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
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