-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added android create keystore command
- Loading branch information
1 parent
4e163f4
commit 5456209
Showing
16 changed files
with
396 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
# 0.14.0 | ||
|
||
## Feat | ||
|
||
- Android create keychain command (cli & plugin) | ||
|
||
# 0.13.8 | ||
|
||
## Fix | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:impaktfull_cli/impaktfull_cli.dart'; | ||
import 'package:impaktfull_cli/src/integrations/android/create_keystore/model/keystore_credentials.dart'; | ||
import 'package:path/path.dart'; | ||
|
||
class AndroidProject { | ||
final Directory directory; | ||
|
||
File get gradleFile => File(join('android', 'app', 'build.gradle')); | ||
|
||
AndroidProject(this.directory); | ||
|
||
void validate() { | ||
_checkIfGradleFileExits(); | ||
} | ||
|
||
void _checkIfGradleFileExits() { | ||
if (!gradleFile.existsSync()) { | ||
throw ImpaktfullCliError( | ||
'${gradleFile.path} does not exist. Maybe your android project is corrupt'); | ||
} | ||
} | ||
|
||
void replacePackageName(String newPackageName) { | ||
var content = gradleFile.readAsStringSync(); | ||
content = content.replaceAll( | ||
RegExp(r'applicationId "[\w.]*"'), 'applicationId "$newPackageName"'); | ||
gradleFile.writeAsStringSync(content); | ||
} | ||
|
||
void replaceNamespace(String newNameSpace) { | ||
var content = gradleFile.readAsStringSync(); | ||
content = content.replaceAll( | ||
RegExp(r'namespace "[\w.]*"'), 'namespace "$newNameSpace"'); | ||
gradleFile.writeAsStringSync(content); | ||
} | ||
|
||
void replaceSigningConfig({ | ||
required KeyStoreCredentials keyStoreCredentials, | ||
}) { | ||
final name = keyStoreCredentials.name; | ||
var content = gradleFile.readAsStringSync(); | ||
|
||
final RegExp configBlockPattern = RegExp( | ||
r'.*' + | ||
name + | ||
r' {\n.*storeFile file\("(.*)"\)\n.*storePassword "(.*)"\n.*keyAlias "(.*)"\n.*keyPassword "(.*)"\n.*}', | ||
multiLine: true, | ||
); | ||
final allMatches = configBlockPattern.allMatches(content); | ||
final match = allMatches.first.group(0)!; | ||
final updatedMatch = match | ||
.replaceFirst(RegExp(r'storePassword "(.*?)"'), | ||
'storePassword "${keyStoreCredentials.password}"') | ||
.replaceFirst(RegExp(r'keyAlias "(.*?)"'), | ||
'keyAlias "${keyStoreCredentials.keyAlias}"') | ||
.replaceFirst(RegExp(r'keyPassword "(.*?)"'), | ||
'keyPassword "${keyStoreCredentials.password}"'); | ||
|
||
final updatedContent = content.replaceAll(configBlockPattern, updatedMatch); | ||
|
||
if (updatedContent == content) { | ||
throw ImpaktfullCliError( | ||
'No matching signing config named "$name" found or no changes necessary.'); | ||
} | ||
|
||
gradleFile.writeAsStringSync(updatedContent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:args/command_runner.dart'; | ||
import 'package:impaktfull_cli/src/integrations/android/create_keystore/command/remove/android_create_keystore_command.dart'; | ||
import 'package:impaktfull_cli/src/core/command/command/root_command.dart'; | ||
|
||
class AndroidRootCommand extends RootCommand { | ||
@override | ||
String get name => 'android'; | ||
|
||
@override | ||
String get description => 'Commands for Android integrations.'; | ||
|
||
AndroidRootCommand({ | ||
required super.processRunner, | ||
}); | ||
|
||
@override | ||
List<Command<dynamic>> getSubCommands() { | ||
return [ | ||
AndroidCreateKeystoreCommand(processRunner: processRunner), | ||
]; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.../integrations/android/create_keystore/command/remove/android_create_keystore_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:impaktfull_cli/impaktfull_cli.dart'; | ||
import 'package:impaktfull_cli/src/core/command/command/cli_command.dart'; | ||
import 'package:impaktfull_cli/src/integrations/android/create_keystore/command/remove/android_create_keystore_command_config.dart'; | ||
import 'package:impaktfull_cli/src/integrations/android/create_keystore/command/remove/model/android_create_keystore_config_data.dart'; | ||
import 'package:impaktfull_cli/src/core/command/config/command_config.dart'; | ||
import 'package:impaktfull_cli/src/integrations/android/create_keystore/plugin/android_create_keystore_plugin.dart'; | ||
|
||
class AndroidCreateKeystoreCommand | ||
extends CliCommand<AndroidCreateKeyStoreConfigData> { | ||
AndroidCreateKeystoreCommand({ | ||
required super.processRunner, | ||
}); | ||
|
||
@override | ||
String get name => 'create_keystore'; | ||
|
||
@override | ||
String get description => 'Create a keystore'; | ||
|
||
@override | ||
CommandConfig<AndroidCreateKeyStoreConfigData> getConfig() => | ||
AndroidCreateKeyStoreCommandConfig(); | ||
|
||
@override | ||
Future<void> runCommand(AndroidCreateKeyStoreConfigData configData) async { | ||
final androidCreateKeyStorePlugin = | ||
AndroidCreateKeyStorePlugin(processRunner: processRunner); | ||
for (final name in configData.configNames) { | ||
ImpaktfullCliLogger.startSpinner('Creating keystore for $name'); | ||
await androidCreateKeyStorePlugin.createKeyStore( | ||
name: name, | ||
dNameFullName: configData.dNameFullName, | ||
dNameOrganization: configData.dNameOrganization, | ||
dNameOrganizationUnit: configData.dNameOrganizationUnit, | ||
dNameCity: configData.dNameCity, | ||
dNameState: configData.dNameState, | ||
dNameCountry: configData.dNameCountry, | ||
); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...ations/android/create_keystore/command/remove/android_create_keystore_command_config.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import 'package:args/args.dart'; | ||
import 'package:impaktfull_cli/src/integrations/android/create_keystore/command/remove/model/android_create_keystore_config_data.dart'; | ||
import 'package:impaktfull_cli/src/core/command/config/command_config.dart'; | ||
import 'package:impaktfull_cli/src/core/util/extensions/arg_result_extensions.dart'; | ||
|
||
class AndroidCreateKeyStoreCommandConfig | ||
extends CommandConfig<AndroidCreateKeyStoreConfigData> { | ||
static const String _optionConfigName = 'configName'; | ||
static const String _optionDNameFullName = 'dNameFullName'; | ||
static const String _optionDNameOrganization = 'dNameOrganization'; | ||
static const String _optionDNameOrganizationUnit = 'dNameOrganizationUnit'; | ||
static const String _optionDNameCity = 'dNameCity'; | ||
static const String _optionDNameState = 'dNameState'; | ||
static const String _optionDNameCountry = 'dNameCountry'; | ||
static const defaultSigningConfigNames = ['debug', 'release']; | ||
|
||
const AndroidCreateKeyStoreCommandConfig(); | ||
|
||
@override | ||
void addConfig(ArgParser argParser) { | ||
argParser.addMultiOption( | ||
_optionConfigName, | ||
help: 'Signing config name', | ||
defaultsTo: defaultSigningConfigNames, | ||
); | ||
argParser.addOption( | ||
_optionDNameFullName, | ||
help: 'Certificate info: Your full name', | ||
mandatory: true, | ||
); | ||
argParser.addOption( | ||
_optionDNameOrganization, | ||
help: 'Certificate info: Your organization name', | ||
mandatory: true, | ||
); | ||
argParser.addOption( | ||
_optionDNameOrganizationUnit, | ||
help: 'Certificate info: Your organization unit name', | ||
); | ||
argParser.addOption( | ||
_optionDNameState, | ||
help: 'Certificate info: Your state name', | ||
); | ||
argParser.addOption( | ||
_optionDNameCity, | ||
help: 'Certificate info: Your city name', | ||
); | ||
argParser.addOption( | ||
_optionDNameCountry, | ||
help: 'Certificate info: Your country name', | ||
mandatory: true, | ||
); | ||
} | ||
|
||
@override | ||
AndroidCreateKeyStoreConfigData parseResult(ArgResults? argResults) => | ||
AndroidCreateKeyStoreConfigData( | ||
configNames: argResults.getRequiredOption(_optionConfigName), | ||
dNameFullName: argResults.getRequiredOptionOrAskInput<String>( | ||
_optionDNameFullName, 'Enter your Full Name'), | ||
dNameOrganization: argResults.getRequiredOptionOrAskInput<String>( | ||
_optionDNameOrganization, 'Enter your Organization'), | ||
dNameOrganizationUnit: argResults.getOptionOrAskInput<String>( | ||
_optionDNameOrganizationUnit, | ||
'Enter your Oranization Unit (optional)'), | ||
dNameCity: argResults.getOptionOrAskInput<String>( | ||
_optionDNameCity, 'Enter your City (optional)'), | ||
dNameState: argResults.getOptionOrAskInput( | ||
_optionDNameState, 'Enter your State (optional)'), | ||
dNameCountry: argResults.getRequiredOptionOrAskInput( | ||
_optionDNameCountry, 'Enter the Country'), | ||
); | ||
} |
22 changes: 22 additions & 0 deletions
22
...ons/android/create_keystore/command/remove/model/android_create_keystore_config_data.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import 'package:impaktfull_cli/src/core/command/config/command_config.dart'; | ||
|
||
class AndroidCreateKeyStoreConfigData extends ConfigData { | ||
final List<String> configNames; | ||
|
||
final String? dNameFullName; | ||
final String? dNameOrganization; | ||
final String? dNameOrganizationUnit; | ||
final String? dNameCity; | ||
final String? dNameState; | ||
final String? dNameCountry; | ||
|
||
const AndroidCreateKeyStoreConfigData({ | ||
required this.configNames, | ||
required this.dNameFullName, | ||
required this.dNameOrganization, | ||
required this.dNameOrganizationUnit, | ||
required this.dNameCity, | ||
required this.dNameState, | ||
required this.dNameCountry, | ||
}); | ||
} |
Oops, something went wrong.