Skip to content

Commit

Permalink
Merge pull request #47 from alsterverse/fix/external-datasources
Browse files Browse the repository at this point in the history
Fix external datasource
  • Loading branch information
PhiFry authored Sep 3, 2024
2 parents 7152c1d + 3da3bd0 commit a3425f0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions code_generator/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class StoryblokCodegen {
required this.components,
required List<DatasourceWithEntries> datasourceWithEntries,
required this.getExternalDatasourceEntries,
}) : datasourceData = datasourceWithEntries.map((e) {
}) : internalDatasources = datasourceWithEntries.map((e) {
final (:datasource, :entries) = e;
return buildEnum(datasource.slug, entries.map((e) => MapEntry(e.name, e.value)));
}).toList();

final List<Component> components;
final List<Enum> datasourceData;
final List<Enum> internalDatasources;
final Future<List<JSONMap>> Function(Uri) getExternalDatasourceEntries;
final codeEmitter = CodeEmitter();

Expand All @@ -36,11 +36,11 @@ class StoryblokCodegen {
final components = _buildComponents(lib).toList();

// enum <name> {
lib.body.addAll(datasourceData);
final externalDatasources = await Future.wait(
lib.body.addAll(internalDatasources);

lib.body.addAll(await Future.wait(
_externalDatasourceUrls.map((e) => buildEnumFromExternalSource(e, getExternalDatasourceEntries)),
);
lib.body.addAll(externalDatasources);
));

// sealed class Blok {
final (:sealedClass, :classes) = buildBloksSealedClass(
Expand Down Expand Up @@ -94,6 +94,9 @@ class StoryblokCodegen {
final supportingClass = field.buildSupportingClass();
if (supportingClass != null) lib.body.addAll(supportingClass);

final externalDatasourceUrl = field.getExternalDatasourceUrl();
if (externalDatasourceUrl != null) _externalDatasourceUrls.add(externalDatasourceUrl);

c.fields.add(field.build(fieldName));

con.initializers.add(
Expand Down

0 comments on commit a3425f0

Please sign in to comment.