diff --git a/lib/src/commands/create/create.dart b/lib/src/commands/create/create.dart index 53cad14b5..ce08afa44 100644 --- a/lib/src/commands/create/create.dart +++ b/lib/src/commands/create/create.dart @@ -151,20 +151,22 @@ class CreateCommand extends Command { final windows = _argResults['windows'] as String? ?? 'true'; final executableName = _argResults['executable-name'] as String? ?? projectName; + var vars = { + 'project_name': projectName, + 'description': description, + 'executable_name': executableName, + 'org_name': orgName, + 'android': android.toBool(), + 'ios': ios.toBool(), + 'web': web.toBool(), + 'linux': linux.toBool(), + 'macos': macos.toBool(), + 'windows': windows.toBool(), + }; + await generator.hooks.preGen(vars: vars, onVarsChanged: (v) => vars = v); final files = await generator.generate( DirectoryGeneratorTarget(outputDirectory), - vars: { - 'project_name': projectName, - 'description': description, - 'executable_name': executableName, - 'org_name': orgName, - 'android': android.toBool(), - 'ios': ios.toBool(), - 'web': web.toBool(), - 'linux': linux.toBool(), - 'macos': macos.toBool(), - 'windows': windows.toBool(), - }, + vars: vars, logger: _logger, ); generateProgress.complete('Generated ${files.length} file(s)'); diff --git a/test/src/commands/create/create_test.dart b/test/src/commands/create/create_test.dart index d4dd42662..13a625e05 100644 --- a/test/src/commands/create/create_test.dart +++ b/test/src/commands/create/create_test.dart @@ -68,6 +68,8 @@ class MockPubUpdater extends Mock implements PubUpdater {} class MockMasonGenerator extends Mock implements MasonGenerator {} +class MockGeneratorHooks extends Mock implements GeneratorHooks {} + class FakeDirectoryGeneratorTarget extends Fake implements DirectoryGeneratorTarget {} @@ -179,6 +181,7 @@ void main() { test('completes successfully with correct output', () async { final argResults = MockArgResults(); + final hooks = MockGeneratorHooks(); final generator = MockMasonGenerator(); final command = CreateCommand( analytics: analytics, @@ -189,6 +192,13 @@ void main() { when(() => argResults.rest).thenReturn(['.tmp']); when(() => generator.id).thenReturn('generator_id'); when(() => generator.description).thenReturn('generator description'); + when(() => generator.hooks).thenReturn(hooks); + when( + () => hooks.preGen( + vars: any(named: 'vars'), + onVarsChanged: any(named: 'onVarsChanged'), + ), + ).thenAnswer((_) async {}); when( () => generator.generate( any(), @@ -248,6 +258,7 @@ void main() { test('completes successfully w/ custom description', () async { final argResults = MockArgResults(); + final hooks = MockGeneratorHooks(); final generator = MockMasonGenerator(); final command = CreateCommand( analytics: analytics, @@ -261,6 +272,13 @@ void main() { when(() => argResults.rest).thenReturn(['.tmp']); when(() => generator.id).thenReturn('generator_id'); when(() => generator.description).thenReturn('generator description'); + when(() => generator.hooks).thenReturn(hooks); + when( + () => hooks.preGen( + vars: any(named: 'vars'), + onVarsChanged: any(named: 'onVarsChanged'), + ), + ).thenAnswer((_) async {}); when( () => generator.generate( any(), @@ -391,6 +409,7 @@ void main() { group('valid --org-name', () { Future expectValidOrgName(String orgName) async { final argResults = MockArgResults(); + final hooks = MockGeneratorHooks(); final generator = MockMasonGenerator(); final command = CreateCommand( analytics: analytics, @@ -404,6 +423,13 @@ void main() { when(() => argResults.rest).thenReturn(['.tmp']); when(() => generator.id).thenReturn('generator_id'); when(() => generator.description).thenReturn('generator description'); + when(() => generator.hooks).thenReturn(hooks); + when( + () => hooks.preGen( + vars: any(named: 'vars'), + onVarsChanged: any(named: 'onVarsChanged'), + ), + ).thenAnswer((_) async {}); when( () => generator.generate( any(), @@ -493,6 +519,7 @@ void main() { required String expectedLogSummary, }) async { final argResults = MockArgResults(); + final hooks = MockGeneratorHooks(); final generator = MockMasonGenerator(); final command = CreateCommand( analytics: analytics, @@ -511,6 +538,13 @@ void main() { when(() => argResults.rest).thenReturn(['.tmp']); when(() => generator.id).thenReturn('generator_id'); when(() => generator.description).thenReturn('generator description'); + when(() => generator.hooks).thenReturn(hooks); + when( + () => hooks.preGen( + vars: any(named: 'vars'), + onVarsChanged: any(named: 'onVarsChanged'), + ), + ).thenAnswer((_) async {}); when( () => generator.generate( any(),