Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom config path option #38

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
93 changes: 59 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,71 +21,85 @@ For more info see [list of changed fields](CHANGED_FIELDS.md)

```yaml
dev_dependencies:
package_rename: ^1.4.0
package_rename: ^1.4.0
milindgoel15 marked this conversation as resolved.
Show resolved Hide resolved
```

#### Create configuration

You can create configurations by adding `package_rename_config` key in:

1. Root `pubspec.yaml` file
1. `package_rename_config.yaml` file at root of your project
1. `package_rename_config.yaml` file at root of your project or a custom folder in the project

## Usage

#### Adding Platform Specific Configurations

```yaml
package_rename_config:
android:
app_name: # (String) The display name of the android app
package_name: # (String) The package name of the android app
override_old_package: # (Optional) (String) Use this to delete the old folder structure of MainActivity or to use the existing code with the new package name
lang: # (Optional) (String) The android development language {kotlin(default) or java}

ios:
app_name: # (String) The display name of the ios app
bundle_name: # (String) The bundle name of the ios app
package_name: # (String) The product bundle identifier of the ios app

linux:
app_name: # (String) The window title of the linux app
package_name: # (String) The application id of the linux app
exe_name: # (String) The executable name (binary name) of the linux app

macos:
app_name: # (String) The product name of the macos app
package_name: # (String) The product bundle identifier of the macos app
copyright_notice: # (String) The product copyright of the macos app

web:
app_name: # (String) The title and display name of the web app and PWA
description: # (String) The description of the web app and PWA

windows:
app_name: # (String) The window title & software name of the windows app
organization: # (String) The organization name (company name) of the windows app
copyright_notice: # (String) The legal copyright of the windows app
exe_name: # (String) The executable name (binary name) of the windows app
android:
app_name: # (String) The display name of the android app
package_name: # (String) The package name of the android app
override_old_package: # (Optional) (String) Use this to delete the old folder structure of MainActivity or to use the existing code with the new package name
lang: # (Optional) (String) The android development language {kotlin(default) or java}

ios:
app_name: # (String) The display name of the ios app
bundle_name: # (String) The bundle name of the ios app
package_name: # (String) The product bundle identifier of the ios app

linux:
app_name: # (String) The window title of the linux app
package_name: # (String) The application id of the linux app
exe_name: # (String) The executable name (binary name) of the linux app

macos:
app_name: # (String) The product name of the macos app
package_name: # (String) The product bundle identifier of the macos app
copyright_notice: # (String) The product copyright of the macos app

web:
app_name: # (String) The title and display name of the web app and PWA
description: # (String) The description of the web app and PWA

windows:
app_name: # (String) The window title & software name of the windows app
organization: # (String) The organization name (company name) of the windows app
copyright_notice: # (String) The legal copyright of the windows app
exe_name: # (String) The executable name (binary name) of the windows app
milindgoel15 marked this conversation as resolved.
Show resolved Hide resolved
```

> For full example click [here](example/example.md#default-configuration)

#### Running Package Rename

Execute the follow command at the root of your project:
Execute the command as per your config location:

if config file exists in either pubspec.yaml or root path:

```bash
dart run package_rename
```

OR

if config file exists in a custom folder:

```bash
dart run package_rename --path="path/to/package_rename_config.yaml"

or

dart run package_rename -p "path/to/package_rename_config.yaml"
```

## Flavour Support

Package Rename supports flavours. You can add flavour specific configurations by adding `flavour_name` in configuration key.

```yaml
package_rename_config-flavour_name:
# ...
# ...
milindgoel15 marked this conversation as resolved.
Show resolved Hide resolved
```

> For full example click [here](example/example.md#flavour-configuration)
Expand All @@ -94,6 +108,17 @@ And then run the following command:

```bash
dart run package_rename --flavour=flavour_name

or

dart run package_rename -f flavour_name

```
milindgoel15 marked this conversation as resolved.
Show resolved Hide resolved

With custom config file location:

```bash
dart run package_rename --flavour=flavour_name --path="path/to/package_rename_config.yaml"
```

## And that's it! 🎉
Expand Down
6 changes: 6 additions & 0 deletions lib/messages.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
part of package_rename;

const _packageRenameCommands = '''
╔═════════════════════════════════════╗
║ Package Rename Commands ║
╚═════════════════════════════════════╝
''';

const _successMessage = '''
╔═════════════════════════════════════════════════════════════╗
║ 🥳🥳🥳 Done! Now go ahead and build your app 🥳🥳🥳 ║
Expand Down
55 changes: 50 additions & 5 deletions lib/package_rename.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,34 @@ void set(List<String> args) {

// Create args parser to get flavour flag and its value
final parser = ArgParser()
..addOption(
'path',
abbr: 'p',
help: 'The path for the config file',
)
..addOption(
'flavour',
abbr: 'f',
help: 'The flavour of the configuration to be used.',
aliases: ['flavor'],
)
..addFlag(
'help',
abbr: 'h',
negatable: false,
help: 'Prints out available command usages',
);
final results = parser.parse(args);

if (results.wasParsed('help')) {
print(_packageRenameCommands);
print(parser.usage);
milindgoel15 marked this conversation as resolved.
Show resolved Hide resolved
exit(0);
}
final flavour = results['flavour'] as String?;
final path = results['path'] as String?;

final config = _getConfig(flavour: flavour);
final config = _getConfig(flavour: flavour, configFile: path);

_setAndroidConfigurations(config['android']);
_setIOSConfigurations(config['ios']);
Expand All @@ -104,10 +122,25 @@ bool _configFileExists() {
return configFile.existsSync() || pubspecFile.existsSync();
}

Map<String, dynamic> _getConfig({required String? flavour}) {
final yamlFile = File(_packageRenameConfigFileName).existsSync()
? File(_packageRenameConfigFileName)
: File(_pubspecFileName);
Map<String, dynamic> _getConfig({
required String? flavour,
String? configFile,
}) {
File yamlFile;

if (configFile != null) {
if (File(configFile).existsSync()) {
_checkConfigContent(configFile);
yamlFile = File(configFile);
} else {
throw _PackageRenameErrors.filesNotFound;
}
} else if (File(_packageRenameConfigFileName).existsSync()) {
_checkConfigContent(_packageRenameConfigFileName);
yamlFile = File(_packageRenameConfigFileName);
} else {
yamlFile = File(_pubspecFileName);
}

final yamlString = yamlFile.readAsStringSync();
final parsedYaml = yaml.loadYaml(yamlString) as Map;
Expand All @@ -124,3 +157,15 @@ Map<String, dynamic> _getConfig({required String? flavour}) {

return Map<String, dynamic>.from(rawConfig);
}

void _checkConfigContent(String yamlFile) {
final fileContent = File(yamlFile).readAsStringSync();

if (fileContent.isEmpty) {
throw _PackageRenameErrors.filesNotFound;
}

if (yaml.loadYaml(fileContent) == null) {
throw _PackageRenameErrors.configNotFound;
}
}
Loading