Skip to content

Commit 6a56817

Browse files
committed
chore: remove Dart version pragma from generated files to prevent mismatches, updated pubspec.yaml to include pub_semver dependency
1 parent 790b235 commit 6a56817

File tree

6 files changed

+49
-17
lines changed

6 files changed

+49
-17
lines changed

maplibre_gl/lib/src/layer_expressions.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @dart=3.9
2-
31
// This file is generated by
42
// ./scripts/lib/generate.dart
53

maplibre_gl/lib/src/layer_properties.dart

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @dart=3.9
2-
31
// This file is generated by
42
// ./scripts/lib/generate.dart
53

@@ -1895,8 +1893,7 @@ class FillExtrusionLayerProperties implements LayerProperties {
18951893
changes.fillExtrusionPattern ?? fillExtrusionPattern,
18961894
fillExtrusionHeight: changes.fillExtrusionHeight ?? fillExtrusionHeight,
18971895
fillExtrusionBase: changes.fillExtrusionBase ?? fillExtrusionBase,
1898-
fillExtrusionVerticalGradient:
1899-
changes.fillExtrusionVerticalGradient ??
1896+
fillExtrusionVerticalGradient: changes.fillExtrusionVerticalGradient ??
19001897
fillExtrusionVerticalGradient,
19011898
visibility: changes.visibility ?? visibility,
19021899
);
@@ -2217,8 +2214,7 @@ class HillshadeLayerProperties implements LayerProperties {
22172214

22182215
HillshadeLayerProperties copyWith(HillshadeLayerProperties changes) {
22192216
return HillshadeLayerProperties(
2220-
hillshadeIlluminationDirection:
2221-
changes.hillshadeIlluminationDirection ??
2217+
hillshadeIlluminationDirection: changes.hillshadeIlluminationDirection ??
22222218
hillshadeIlluminationDirection,
22232219
hillshadeIlluminationAnchor:
22242220
changes.hillshadeIlluminationAnchor ?? hillshadeIlluminationAnchor,

maplibre_gl_platform_interface/lib/src/source_properties.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @dart=3.9
2-
31
// This file is generated by
42
// ./scripts/lib/generate.dart
53

maplibre_gl_web/lib/src/layer_tools.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @dart=3.9
2-
31
// This file is generated by
42
// ./scripts/lib/generate.dart
53

scripts/lib/generate.dart

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
// Code generation entry point for the MapLibre Flutter workspace.
2+
//
3+
// This script reads the canonical style definition (style.json) and produces
4+
// strongly-typed Dart (and some platform specific Java/Swift) sources that
5+
// expose layer & source properties plus expression helpers.
6+
//
7+
// Key goals:
8+
// - Keep hand‑written logic small; most surface area is generated.
9+
// - Ensure deterministic output (stable ordering helps minimal diffs).
10+
// - Apply formatting immediately so CI "format-all" never fails after generation.
11+
//
12+
// Notes:
13+
// - Do NOT edit the generated files manually; instead adjust templates or
14+
// this generator.
15+
// - The generator intentionally avoids adding a per‑file language version
16+
// pragma to prevent part <-> library mismatches (see earlier CI issue).
17+
// - If the style specification evolves, update templates & mapping tables
18+
// inside conversions.dart.
19+
// - Run via: melos run generate
20+
//
121
import 'dart:io';
222
import 'dart:convert';
323

@@ -9,10 +29,14 @@ import 'package:pub_semver/pub_semver.dart';
929
import 'conversions.dart';
1030

1131
Future<void> main() async {
32+
/// We assume the current working directory for this script is the scripts/
33+
/// package root (melos exec enforces that). style.json lives under input/.
1234
final currentPath = Directory.current.path;
1335
final styleFilePath = '$currentPath/input/style.json';
1436
final styleJson = jsonDecode(await File(styleFilePath).readAsString());
1537

38+
/// Layer types in the order we want to render them. Order matters for
39+
/// deterministic output & smaller diffs.
1640
final layerTypes = [
1741
"symbol",
1842
"circle",
@@ -24,6 +48,8 @@ Future<void> main() async {
2448
"heatmap",
2549
];
2650

51+
/// Source types. The template will convert snake_case to
52+
/// the appropriate casing for class names and enum-like strings.
2753
final sourceTypes = [
2854
"vector",
2955
"raster",
@@ -33,6 +59,9 @@ Future<void> main() async {
3359
"image"
3460
];
3561

62+
/// Build the mustache rendering context consumed by each template.
63+
/// Most heavy lifting (doc splitting, type inference) happens in helper
64+
/// functions below for clarity & reuse.
3665
final renderContext = {
3766
"layerTypes": [
3867
for (final type in layerTypes)
@@ -56,11 +85,15 @@ Future<void> main() async {
5685
};
5786

5887
// required for deduplication
88+
// Collect a set of all layout property names across layer types to enable
89+
// template logic for shared helpers / deduplication.
5990
renderContext["all_layout_properties"] = <dynamic>{
6091
for (final type in renderContext["layerTypes"]!)
6192
...type["layout_properties"].map((p) => p["value"])
6293
}.map((p) => {"property": p}).toList();
6394

95+
// Ordered list of templates we render. If you add a new feature, append
96+
// here to keep existing diff noise minimal.
6497
const templates = [
6598
"maplibre_gl/android/src/main/java/org/maplibre/maplibregl/LayerPropertyConverter.java",
6699
"maplibre_gl/ios/maplibre_gl/Sources/maplibre_gl/LayerPropertyConverter.swift",
@@ -75,6 +108,9 @@ Future<void> main() async {
75108
}
76109
}
77110

111+
/// Render a single template file.
112+
/// [path] is the relative workspace path to the output (and indirectly the
113+
/// template at scripts/templates/$filename.template).
78114
Future<void> render(
79115
Map<String, List> renderContext,
80116
String path,
@@ -104,11 +140,6 @@ Future<void> render(
104140
final languageVersion =
105141
'${versionParts.elementAt(0)}.${versionParts.elementAt(1)}';
106142

107-
// Prepend language version pragma if not already present
108-
if (!rendered.startsWith('// @dart=')) {
109-
rendered = '// @dart=$languageVersion\n\n$rendered';
110-
}
111-
112143
// Pass the version to the formatter so it can format accordingly
113144
final versionObj = Version.parse('$languageVersion.0');
114145
final formatter = DartFormatter(languageVersion: versionObj);
@@ -122,13 +153,15 @@ Future<void> render(
122153
await outputFile.writeAsString(rendered);
123154
}
124155

156+
/// Build the (paint/layout) style properties list for a given style.json key.
125157
List<Map<String, dynamic>> buildStyleProperties(
126158
Map<String, dynamic> styleJson, String key) {
127159
final Map<String, dynamic> items = styleJson[key];
128160

129161
return items.entries.map((e) => buildStyleProperty(e.key, e.value)).toList();
130162
}
131163

164+
/// Translate a single raw style property spec into a template-ready map.
132165
Map<String, dynamic> buildStyleProperty(
133166
String key, Map<String, dynamic> value) {
134167
final typeDart = dartTypeMappingTable[value["type"]];
@@ -149,6 +182,7 @@ Map<String, dynamic> buildStyleProperty(
149182
};
150183
}
151184

185+
/// Build the list of source properties (excluding generic wildcard entries).
152186
List<Map<String, dynamic>> buildSourceProperties(
153187
Map<String, dynamic> styleJson, String key) {
154188
final Map<String, dynamic> items = styleJson[key];
@@ -159,6 +193,8 @@ List<Map<String, dynamic>> buildSourceProperties(
159193
.toList();
160194
}
161195

196+
/// Translate one source property spec to a template map, including default
197+
/// value normalization (prefixing const for literal lists, quoting strings).
162198
Map<String, dynamic> buildSourceProperty(
163199
String key, Map<String, dynamic> value) {
164200
final camelCase = ReCase(key).camelCase;
@@ -189,6 +225,8 @@ Map<String, dynamic> buildSourceProperty(
189225
};
190226
}
191227

228+
/// Produce a wrapped documentation block (array of lines) including
229+
/// type/default/constraints plus enumerated option docs.
192230
List<String> buildDocSplit(Map<String, dynamic> item) {
193231
final defaultValue = item["default"];
194232
final maxValue = item["maximum"];
@@ -230,6 +268,7 @@ List<String> buildDocSplit(Map<String, dynamic> item) {
230268
return result;
231269
}
232270

271+
/// Simple greedy word-wrapping utility used for docs.
233272
List<String> splitIntoChunks(String input, int lineLength,
234273
{String prefix = ""}) {
235274
final words = input.split(" ");
@@ -250,6 +289,8 @@ List<String> splitIntoChunks(String input, int lineLength,
250289
return chunks;
251290
}
252291

292+
/// Build expression metadata (renaming reserved or symbolic operators to
293+
/// valid method-like identifiers for Dart code generation).
253294
List<Map<String, dynamic>> buildExpressionProperties(
254295
Map<String, dynamic> styleJson) {
255296
final Map<String, dynamic> items = styleJson["expression_name"]["values"];

scripts/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ environment:
1111
dependencies:
1212
dart_style: ^3.1.2
1313
mustache_template: ^2.0.1
14+
pub_semver: ^2.2.0
1415
recase: ^4.1.0
1516

1617
dev_dependencies:

0 commit comments

Comments
 (0)