refactor: use lambda shorthand syntax (#16)

This commit is contained in:
Felix Angelov 2022-04-11 14:15:08 -05:00 committed by GitHub
parent 61db82ebbb
commit 5baf0dfa61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 31 deletions

View File

@ -3,7 +3,7 @@ description: A very good federated Flutter plugin.
version: 0.1.0+1 version: 0.1.0+1
environment: environment:
mason: ">=0.1.0-dev <0.1.0" mason: ">=0.1.0-dev.15 <0.1.0"
vars: vars:
project_name: project_name:

View File

@ -15,8 +15,8 @@ final _sourceMyPluginKtPath = path.join(
); );
final _targetMyPluginKtPath = path.join( final _targetMyPluginKtPath = path.join(
_androidKotlinPath, _androidKotlinPath,
'{{#pathCase}}{{org_name}}{{/pathCase}}', '{{org_name.pathCase()}}',
'{{#pascalCase}}{{project_name}}{{/pascalCase}}Plugin.kt', '{{project_name.pascalCase()}}Plugin.kt',
); );
final year = DateTime.now().year; final year = DateTime.now().year;
final copyrightHeader = ''' final copyrightHeader = '''
@ -80,26 +80,11 @@ void main() async {
file.isAsset() ? await file.readAsBytes() : await file.readAsString(); file.isAsset() ? await file.readAsBytes() : await file.readAsString();
final templatedContents = (contents is String) final templatedContents = (contents is String)
? contents ? contents
.replaceAll( .replaceAll('com.example.my_plugin', '{{org_name.dotCase()}}')
'com.example.my_plugin', .replaceAll('my_plugin', '{{project_name.snakeCase()}}')
'{{#dotCase}}{{org_name}}{{/dotCase}}', .replaceAll('my-plugin', '{{project_name.paramCase()}}')
) .replaceAll('MyPlugin', '{{project_name.pascalCase()}}')
.replaceAll( .replaceAll('myPlugin', '{{project_name.camelCase()}}')
'my_plugin',
'{{#snakeCase}}{{project_name}}{{/snakeCase}}',
)
.replaceAll(
'my-plugin',
'{{#paramCase}}{{project_name}}{{/paramCase}}',
)
.replaceAll(
'MyPlugin',
'{{#pascalCase}}{{project_name}}{{/pascalCase}}',
)
.replaceAll(
'myPlugin',
'{{#camelCase}}{{project_name}}{{/camelCase}}',
)
.replaceAll( .replaceAll(
'A very good Flutter federated plugin', 'A very good Flutter federated plugin',
'{{{description}}}', '{{{description}}}',
@ -115,14 +100,8 @@ void main() async {
.any((e) => e.contains('my_plugin') || e.contains('MyPlugin'))) { .any((e) => e.contains('my_plugin') || e.contains('MyPlugin'))) {
final newSegments = fileSegments.map((e) { final newSegments = fileSegments.map((e) {
return e return e
.replaceAll( .replaceAll('MyPlugin', '{{project_name.pascalCase()}}')
'MyPlugin', .replaceAll('my_plugin', '{{project_name.snakeCase()}}');
'{{#pascalCase}}{{project_name}}{{/pascalCase}}',
)
.replaceAll(
'my_plugin',
'{{#snakeCase}}{{project_name}}{{/snakeCase}}',
);
}); });
final newPathSegment = newSegments.join('/'); final newPathSegment = newSegments.join('/');
final newPath = path.join(_targetPath, newPathSegment); final newPath = path.join(_targetPath, newPathSegment);