File tree Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Expand file tree Collapse file tree 1 file changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,41 @@ void main() {
17
17
}
18
18
```
19
19
20
- You can find more about the ` PubspecLock ` object in the documentation [ here] ( https://pub.dev/documentation/pubspec_lock_parse/latest/ )
20
+ You can find more about the ` PubspecLock ` object in the documentation [ here] ( https://pub.dev/documentation/pubspec_lock_parse/latest/ )
21
+
22
+ ### toJson() methods
23
+
24
+ ` pubspec_lock_parse ` includes ` .toJson() ` methods on each object to allow for easy re-generation/mutation of pubspec files
25
+
26
+ This can be combined with [ yaml_writer] ( https://github.com/gmpassos/yaml_writer ) to re-generate yaml output
27
+
28
+ ``` dart
29
+ void main() {
30
+ final pubspec = PubspecLock(
31
+ packages: {
32
+ 'somePackage': Package(
33
+ dependency: 'transitive',
34
+ description: PathPackageDescription(
35
+ path: '../somePackage',
36
+ relative: true,
37
+ )
38
+ )
39
+ },
40
+ sdks: {
41
+ 'dart': VersionConstraint.parse(">=2.17.0 <3.0.0"),
42
+ }
43
+ );
44
+
45
+ final jsonPubspec = pubspec.toJson(); // outputs Map<String, dynamic>
46
+ final yamlPubspec = YamlWriter().write(jsonPubspec); // outputs String
47
+ }
48
+ ```
49
+
50
+ ` toJson ` can also be run on any individual object
51
+ ``` dart
52
+ // outputs: { path: '../somePackage', relative: true }
53
+ print(PathPackageDescription(
54
+ path: '../somePackage',
55
+ relative: true,
56
+ ));
57
+ ```
You can’t perform that action at this time.
0 commit comments