Skip to content
Open
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
32 changes: 32 additions & 0 deletions bin/dev_pilot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:dcli/dcli.dart' as dcli;
import 'package:dev_pilot/src/constants/app_constants.dart';
import 'package:dev_pilot/src/enums/addon.dart';
import 'package:dev_pilot/src/services/converter_service.dart';
import 'package:dev_pilot/src/services/directory_service.dart';
import 'package:dev_pilot/src/services/file_service.dart';
Expand Down Expand Up @@ -33,6 +34,7 @@ void main(List<String> arguments) async {
List<String> featureModules = <String>[];
List<String> flavors = <String>[];
bool isPackagesNeeded = false;
List<Addon> addons = <Addon>[];
final List<String> packageModules = <String>[];
final Map<String, List<String>> packages = <String, List<String>>{};

Expand Down Expand Up @@ -161,6 +163,22 @@ void main(List<String> arguments) async {
}
}

final String doIncludeAddonsAnswer = logger.chooseOne(
AppConstants.kWillYouUseAddons,
choices: <String>[
AppConstants.kYes,
AppConstants.kNo,
],
);

if (doIncludeAddonsAnswer == AppConstants.kYes) {
addons = logger.chooseAny(
AppConstants.kSpecifyAddons,
choices: Addon.values,
display: (Addon addon) => addon.displayName,
);
}

