run method
Executes the initialization command to set up the project.
This method performs the following tasks:
- Creates necessary distribution directories
- Validates required development tools
- Sets up platform-specific configurations
- Generates initial configuration files
- Downloads metadata for Android publishing
The initialization process includes:
- Directory structure creation for Android and iOS (macOS only)
- Tool validation for Flutter, Firebase, Git, Fastlane, and compression tools
- Fastlane configuration setup
- Google Play Console metadata download
Implementation
@override
Future<int> run() async {
final initialized = <String, bool>{};
final configFilePath = configPath;
_logWelcome();
if (!_checkPubspecFile()) return 1;
await _createDirectory(
path.join("distribution", "android", "output"),
initialized,
"android_directory",
);
if (Platform.isMacOS) {
await _createDirectory(
path.join("distribution", "ios", "output"),
initialized,
"ios_directory",
);
}
if (!(argResults!['skip-tools'] as bool)) {
await _checkTool(
"flutter",
"Flutter",
initialized,
args: ['--version'],
).catchError((_) => -1);
await _checkTool(
"firebase",
"Firebase",
initialized,
).catchError((_) => -1);
await _checkTool(
"git",
"Git",
initialized,
args: ['--version'],
).catchError((_) => -1);
await CompressFiles.checkTools().then((value) {
if (!value) {
logger.logWarning("archiver ${ColorizeLogger.dim("not found")}");
} else {
logger.logSuccess("archiver ${ColorizeLogger.dim("available")}");
initialized["compress_tool"] = true;
}
});
await _checkTool(
"fastlane",
"Fastlane",
initialized,
args: ['actions'],
).catchError((_) => -1).then((value) async {
if (value == 0) {
await _validateFastlaneJson(initialized).then((value) async {
if (value == 0) return await _downloadAndroidMetaData();
});
} else {
final install = Platform.isWindows
? 'gem install fastlane'
: 'sudo gem install fastlane';
logger.logDetail('install with `$install` (requires Ruby)');
initialized["fastlane_json"] = false;
}
});
if (Platform.isMacOS) {
await _checkTool(
"xcrun",
"XCRun",
initialized,
args: ["altool", "-h"],
).catchError((_) => -1);
}
}
final yaml = File(configFilePath);
if (yaml.existsSync()) {
logger.logWarning(
"kept ${ColorizeLogger.dim("$configFilePath already exists")}");
} else {
await yaml.writeAsString(yamlEncode(structures), flush: true);
logger.logSuccess("created ${ColorizeLogger.dim(configFilePath)}");
}
await _ensureLogIsIgnored();
return 0;
}