// Copyright (C) 2023 WYATT GROUP // Please see the AUTHORS file for details. // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . import 'dart:io'; import 'package:mason/mason.dart'; void removeGitKeepFiles(String targetPath) { if (!FileSystemEntity.isDirectorySync(targetPath)) { throw ArgumentError('Target must be a directory', 'targetPath'); } Directory(targetPath) .listSync(recursive: true) .whereType() .forEach((file) { if (file.path.contains('.gitkeep')) { file.deleteSync(recursive: true); } }); } Future run(HookContext context) async { final workingDirectory = Directory.current.path; /// Remove .gitkeep files print('Removing .gitkeep files'); removeGitKeepFiles(workingDirectory); /// dart pub get print('Running `dart pub get`'); await Process.run('dart', ['pub', 'get'], runInShell: true); /// dart format . --fix && dart fix . --apply print('Running `dart format . --fix && dart fix . --apply`'); await Process.run('dart', ['format', '.', '--fix'], runInShell: true); await Process.run('dart', ['fix', '.', '--apply'], runInShell: true); final bundleId = context.vars['bundle_id'] as String?; final appName = bundleId?.split('.').last; final org = bundleId?.replaceAll('.$appName', ''); /// flutter create --platforms android,ios --org com.example --project-name example . print( 'Running `flutter create --platforms android,ios --org $org --project-name $appName .`'); await Process.run( 'flutter', [ 'create', '--platforms', 'android,ios', '--org', org ?? 'com.example', '--project-name', appName ?? 'example', '.' ], runInShell: true); }