//Create project with a given name
final ProcessResult result = Process.runSync(
AppConstants.kFlutter,
Expand Down Expand Up @@ -349,6 +367,20 @@ void main(List<String> arguments) async {
destinationPath: '$path/$projectName/.gitignore',
);

//Include specified addons
final String rootProjectPath = '$path/$projectName';
final String rootProjectAbsolutePath = Directory(rootProjectPath).absolute.path;
final List<String> rootProjectPathArgs = <String>[rootProjectAbsolutePath];

for (final Addon addon in addons) {
final String workingDirectory = '$templatesPath/${AppConstants.kAddons}/${addon.remoteName}';
await ScriptService.runScript(
AppConstants.kAddonScriptName,
workingDirectory,
rootProjectPathArgs,
);
}

//Delete templates directory
await DirectoryService.deleteDirectory(
path: templatesPath,
Expand Down
13 changes: 9 additions & 4 deletions lib/src/constants/app_constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class AppConstants {
'Please enter the flavors separated by commas (dev, stage, prod etc...): ';
static const String kInvalidFlavours =
'Invalid input. Please enter only full strings separated by commas : ';
static const String kWillYouUseAddons =
'Do you want to include any addons (network provider, shared prefs setup, etc.) to this project?';
static const String kSpecifyAddons = 'Please specify addons you would like to include';

static String kAddPackages(String modulesString) {
return 'Do you want to add any packages to any of the following modules (core, core_ui, data, domain, navigation, features ${modulesString.isEmpty ? '' : <String>[
Expand Down Expand Up @@ -67,17 +70,19 @@ class AppConstants {
static const String kFeature = 'feature';
static const String kNavigation = 'navigation';
static const String kApp = 'app';
static const String kFiles = 'files';
static const String kAddons = 'addons';

static const String kFlutter = 'flutter';
static const String kCreate = 'create';
static const String kNoPub = '--no-pub';
static const String kOrg = '--org';
static const String kComExample = 'com.example';
static const String kProjectName = '--project-name';
static const String kAddonScriptName = 'script.sh';

static String kCurrentPath = Directory.current.path;
static String kTemplates = '$kCurrentPath/lib/src/templates';
static const String kFiles = 'files';
static const String kGlobalErrorHandler = 'error_handler';

static const String kFeaturePlug = 'name: plug';
Expand Down Expand Up @@ -141,7 +146,7 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyLocalization.ensureInitialized();

_setupDI(Flavor.dev);
await _setupDI(Flavor.dev);

runApp(const App());
}
Expand Down Expand Up @@ -183,9 +188,9 @@ import 'error_handler/provider/app_error_handler_provider.dart';
Future<void> _setupDI(Flavor flavor) async {
appLocator.pushNewScope(
scopeName: unauthScope,
init: (_) {
init: (_) async {
AppDI.initDependencies(appLocator, flavor);
DataDI.initDependencies(appLocator);
await DataDI.initDependencies(appLocator);
DomainDI.initDependencies(appLocator);
NavigationDI.initDependencies(appLocator);
},
Expand Down
26 changes: 26 additions & 0 deletions lib/src/enums/addon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
enum Addon {
internetObserver(
remoteName: 'connection_observer',
displayName: 'Internet observer',
),
apiProvider(
remoteName: 'api_provider',
displayName: 'HTTP provider',
),
websocketProvider(
remoteName: 'websocket_provider',
displayName: 'Websocket provider',
),
driftDatabase(
remoteName: 'drift_database',
displayName: 'Drift database',
);

final String remoteName;
final String displayName;

const Addon({
required this.remoteName,
required this.displayName,
});
}
37 changes: 18 additions & 19 deletions lib/src/services/script_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ class ScriptService {
runInShell: true,
);
if (cleanProcess.exitCode != 0) {
stdout.writeln(red(
'❌ Error running flutter clean for $modulePath: ${cleanProcess.stderr}'));
stdout.writeln(red('❌ Error running flutter clean for $modulePath: ${cleanProcess.stderr}'));
} else {
stdout
.writeln(green('✅ Successfully ran flutter clean for $modulePath'));
stdout.writeln(green('✅ Successfully ran flutter clean for $modulePath'));
}
}

Expand All @@ -41,11 +39,10 @@ class ScriptService {
runInShell: true,
);
if (pubGetProcess.exitCode != 0) {
stdout.writeln(red(
'❌ Error running flutter pub get for $modulePath : ${pubGetProcess.stderr}'));
} else {
stdout.writeln(
green('✅ Successfully ran flutter pub get for $modulePath'));
red('❌ Error running flutter pub get for $modulePath : ${pubGetProcess.stderr}'));
} else {
stdout.writeln(green('✅ Successfully ran flutter pub get for $modulePath'));
}
}

Expand Down Expand Up @@ -87,11 +84,18 @@ class ScriptService {
///
/// If the command is successful, a success message is printed to the console.
/// If the command fails, an error message is printed to the console.
static Future<void> runScript(String scriptName, String directoryPath) async {
static Future<void> runScript(
String scriptName,
String directoryPath, [
List<String>? parameters,
]) async {
final String scriptPath = '$directoryPath/$scriptName';
final ProcessResult process = await Process.run(
'sh',
<String>[scriptPath],
<String>[
scriptPath,
if (parameters != null) ...parameters,
],
workingDirectory: directoryPath,
runInShell: true,
);
Expand Down Expand Up @@ -130,16 +134,14 @@ class ScriptService {
/// [maxVersion] A string that represents the maximum version of Dart allowed.
/// return A Future<bool> that is true if the installed version of Dart
/// is within the allowed range and false otherwise.
static Future<bool> isDartVersionInRange(
String minVersion, String maxVersion) async {
static Future<bool> isDartVersionInRange(String minVersion, String maxVersion) async {
final ProcessResult processResult = await Process.run(
'dart',
<String>['--version'],
runInShell: true,
);
final String versionOutput = processResult.stdout.toString().trim();
final RegExpMatch? versionMatch =
RegExp(r'version: ([\d\.]+)').firstMatch(versionOutput);
final RegExpMatch? versionMatch = RegExp(r'version: ([\d\.]+)').firstMatch(versionOutput);
if (versionMatch != null) {
final String? sdkVersion = versionMatch.group(1);
if (sdkVersion != null) {
Expand All @@ -149,11 +151,8 @@ class ScriptService {
convertToThousands(int.tryParse(minVersion.replaceAll('.', '')));
final int? numericMaxVersion =
convertToThousands(int.tryParse(maxVersion.replaceAll('.', '')));
if (numericSdkVersion != null &&
numericMinVersion != null &&
numericMaxVersion != null) {
if (numericSdkVersion >= numericMinVersion &&
numericSdkVersion <= numericMaxVersion) {
if (numericSdkVersion != null && numericMinVersion != null && numericMaxVersion != null) {
if (numericSdkVersion >= numericMinVersion && numericSdkVersion <= numericMaxVersion) {
return true;
}
}
Expand Down