dart-sdk/tools/yaml2json.dart
Devon Carew c17e2a13da update the tooling to generate libraries.json from libraries.yaml
Change-Id: I960187ae02834f42a2b7fce2135a8b84b1f21979
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208260
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2021-07-27 23:02:50 +00:00

33 lines
1.1 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.
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) {
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(new File.fromUri(input).readAsStringSync());
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);
file.writeAsStringSync(const JsonEncoder.withIndent(" ").convert(result));
port.close();
}