Skip to content
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
26 changes: 14 additions & 12 deletions lib/src/commands/create/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,22 @@ class CreateCommand extends Command<int> {
final windows = _argResults['windows'] as String? ?? 'true';
final executableName =
_argResults['executable-name'] as String? ?? projectName;
var vars = <String, dynamic>{
'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: <String, dynamic>{
'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)');
Expand Down
34 changes: 34 additions & 0 deletions test/src/commands/create/create_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -391,6 +409,7 @@ void main() {
group('valid --org-name', () {
Future<void> expectValidOrgName(String orgName) async {
final argResults = MockArgResults();
final hooks = MockGeneratorHooks();
final generator = MockMasonGenerator();
final command = CreateCommand(
analytics: analytics,
Expand All @@ -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(),
Expand Down Expand Up @@ -493,6 +519,7 @@ void main() {
required String expectedLogSummary,
}) async {
final argResults = MockArgResults();
final hooks = MockGeneratorHooks();
final generator = MockMasonGenerator();
final command = CreateCommand(
analytics: analytics,
Expand All @@ -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(),
Expand Down