dart-sdk/tools/yaml2json.dart
Alexander Thomas 44f3881be6 [infra] Update checked-in SDKs to 2.12.0-0.0.dev
This is the first checked-in SDK with null-safety enabled by default.

Change-Id: I8f6fcdfd8856483f4737eb200ed4623a244cb0cd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170085
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2020-11-05 07:53:22 +00:00

35 lines
1.2 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.9
import 'dart:io' show File, exit, stderr;
import 'dart:isolate' show RawReceivePort;
import 'dart:convert' show JsonEncoder;
import 'package:yaml/yaml.dart' show loadYaml;
main(List<String> arguments) async {
var port = new RawReceivePort();
if (arguments.length != 2) {
stderr.writeln("Usage: yaml2json.dart input.yaml output.json");
exit(1);
}
Uri input = Uri.base.resolve(arguments[0]);
Uri output = Uri.base.resolve(arguments[1]);
Map yaml = loadYaml(await new File.fromUri(input).readAsString());
Map<String, dynamic> result = new Map<String, dynamic>();
result["comment:0"] = "NOTE: THIS FILE IS GENERATED. DO NOT EDIT.";
result["comment:1"] =
"Instead modify '${arguments[0]}' and follow the instructions therein.";
for (String key in yaml.keys) {
result[key] = yaml[key];
}
File file = new File.fromUri(output);
await file.writeAsString(const JsonEncoder.withIndent(" ").convert(result));
port.close();
}