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

feat(fluttium_interfaces): refactor to use addons semantics instead of actions #204

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import 'package:equatable/equatable.dart';
import 'package:fluttium_interfaces/src/fluttium/fluttium.dart';

/// {@template action_location}
/// The location of an action.
@Deprecated('use AddonLocation instead')
typedef ActionLocation = AddonLocation;

/// {@template addon_location}
/// The location of an addon.
/// {@endtemplate}
class ActionLocation extends Equatable {
/// {@macro action_location}
const ActionLocation({
class AddonLocation extends Equatable {
/// {@macro addon_location}
const AddonLocation({
this.hosted,
this.git,
this.path,
Expand All @@ -17,20 +21,20 @@ class ActionLocation extends Equatable {
'Only one of hosted, git, or path can be set.',
);

/// {@macro action_location}
/// {@macro addon_location}
///
/// Converts a json map to an [ActionLocation].
factory ActionLocation.fromJson(dynamic data) {
/// Converts a json map to an [AddonLocation].
factory AddonLocation.fromJson(dynamic data) {
if (data is String) {
return ActionLocation(
return AddonLocation(
hosted: HostedPath(
url: 'https://pub.dartlang.org',
version: VersionConstraint.parse(data),
),
);
} else if (data is Map<String, dynamic>) {
if (data.containsKey('hosted')) {
return ActionLocation(
return AddonLocation(
hosted: HostedPath(
url: data['hosted'] as String,
version: VersionConstraint.parse(data['version'] as String),
Expand All @@ -39,9 +43,9 @@ class ActionLocation extends Equatable {
} else if (data.containsKey('git')) {
final dynamic git = data['git'];
if (git is String) {
return ActionLocation(git: GitPath(url: git));
return AddonLocation(git: GitPath(url: git));
} else if (git is Map<String, dynamic>) {
return ActionLocation(
return AddonLocation(
git: GitPath(
url: git['url'] as String,
ref: git['ref'] as String?,
Expand All @@ -50,9 +54,9 @@ class ActionLocation extends Equatable {
);
}
} else if (data.containsKey('path')) {
return ActionLocation(path: data['path'] as String);
return AddonLocation(path: data['path'] as String);
}
throw UnsupportedError('unknown action dependency setup: $data');
throw UnsupportedError('unknown addon dependency setup: $data');
} else {
throw ArgumentError.value(
data,
Expand All @@ -62,21 +66,21 @@ class ActionLocation extends Equatable {
}
}

/// The hosted path of the action.
/// The hosted path of the addon.
final HostedPath? hosted;

/// The git path of the action.
/// The git path of the addon.
final GitPath? git;

/// The path of the action.
/// The path of the addon.
final String? path;

@override
List<Object?> get props => [hosted, git, path];
}

/// {@template hosted_path}
/// The hosted path of an action.
/// The hosted path of an addon.
/// {@endtemplate}
class HostedPath extends Equatable {
/// {@macro hosted_path}
Expand All @@ -88,15 +92,15 @@ class HostedPath extends Equatable {
/// The hosted url.
final String url;

/// The version constraint of the action.
/// The version constraint of the addon.
final VersionConstraint version;

@override
List<Object?> get props => [url, version];
}

/// {@template git_path}
/// The git path of an action.
/// The git path of an addon.
/// {@endtemplate}
class GitPath extends Equatable {
/// {@macro git_path}
Expand All @@ -112,7 +116,7 @@ class GitPath extends Equatable {
/// The ref of the git repository.
final String? ref;

/// The path where the action is located in the git repository.
/// The path where the addon is located in the git repository.
final String? path;

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ library fluttium;

export 'package:pub_semver/pub_semver.dart';

export 'action_location.dart';
export 'addon_location.dart';
export 'driver_configuration.dart';
export 'fluttium_environment.dart';
export 'fluttium_yaml.dart';
27 changes: 17 additions & 10 deletions packages/fluttium_interfaces/lib/src/fluttium/fluttium_yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FluttiumYaml extends Equatable {
/// {@macro fluttium_yaml}
const FluttiumYaml({
required this.environment,
this.actions = const {},
this.addons = const {},
this.driver = const DriverConfiguration(),
});

Expand All @@ -28,10 +28,12 @@ class FluttiumYaml extends Equatable {
environment: FluttiumEnvironment.fromJson(
yaml['environment'] as Map<String, dynamic>? ?? {},
),
actions: {
for (final entry
in (yaml['actions'] as Map<String, dynamic>? ?? {}).entries)
entry.key: ActionLocation.fromJson(entry.value)
addons: {
for (final entry in (yaml['addons'] as Map<String, dynamic>? ??
yaml['actions'] as Map<String, dynamic>? ??
{})
.entries)
entry.key: AddonLocation.fromJson(entry.value)
},
driver: DriverConfiguration.fromJson(
yaml['driver'] as Map<String, dynamic>? ?? {},
Expand All @@ -45,21 +47,26 @@ class FluttiumYaml extends Equatable {
/// The configuration for the driver.
final DriverConfiguration driver;

/// The actions to install to run the flow.
final Map<String, ActionLocation> actions;
/// The addons to install to run the flow.
final Map<String, AddonLocation> addons;

/// The addons to install to run the flow.
@Deprecated('use addons instead')
Map<String, AddonLocation> get actions => addons;

@override
List<Object?> get props => [environment, driver, actions];
List<Object?> get props => [environment, driver, addons];

/// Copy the configuration to a new instance with optional overrides.
FluttiumYaml copyWith({
FluttiumEnvironment? environment,
Map<String, ActionLocation>? actions,
@Deprecated('use addons instead') Map<String, AddonLocation>? actions,
Map<String, AddonLocation>? addons,
DriverConfiguration? driver,
}) {
return FluttiumYaml(
environment: environment ?? this.environment,
actions: actions ?? this.actions,
addons: addons ?? this.addons,
driver: driver ?? this.driver,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import 'package:fluttium_interfaces/fluttium_interfaces.dart';
import 'package:test/test.dart';

void main() {
group('ActionLocation', () {
group('$AddonLocation', () {
test('can be instantiated', () {
final location = ActionLocation(
final location = AddonLocation(
hosted: HostedPath(
url: 'https://pub.dartlang.org',
version: VersionConstraint.parse('1.0.0'),
Expand All @@ -20,7 +20,7 @@ void main() {

group('fromJson', () {
test('creates hosted location when data is a string', () {
final location = ActionLocation.fromJson('1.0.0');
final location = AddonLocation.fromJson('1.0.0');

expect(location.hosted, isNotNull);
expect(
Expand All @@ -32,7 +32,7 @@ void main() {
});

test('creates hosted location when data is a hosted map', () {
final location = ActionLocation.fromJson(const {
final location = AddonLocation.fromJson(const {
'hosted': 'https://my.custom.pub',
'version': '1.0.0',
});
Expand All @@ -48,37 +48,37 @@ void main() {
});

test('creates git location when data is a git map with a string', () {
final location = ActionLocation.fromJson(const {
'git': 'git@git.some.where/some/action.git',
final location = AddonLocation.fromJson(const {
'git': 'git@git.some.where/some/addon.git',
});

expect(location.hosted, isNull);
expect(location.git, isNotNull);
expect(location.git!.url, equals('git@git.some.where/some/action.git'));
expect(location.git!.url, equals('git@git.some.where/some/addon.git'));
expect(location.git!.ref, isNull);
expect(location.git!.path, isNull);
expect(location.path, isNull);
});

test('creates git location when data is a git map', () {
final location = ActionLocation.fromJson(const {
final location = AddonLocation.fromJson(const {
'git': {
'url': 'git@git.some.where/some/action.git',
'url': 'git@git.some.where/some/addon.git',
'ref': 'main',
'path': 'some/path',
}
});

expect(location.hosted, isNull);
expect(location.git, isNotNull);
expect(location.git!.url, equals('git@git.some.where/some/action.git'));
expect(location.git!.url, equals('git@git.some.where/some/addon.git'));
expect(location.git!.ref, equals('main'));
expect(location.git!.path, equals('some/path'));
expect(location.path, isNull);
});

test('creates path location when data is a path map', () {
final location = ActionLocation.fromJson(const {
final location = AddonLocation.fromJson(const {
'path': 'some/path',
});

Expand All @@ -89,14 +89,14 @@ void main() {

test('throws when data is not a string or map', () {
expect(
() => ActionLocation.fromJson(1),
() => AddonLocation.fromJson(1),
throwsA(isA<ArgumentError>()),
);
});

test('throws when data is a map with unknown keys', () {
expect(
() => ActionLocation.fromJson(const {
() => AddonLocation.fromJson(const {
'unknown': 'some/path',
}),
throwsA(isA<UnsupportedError>()),
Expand All @@ -105,14 +105,14 @@ void main() {
});

test('equality', () {
final location = ActionLocation(
final location = AddonLocation(
hosted: HostedPath(
url: 'https://pub.dartlang.org',
version: VersionConstraint.parse('1.0.0'),
),
);

final otherLocation = ActionLocation(
final otherLocation = AddonLocation(
hosted: HostedPath(
url: 'https://pub.dartlang.org',
version: VersionConstraint.parse('1.0.0'),
Expand Down Expand Up @@ -152,25 +152,25 @@ void main() {
group('GitPath', () {
test('can be instantiated', () {
final path = GitPath(
url: 'git@git.some.where/some/action.git',
url: 'git@git.some.where/some/addon.git',
ref: 'main',
path: 'some/path',
);

expect(path.url, equals('git@git.some.where/some/action.git'));
expect(path.url, equals('git@git.some.where/some/addon.git'));
expect(path.ref, equals('main'));
expect(path.path, equals('some/path'));
});

test('equality', () {
final path = GitPath(
url: 'git@git.some.where/some/action.git',
url: 'git@git.some.where/some/addon.git',
ref: 'main',
path: 'some/path',
);

final otherPath = GitPath(
url: 'git@git.some.where/some/action.git',
url: 'git@git.some.where/some/addon.git',
ref: 'main',
path: 'some/path',
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:fluttium_interfaces/fluttium_interfaces.dart';
import 'package:test/test.dart';

void main() {
group('DriverConfiguration', () {
group('$DriverConfiguration', () {
test('can be instantiated', () {
final driver = DriverConfiguration(
target: 'lib/main_development.dart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:fluttium_interfaces/fluttium_interfaces.dart';
import 'package:test/test.dart';

void main() {
group('FluttiumEnvironment', () {
group('$FluttiumEnvironment', () {
test('can be instantiated', () {
final environment = FluttiumEnvironment(
fluttium: VersionConstraint.parse('>=0.1.0-dev.1 <0.1.0'),
Expand Down
Loading